我是新的OpenERP 7编程。我创建了一个预订模块,允许客人预订多个房间。我希望能够在创建新预订时将房间状态从可用更改为预订。这种情况的解决方案似乎覆盖了openERP的 create 或 write ORM方法。
我完全不知道如何在我的代码中加入它。以下是我的代码的一部分。
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')
}
使用默认状态作为草稿创建预留。在我的代码中我如何以及在何处使用创建或编写方法?感谢。
答案 0 :(得分:1)
尝试以下,
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)