Hello,
Im trying to create the method which has to check the record has selected or not in one2many tree view. If the record has selected then the method will change state. If not, then it will raise the warning for user.
model_b.py :
name = fields.Many2one('hr.employee')
o_2_m = fields.One2many('model.a', 'keya')
state = fields.Selection([
('draf', 'DRAF'),
('confirm', 'CONFIRMED'),
(cancel', 'CANCEL'),
],default='draf')
model_a.py :
name = fields.Many2one('hr.employee')
keya = fields.Many2one('model.b')
The method's code like this:
def confirm(self)
for rec in self:
mod_b = self.env["model.b"].search([('o_2_m.name', '=', rec.name.id)])
mod_a = self.env["model.a"].search([('name', '=', rec.name.id)])
if mod_b.o_2_m.name == mod_a.name :
mod_b.write({'state': 'confirm'})
else:
return {
'warning': {
'title': "You forget to select the record for changing in o2m",
'message': "Please select as below",
},
}
I have tested with select no select the record via "Add a line" link in one2many tree view of model_b.py. But nothing works.
Please help!
Thank you!