I'm working with Odoo 16 and I would like to have an auto update on the state based on a one2many lines_count. Is it possible? I've tried with the code below but it doesn't work (I have another method to create the close_move_id)
close_move_ids = fields.One2many('contribution.ledger.close.move', 'ledger_id', string='Close Slip')
state = fields.Selection(selection=[
('draft', 'Draft'),
('in_progress', 'In-progress'),
('done', 'Done')],
string='Status',
default='draft')
@api.onchange('close_move_ids')
def _onchange_close_move_ids(self):
for record in self:
print(len(record.close_move_ids))
if len(record.close_move_ids) == 0:
record.state = 'draft'
if len(record.close_move_ids) > 0 & len(record.close_move_ids) < self.lines_count:
record.state = 'in_progress'
if len(record.close_move_ids) >= self.lines_count:
record.state = 'done'