2016-05-18 21 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。

相关问题