2016-05-03 6 views
0

Datensätze erstellen Ich habe diese vier Klassen namens roster_time, roster_type, roster_allocation und roster_substitution und jede Klasse einer Verbindung mit one to many Beziehung außer roster_substitution.OPENERP wie von einer Klasse in einer anderen

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() 

Roster Definition Klasse

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()  

Zuteilung Roster Klasse

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() 

Roster Stornierung Klasse

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() 

Was ich versuche, ist, wenn ich eine Zuordnung mit roster_substitution Klasse abbrechen Ich mag, dass Datensatz mit der neu zugewiesenen Person in roster_allocation Tabelle des gewählte Datum und Zeit verwenden. Wie man das macht

dies ist mein Versuch, es zu tun und es funktioniert offensichtlich nicht

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  

Antwort

0

Die emp_id und department_id vom Objekt roster.allocation sind beide many2one Feld. Beim Übergeben des Werts zum Schreiben/Erstellen des Werts sollte die Datenbankkennung des Datensatzes festgelegt werden, in diesem Fall ist es die ID hr.employee für emp_id und hr.department für department_id.

zum Beispiel:

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 

     emp_id = 1 # Search from hr.employee 
     department_id = 1 # Search from hr.department 

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

     return True 
Verwandte Themen