Hello,
I have two models. And want to show the tree view of model 2/ into the user's form view of model 1/.
1/ Model dieu_chinh.py using one2many field:
class DieuChinh(models.Model):
_name = "dieu.chinh"
lstd_dieuchinh = fields.One2many('lich.su', 'thamchieu')
thamchieu = fields.Char('Tham chiếu')
thoigian = fields.Date('Time XYZ', default=datetime.today())
2/ Model lich_su.py using many2one field and has tree view:
class DieuChinh(models.Model):
_name = "dieu.chinh"
name = fields.Many2one('hr.employee', string="Test XYZ")
thamchieu = fields.Many2one('dieu.chinh')
thoigian = fields.Date('Time ABC', default=datetime.today())
This is code of the button to execute:
def accept(self):
giatri_lstd = self.env['lich.su']
gt = {
'name': self.name.id,
'thamchieu': self.id,
'thoigian': self.thoigian
}
list_lstd_dieuchinh=[]
for line in self.lstd_dieuchinh :
art = {}
art['name'] = line.name.id
art['thamchieu'] = line.self.id
art['thoigian'] = line.thoigian
list_lstd_dieuchinh.append((0, 0, art))
gt.update({
'thamchieu': list_lstd_dieuchinh
})
giatri_lstd = giatri_lstd.create(gt)
After click the button 'accpet'. It can pass and create the records with the value from field: 'name', 'thoigian' to the model 2/'s tree view.
But it still not create the record from the field: 'thamchieu' which has a relation many2one with model 1/ . So that it cannot auto show the value in the model 2/'s tree view in the form view of model 1/'s user.
What am I doing wrong?
Please help!
Thank you!