Reputation: 11
I am new OpenERP 7 programming. I have created a booking module that allows a guest to book more than one room. I want to be able to change the room status from available to booked when creating the new reservation. The solution to this kind of scenario seems to be overriding the create or write ORM methods for openERP.
I completely don't know how to incorporate this in my code. Below is part of my code.
class reservation(osv.osv):
_columns = {
'name': fields.char('Reservation No', required=True, select=True, readonly=True),
'date_order':fields.datetime('Date Ordered', required=True, readonly=True),
'reserved_rooms': fields.one2many('hotel.reservation.line','line_id', 'Reserved Rooms'),
'state': fields.selection([('draft', 'Draft'),('confirmed','Confirmed'),('cancelled','Cancelled'),('done','Done')], 'State',readonly=True),
}
reservation()
_defaults = {
'name': lambda obj, cr, uid, context: obj.pool.get('ir.sequence').get(cr, uid,'hotel.reservation'),
'state': lambda *a: 'draft',
'date_order': lambda *a: time.strftime('%Y-%m-%d %H:%M:%S')
}
The reservation is created with the default state as draft. How and where in my code do i put and use the create or write method? Thanks.
Upvotes: 1
Views: 823
Reputation: 14746
Try following,
class reservation(osv.osv):
_columns = {
'name': fields.char('Reservation No', required=True, select=True, readonly=True),
'date_order':fields.datetime('Date Ordered', required=True, readonly=True),
'reserved_rooms': fields.one2many('hotel.reservation.line','line_id', 'Reserved Rooms'),
'state': fields.selection([('draft', 'Draft'),('confirmed','Confirmed'),('cancelled','Cancelled'),('done','Done')], 'State',readonly=True),
}
_defaults = {
'name': lambda obj, cr, uid, context: obj.pool.get('ir.sequence').get(cr, uid,'hotel.reservation'),
'state': lambda *a: 'draft',
'date_order': lambda *a: time.strftime('%Y-%m-%d %H:%M:%S')
}
def create(self, cr, uid, vals, context=None):
###Add your code here
####update status in vals
return super(reservation,self).create(cr, uid, vals, context=context)
def write(self, cr, uid, ids, vals, context=None):
###Add your code here
####update status in vals
## you will get only those fields into the vals which are updated.
return super(reservation,self).write(cr, uid, ids, vals, context=context)
Upvotes: 1