2016-05-18 25 views
0

我目前正在使用兩個類,現在我處於一個混亂狀態。請幫我解決這個Openerp如何更新兩個類中的字段值

我需要做的就是曾經在「roster_allocation」級要取消他/她被分配花名冊僱員,然後爲目的,你必須要經過「roster_substitution」級,這使記錄原始分配和替代分配以及日期和時間。一旦你通過該表輸入記錄,我想用**「roster_substitute」**表中的substitute_employee_id更新現有的employee_id來更新該特定的「roster_allocation」表記錄。

這些都是我的兩個班

名冊配置類別

class roster_allocation(osv.osv): 



     _name="roster.allocation" 
     _description ="Allocate rosters on employees" 

     _columns={ 

      'emp_id':fields.many2one('hr.employee','Employee'), 
      'department_id':fields.many2one('hr.department','Department'), 
      'roster_allocation_allocation':fields.one2many('roster.days.allocation','roster_allocation_connection','Days connection'), 
      'roster_time':fields.char('Take the related field roster_time.name'), 
      'monthly allocation':fields.char('Month') , 
      'roster_rest_allocation':fields.one2many('roster.rest.days','roster_id','Rest Days'), 
      'roster_substitute':fields.one2many('roster.substitution','allocation_id','Substitution'), 

roster_allocation() 

名冊天分配類(這使開始日期,名冊類型和時間段的記錄)

class roster_days_allocation(osv.osv): 
    _name="roster.days.allocation" 
    _description = "To allocate days in to the already defined time slots" 


    def get_domain_useer_id(self,cr,uid,ids,roster_type_list,context=None): 
     mach=[] 
     filter = self.pool.get('roster.type').search(cr,uid,[('id','=',roster_type_list)]) 
     return {'domain':{'roster_time_list':[('rostertype','=',filter)]}} 


    _columns={ 
      'name':fields.char('Days_Allocation'), 
      'allocation_start_day':fields.date('Start Date',required=True), 
      'allocation_end_day':fields.date('End Date',required=True), 
      'type_connection':fields.one2many('roster.type','date_allocation_connection','Roster Type'), 
      'roster_type_list':fields.many2one('roster.type','Rosters'), 
      'roster_time_list':fields.many2one('roster.time','Time Slot'), 

      'roster_allocation_connection':fields.many2one('roster.allocation','Allocation Connection') 


       } 


roster_days_allocation() 

名冊替換類(wh ICH保持最初分配員工和替代員工)的記錄

class roster_substitution(osv.osv): 



    _name="roster.substitution" 
    _description="Substituting employees " 
    _columns={ 
      'allocation_id':fields.many2one('roster.allocation','Allocation'), 
      'employee':fields.many2one('hr.employee','Employee'), 
      'sub_employee':fields.many2one('hr.employee','Employee'), 
      'time_slot':fields.many2one('roster.time','Roster'), 
      'roster_day':fields.date('Day'), 
      'reason':fields.text('Reason'), 
      'department_id':fields.many2one('hr.department','Department'), 


      } 


    def onchange_date(self, cr, uid, ids, roster_date): 
     result = {'value': {'type': False}} 
     if type_id: 
      type = self.pool.get('roster.time').browse(cr, uid, roster_date) 
     result['value'] = {'time_slot': type.name.id} 
     return result 



roster_substitution() 

請幫我解決這個

回答

0

對不起,我一遍又一遍地讀您的文章,但我不明白你是什麼準確地做到這一點(可能是因爲你在代碼和文本中以不同的方式命名字段)。但無論如何:

我認爲你必須在你的roster_allocation類中修改你的emp_id

'emp_id': fields.function(_creation_function, 
            type="many2one", 
            obj='hr.employee', 
            string='Employee', 
            store={ 
            'roster.substitution': (_modify_function, 
                  ['field_that_change'], 
                  10)}), 

_creation_function當您創建它時,您必須爲值emp_id定義的函數。 _modify_function當'roster.substitution'中的field_that_change將被修改時,將修改您的emp_id的函數。

這是因爲onchange不允許您從model_B修改model_A中的字段。它不會保存數據庫中的任何內容,除非由於onchange而更新的字段在屏幕上被修改,並且之後保存。

如果您想添加一些您想要關注的字段,您可以將它們添加到['field_that_change', 'second_field']中(如果在同一個對象中),或者在商店中添加第二個具有相同語法的objet。

相關問題