2015-04-01 72 views
1

我是新的OpenERP 7編程。我創建了一個預訂模塊,允許客人預訂多個房間。我希望能夠在創建新預訂時將房間狀態從可用更改爲預訂。這種情況的解決方案似乎覆蓋了對openERP的ORM方法創建編寫 ORM方法。openerp 7創建方法覆蓋

我完全不知道如何將它合併到我的代碼中。以下是我的代碼的一部分。

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') 
} 

使用草稿默認狀態創建預留。如何和在我的代碼在哪裏我把和創建方法?謝謝。

回答

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) 
+0

您好,感謝您的回答以上,但我意識到這一點。我似乎無法得到的是如何訪問窗體上輸入的房間字典(假設它是一個字典,因爲它是一個二維字段)。一旦我知道如何做到這一點,我將能夠循環使用這些值並更改房間的狀態。 – 2015-04-07 06:12:32

+0

如果它是在創建方法中,那麼你應該得到'vals.get('reserved_rooms',False)'它返回id列表或者False不是字典,或者在寫入方法中你應該這樣寫, 'obj in self.browse (cr,uid,ids,context = context): obj.reserved_rooms',obj.reserved_rooms返回可瀏覽的對象而非ID。 – 2015-04-07 09:19:32