Openerp如何创建从一个类到另一个类的记录

时间:2016-05-03 10:26:47

标签: python python-2.7 openerp openerp-7

我有四个名为 roster_time,roster_type,roster_allocation和roster_substitution 的类,每个类都与一对多关系连接,除了roster_substitution 。< / p>

 class roster_time(osv.osv):

    _name="roster.time"
    _description = "To create roster time slot"

    _columns={
           'roster_id':fields.integer('Roster ID'),
           'start_time': fields.char('Start Time',required=True),
           'end_time':fields.char('End Time',required=True),
           'rostertype':fields.many2one('roster.type','roster','Roster Time'),
           'name':fields.char('Roster Time'),

           }


roster_time()

名册定义类

class roster_type(osv.osv):

_name="roster.type"
_description = "To create roster type for each department"

_columns={


    'name': fields.char('Roster type'),
           'roster':fields.one2many('roster.time','rostertype','Time Slot'),

           'allocation_id':fields.many2one('roster.allocation','Roster ID'),
           'roster_time':fields.many2one('roster.time','Slot'),
          'roster_end':fields.related('roster.time','roster_start',type='char',string='End Time'),
           'allocation_start_day':fields.date('Start Date' ),
           'allocation_end_day':fields.date('End Date'),
           'department_id':fields.many2one('hr.department','Department',required=True),



           }


roster_time()    

名册分配类

    class roster_allocation(osv.osv):

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


     _columns={

         'emp_id':fields.many2one('hr.employee','Employee',required=True),
         'department_id':fields.many2one('hr.department','Department',required=True),
         #'roster':fields.many2one('roster.type','roster', 'Roster ID'),
         'roster_linked_ids':fields.one2many('roster.type','allocation_id','Roster Linked Ids'),

         'roster_type':fields.related('roster.type','department_id', type='char', string='Roster Type'),
         '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_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'),


             }
roster_substitution()

我尝试做的是使用 roster_substitution class 取消分配后,我希望使用选中的 roster_allocation 表中的新分配人员日期时间。怎么做

这是我尝试这样做,而且它显然无法正常工作

   def allocation_substitute(self,cr,uid,ids,roster_day,context=None):
        sub_day=vals.get(roster_day)
        sub_time_slot=vals.get(time_slot)

        allocation_obj=self.pool.get('roster.allocation')
        original_employee_id =  allocation_obj.browse(cr,uid, values['emp_id']).id
        original_employee_roster=allocation_obj.browse(cr,uid, original_employee_id).roster_type

        values={'emp_id':'employee',
                'department_id':'department_id',
                }
        allocation_id=allocation_obj.create(cr, uid, value, context=context)  

        return True     

1 个答案:

答案 0 :(得分:0)

对象emp_id中的department_idroster.allocation都是many2one字段。当传递值来写/创建时,值应该是要设置的记录的数据库标识符,在这种情况下,它是hr.employee的{​​{1}}和emp_id的{​​{1}}的ID

例如:

hr.department