1
##############################################################################
3
# Copyright (c) 2006 TINY SPRL. (http://tiny.be) All Rights Reserved.
4
# Fabien Pinckaers <fp@tiny.Be>
6
# WARNING: This program as such is intended to be used by professional
7
# programmers who take the whole responsability of assessing all potential
8
# consequences resulting from its eventual inadequacies and bugs
9
# End users who are looking for a ready-to-use solution with commercial
10
# garantees and support are strongly adviced to contract a Free Software
13
# This program is Free Software; you can redistribute it and/or
14
# modify it under the terms of the GNU General Public License
15
# as published by the Free Software Foundation; either version 2
16
# of the License, or (at your option) any later version.
18
# This program is distributed in the hope that it will be useful,
19
# but WITHOUT ANY WARRANTY; without even the implied warranty of
20
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21
# GNU General Public License for more details.
23
# You should have received a copy of the GNU General Public License
24
# along with this program; if not, write to the Free Software
25
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
27
##############################################################################
28
from osv import fields
33
from mx import DateTime
36
from tools import config
38
class hotel_floor(osv.osv):
40
_description = "Floor"
42
'name': fields.char('Floor Name', size=64, required=True,select=True),
43
'sequence' : fields.integer('Sequence', size=64),
47
class product_category(osv.osv):
48
_inherit="product.category"
50
'isroomtype':fields.boolean('Is Room Type'),
51
'isamenitype':fields.boolean('Is amenities Type'),
52
'isservicetype':fields.boolean('Is Service Type'),
56
class hotel_room_type(osv.osv):
57
_name = "hotel.room_type"
58
_inherits = {'product.category':'cat_id'}
59
_description = "Room Type"
61
'cat_id':fields.many2one('product.category','category',required=True,select=True),
65
'isroomtype': lambda *a: 1,
70
class product_product(osv.osv):
71
_inherit="product.product"
73
'isroom':fields.boolean('Is Room'),
74
'iscategid':fields.boolean('Is categ id'),
75
'isservice':fields.boolean('Is Service id'),
80
class hotel_room_amenities_type(osv.osv):
81
_name='hotel.room_amenities_type'
82
_description='amenities Type'
83
_inherits = {'product.category':'cat_id'}
85
'cat_id':fields.many2one('product.category','category',required=True),
88
'isamenitype': lambda *a: 1,
92
hotel_room_amenities_type()
94
class hotel_room_amenities(osv.osv):
95
_name='hotel.room_amenities'
96
_description='Room amenities'
97
_inherits={'product.product':'room_categ_id'}
100
'room_categ_id':fields.many2one('product.product','Product Category',required=True),
101
'rcateg_id':fields.many2one('hotel.room_amenities_type','Amenity Catagory'),
102
'amenity_rate':fields.integer('Amenity Rate'),
107
'iscategid': lambda *a: 1,
111
hotel_room_amenities()
114
class hotel_room(osv.osv):
117
_inherits={'product.product':'product_id'}
118
_description='Hotel Room'
121
'product_id': fields.many2one('product.product','Product_id'),
122
'floor_id':fields.many2one('hotel.floor','Floor No'),
123
'maxAdult':fields.integer('Max Adult'),
124
'maxChild':fields.integer('Max Child'),
125
'avail_status':fields.selection([('assigned','Assigned'),(' unassigned','Unassigned')],'Room Status'),
126
'room_amenities':fields.many2many('hotel.room_amenities','temp_tab','room_amenities','rcateg_id','Room Amenities'),
129
'isroom': lambda *a: 1,
130
'rental': lambda *a: 1,
136
class hotel_folio(osv.osv):
138
def _incoterm_get(self, cr, uid, context={}):
139
return self.pool.get('sale.order')._incoterm_get(cr, uid, context={})
140
def copy(self, cr, uid, id, default=None,context={}):
141
return self.pool.get('sale.order').copy(cr, uid, id, default=None,context={})
142
def _invoiced(self, cursor, user, ids, name, arg, context=None):
143
return self.pool.get('sale.order')._invoiced(cursor, user, ids, name, arg, context=None)
144
def _invoiced_search(self, cursor, user, obj, name, args):
145
return self.pool.get('sale.order')._invoiced_search(cursor, user, obj, name, args)
146
def _amount_untaxed(self, cr, uid, ids, field_name, arg, context):
147
return self.pool.get('sale.order')._amount_untaxed(cr, uid, ids, field_name, arg, context)
148
def _amount_tax(self, cr, uid, ids, field_name, arg, context):
149
return self.pool.get('sale.order')._amount_tax(cr, uid, ids, field_name, arg, context)
150
def _amount_total(self, cr, uid, ids, field_name, arg, context):
151
return self.pool.get('sale.order')._amount_total(cr, uid, ids, field_name, arg, context)
154
_description='hotel folio new'
155
_inherits={'sale.order':'order_id'}
157
'order_id':fields.many2one('sale.order','order_id',required=True,ondelete='cascade'),
158
'checkin_date': fields.datetime('Check In',required=True,readonly=True, states={'draft':[('readonly',False)]}),
159
'checkout_date': fields.datetime('Check Out',required=True,readonly=True, states={'draft':[('readonly',False)]}),
160
'room_lines': fields.one2many('hotel_folio.line','folio_id'),
161
'service_lines': fields.one2many('hotel_service.line','folio_id'),
164
def create(self, cr, uid, vals, context=None, check=True):
165
tmp_room_lines = vals['room_lines']
166
tmp_service_lines = vals['service_lines']
167
if not vals.has_key("folio_id"):
168
vals.update({'room_lines':[],'service_lines':[]})
169
folio_id = super(hotel_folio, self).create(cr, uid, vals, context)
170
for line in tmp_room_lines:
171
line[2].update({'folio_id':folio_id})
172
for line in tmp_service_lines:
173
line[2].update({'folio_id':folio_id})
174
vals.update({'room_lines':tmp_room_lines,'service_lines':tmp_service_lines})
175
super(hotel_folio, self).write(cr, uid,[folio_id], vals, context)
177
folio_id = super(hotel_folio, self).create(cr, uid, vals, context)
181
def onchange_shop_id(self, cr, uid, ids, shop_id):
182
return self.pool.get('sale.order').onchange_shop_id(cr, uid, ids, shop_id)
183
def onchange_partner_id(self, cr, uid, ids, part):
184
return self.pool.get('sale.order').onchange_partner_id(cr, uid, ids, part)
185
def button_dummy(self, cr, uid, ids, context={}):
186
return self.pool.get('sale.order').button_dummy(cr, uid, ids, context={})
188
def action_invoice_create(self, cr, uid, ids, grouped=False, states=['confirmed','done']):
189
i = self.pool.get('sale.order').action_invoice_create(cr, uid, ids, grouped=False, states=['confirmed','done'])
190
for line in self.browse(cr, uid, ids, context={}):
191
self.write(cr, uid, [line.id], {'invoiced':True})
193
self.write(cr, uid, [line.id], {'state' : 'progress'})
195
self.write(cr, uid, [line.id], {'state' : 'progress'})
199
def action_invoice_cancel(self, cr, uid, ids, context={}):
200
res = self.pool.get('sale.order').action_invoice_cancel(cr, uid, ids, context={})
201
for sale in self.browse(cr, uid, ids):
202
for line in sale.order_line:
203
self.pool.get('sale.order.line').write(cr, uid, [line.id], {'invoiced': invoiced})
204
self.write(cr, uid, ids, {'state':'invoice_except', 'invoice_id':False})
206
def action_cancel(self, cr, uid, ids, context={}):
207
c = self.pool.get('sale.order').action_cancel(cr, uid, ids, context={})
209
for sale in self.browse(cr, uid, ids):
210
for r in self.read(cr,uid,ids,['picking_ids']):
211
for pick in r['picking_ids']:
212
wf_service = netsvc.LocalService("workflow")
213
wf_service.trg_validate(uid, 'stock.picking', pick, 'button_cancel', cr)
214
for r in self.read(cr,uid,ids,['invoice_ids']):
215
for inv in r['invoice_ids']:
216
wf_service = netsvc.LocalService("workflow")
217
wf_service.trg_validate(uid, 'account.invoice', inv, 'invoice_cancel', cr)
219
self.write(cr,uid,ids,{'state':'cancel'})
222
def action_wait(self, cr, uid, ids, *args):
223
res = self.pool.get('sale.order').action_wait(cr, uid, ids, *args)
224
for o in self.browse(cr, uid, ids):
225
if (o.order_policy == 'manual') and (not o.invoice_ids):
226
self.write(cr, uid, [o.id], {'state': 'manual'})
228
self.write(cr, uid, [o.id], {'state': 'progress'})
230
def test_state(self, cr, uid, ids, mode, *args):
232
write_cancel_ids = []
233
res = self.pool.get('sale.order').test_state(cr, uid, ids, mode, *args)
235
self.pool.get('sale.order.line').write(cr, uid, write_done_ids, {'state': 'done'})
237
self.pool.get('sale.order.line').write(cr, uid, write_cancel_ids, {'state': 'cancel'})
239
def procurement_lines_get(self, cr, uid, ids, *args):
240
res = self.pool.get('sale.order').procurement_lines_get(cr, uid, ids, *args)
242
def action_ship_create(self, cr, uid, ids, *args):
243
res = self.pool.get('sale.order').action_ship_create(cr, uid, ids, *args)
245
for order in self.browse(cr, uid, ids, context={}):
246
for line in order.order_line:
248
if line.state == 'done':
250
wf_service = netsvc.LocalService("workflow")
251
wf_service.trg_validate(uid, 'mrp.procurement', proc_id, 'button_confirm', cr)
252
self.pool.get('sale.order.line').write(cr, uid, [line.id], {'procurement_id': proc_id})
254
wf_service = netsvc.LocalService("workflow")
255
wf_service.trg_validate(uid, 'mrp.procurement', proc_id, 'button_confirm', cr)
256
self.pool.get('sale.order.line').write(cr, uid, [line.id], {'procurement_id': proc_id})
260
wf_service = netsvc.LocalService("workflow")
261
wf_service.trg_validate(uid, 'stock.picking', picking_id, 'button_confirm', cr)
262
#val = {'picking_ids':[(6,0,[picking_id])]}
264
if order.state=='shipping_except':
265
val['state'] = 'progress'
266
if (order.order_policy == 'manual') and order.invoice_ids:
267
val['state'] = 'manual'
268
self.write(cr, uid, [order.id], val)
270
def action_ship_end(self, cr, uid, ids, context={}):
271
res = self.pool.get('sale.order').action_ship_end(cr, uid, ids, context={})
272
for order in self.browse(cr, uid, ids):
273
val = {'shipped':True}
274
self.write(cr, uid, [order.id], val)
276
def _log_event(self, cr, uid, ids, factor=0.7, name='Open Order'):
277
return self.pool.get('sale.order')._log_event(cr, uid, ids, factor=0.7, name='Open Order')
278
def has_stockable_products(self,cr, uid, ids, *args):
279
return self.pool.get('sale.order').has_stockable_products(cr, uid, ids, *args)
280
def action_cancel_draft(self, cr, uid, ids, *args):
281
d = self.pool.get('sale.order').action_cancel_draft(cr, uid, ids, *args)
282
self.write(cr, uid, ids, {'state':'draft', 'invoice_ids':[], 'shipped':0})
283
self.pool.get('sale.order.line').write(cr, uid, line_ids, {'invoiced':False, 'state':'draft', 'invoice_lines':[(6,0,[])]})
288
class hotel_folio_line(osv.osv):
290
def copy(self, cr, uid, id, default=None, context={}):
291
return self.pool.get('sale.order.line').copy(cr, uid, id, default=None, context={})
292
def _amount_line_net(self, cr, uid, ids, field_name, arg, context):
293
return self.pool.get('sale.order.line')._amount_line_net(cr, uid, ids, field_name, arg, context)
294
def _amount_line(self, cr, uid, ids, field_name, arg, context):
295
return self.pool.get('sale.order.line')._amount_line(cr, uid, ids, field_name, arg, context)
296
def _number_packages(self, cr, uid, ids, field_name, arg, context):
297
return self.pool.get('sale.order.line')._number_packages(cr, uid, ids, field_name, arg, context)
298
def _get_1st_packaging(self, cr, uid, context={}):
299
return self.pool.get('sale.order.line')._get_1st_packaging(cr, uid, context={})
300
def _get_checkin_date(self,cr, uid, context={}):
301
if 'checkin_date' in context:
302
return context['checkin_date']
303
return time.strftime('%Y-%m-%d %H:%M:%S')
304
def _get_checkout_date(self,cr, uid, context={}):
305
if 'checkin_date' in context:
306
return context['checkout_date']
307
return time.strftime('%Y-%m-%d %H:%M:%S')
309
_name='hotel_folio.line'
310
_description='hotel folio1 room line'
311
_inherits={'sale.order.line':'order_line_id'}
313
'order_line_id':fields.many2one('sale.order.line','order_line_id',required=True,ondelete='cascade'),
314
'folio_id':fields.many2one('hotel.folio','folio_id',ondelete='cascade'),
315
'checkin_date': fields.datetime('Check In',required=True),
316
'checkout_date': fields.datetime('Check Out',required=True),
319
'checkin_date':_get_checkin_date,
320
'checkout_date':_get_checkout_date,
324
def create(self, cr, uid, vals, context=None, check=True):
327
if vals.has_key("folio_id"):
328
folio = self.pool.get("hotel.folio").browse(cr,uid,[vals['folio_id']])[0]
329
vals.update({'order_id':folio.order_id.id})
330
roomline = super(osv.osv, self).create(cr, uid, vals, context)
332
def uos_change(self, cr, uid, ids, product_uos, product_uos_qty=0, product_id=None):
333
return self.pool.get('sale.order.line').uos_change(cr, uid, ids, product_uos, product_uos_qty=0, product_id=None)
334
def product_id_change(self, cr, uid, ids, pricelist, product, qty=0,
335
uom=False, qty_uos=0, uos=False, name='', partner_id=False,
336
lang=False, update_tax=True, date_order=False):
337
return self.pool.get('sale.order.line').product_id_change(cr, uid, ids, pricelist, product, qty=0,
338
uom=False, qty_uos=0, uos=False, name='', partner_id=False,
339
lang=False, update_tax=True, date_order=False)
340
def product_uom_change(self, cursor, user, ids, pricelist, product, qty=0,
341
uom=False, qty_uos=0, uos=False, name='', partner_id=False,
342
lang=False, update_tax=True, date_order=False):
343
return self.pool.get('sale.order.line').product_uom_change(cursor, user, ids, pricelist, product, qty=0,
344
uom=False, qty_uos=0, uos=False, name='', partner_id=False,
345
lang=False, update_tax=True, date_order=False)
346
def on_change_checkout(self,cr, uid, ids, checkin_date=time.strftime('%Y-%m-%d %H:%M:%S'),checkout_date=time.strftime('%Y-%m-%d %H:%M:%S'),context=None):
350
if checkout_date < checkin_date:
351
raise osv.except_osv ('Error !','Checkout must be greater or equal checkin date')
353
diffDate = datetime.datetime(*time.strptime(checkout_date,'%Y-%m-%d %H:%M:%S')[:5]) - datetime.datetime(*time.strptime(checkin_date,'%Y-%m-%d %H:%M:%S')[:5])
355
return {'value':{'product_uom_qty':qty}}
357
def button_confirm(self, cr, uid, ids, context={}):
359
return self.pool.get('sale.order.line').button_confirm(cr, uid, ids, context={})
360
def button_done(self, cr, uid, ids, context={}):
361
res = self.pool.get('sale.order.line').button_done(cr, uid, ids, context={})
362
wf_service = netsvc.LocalService("workflow")
363
res = self.write(cr, uid, ids, {'state':'done'})
364
for line in self.browse(cr,uid,ids,context):
365
wf_service.trg_write(uid, 'sale.order', line.order_id.id, cr)
369
def uos_change(self, cr, uid, ids, product_uos, product_uos_qty=0, product_id=None):
370
return self.pool.get('sale.order.line').uos_change(cr, uid, ids, product_uos, product_uos_qty=0, product_id=None)
371
def copy(self, cr, uid, id, default=None,context={}):
372
return self.pool.get('sale.order.line').copy(cr, uid, id, default=None,context={})
378
class hotel_service_line(osv.osv):
380
def copy(self, cr, uid, id, default=None, context={}):
381
return self.pool.get('sale.order.line').copy(cr, uid, id, default=None, context={})
382
def _amount_line_net(self, cr, uid, ids, field_name, arg, context):
383
return self.pool.get('sale.order.line')._amount_line_net(cr, uid, ids, field_name, arg, context)
384
def _amount_line(self, cr, uid, ids, field_name, arg, context):
385
return self.pool.get('sale.order.line')._amount_line(cr, uid, ids, field_name, arg, context)
386
def _number_packages(self, cr, uid, ids, field_name, arg, context):
387
return self.pool.get('sale.order.line')._number_packages(cr, uid, ids, field_name, arg, context)
388
def _get_1st_packaging(self, cr, uid, context={}):
389
return self.pool.get('sale.order.line')._get_1st_packaging(cr, uid, context={})
392
_name='hotel_service.line'
393
_description='hotel Service line'
394
_inherits={'sale.order.line':'service_line_id'}
396
'service_line_id':fields.many2one('sale.order.line','service_line_id',required=True,ondelete='cascade'),
397
'folio_id':fields.many2one('hotel.folio','folio_id',ondelete='cascade'),
401
def create(self, cr, uid, vals, context=None, check=True):
404
if vals.has_key("folio_id"):
405
folio = self.pool.get("hotel.folio").browse(cr,uid,[vals['folio_id']])[0]
406
vals.update({'order_id':folio.order_id.id})
407
roomline = super(osv.osv, self).create(cr, uid, vals, context)
409
def uos_change(self, cr, uid, ids, product_uos, product_uos_qty=0, product_id=None):
410
return self.pool.get('sale.order.line').uos_change(cr, uid, ids, product_uos, product_uos_qty=0, product_id=None)
411
def product_id_change(self, cr, uid, ids, pricelist, product, qty=0,
412
uom=False, qty_uos=0, uos=False, name='', partner_id=False,
413
lang=False, update_tax=True, date_order=False):
414
return self.pool.get('sale.order.line').product_id_change(cr, uid, ids, pricelist, product, qty=0,
415
uom=False, qty_uos=0, uos=False, name='', partner_id=False,
416
lang=False, update_tax=True, date_order=False)
417
def product_uom_change(self, cursor, user, ids, pricelist, product, qty=0,
418
uom=False, qty_uos=0, uos=False, name='', partner_id=False,
419
lang=False, update_tax=True, date_order=False):
420
return self.pool.get('sale.order.line').product_uom_change(cursor, user, ids, pricelist, product, qty=0,
421
uom=False, qty_uos=0, uos=False, name='', partner_id=False,
422
lang=False, update_tax=True, date_order=False)
423
def on_change_checkout(self,cr, uid, ids, checkin_date=time.strftime('%Y-%m-%d %H:%M:%S'),checkout_date=time.strftime('%Y-%m-%d %H:%M:%S'),context=None):
427
if checkout_date < checkin_date:
428
raise osv.except_osv ('Error !','Checkout must be greater or equal checkin date')
430
diffDate = datetime.datetime(*time.strptime(checkout_date,'%Y-%m-%d %H:%M:%S')[:5]) - datetime.datetime(*time.strptime(checkin_date,'%Y-%m-%d %H:%M:%S')[:5])
432
return {'value':{'product_uom_qty':qty}}
434
def button_confirm(self, cr, uid, ids, context={}):
436
return self.pool.get('sale.order.line').button_confirm(cr, uid, ids, context={})
437
def button_done(self, cr, uid, ids, context={}):
438
return self.pool.get('sale.order.line').button_done(cr, uid, ids, context={})
439
def uos_change(self, cr, uid, ids, product_uos, product_uos_qty=0, product_id=None):
440
return self.pool.get('sale.order.line').uos_change(cr, uid, ids, product_uos, product_uos_qty=0, product_id=None)
441
def copy(self, cr, uid, id, default=None,context={}):
442
return self.pool.get('sale.order.line').copy(cr, uid, id, default=None,context={})
448
class hotel_service_type(osv.osv):
449
_name = "hotel.service_type"
450
_inherits = {'product.category':'ser_id'}
451
_description = "Service Type"
453
'ser_id':fields.many2one('product.category','category',required=True,select=True),
457
'isservicetype': lambda *a: 1,
462
class hotel_services(osv.osv):
464
_name = 'hotel.services'
465
_description = 'Hotel Services and its charges'
466
_inherits={'product.product':'service_id'}
468
'service_id': fields.many2one('product.product','Service_id'),
472
'isservice': lambda *a: 1,