I need to compute a filed after pos_session.state is 'closed' in a (working) function:
class pos_session2(models.Model):
_inherit = 'pos.session'
chk = fields.Char(string = 'chk', compute = '_session_costs_control', store = True)
@api.depends('sequence_number')
def _session_costs_control(self):
_logger.info('Status = %s', self.state)
if self.state == 'closed':
self.chk = self.state #for tests purpose
else:
self.chk = self.sequence_number
The if statement is never reached, the else statement works fine and correctly update for every order added.
I've tried with:
self.state == str('closed')
(self.state == 'closed')
But nothing so far. When I close a session the field pos_session.chk is not updated. For now I'm checking the field with a cr.execute but I would like to understand why a simple string is not captured in Odoo.
Edit: Solved adding 'state' and 'stop_at' on api.depends(). When I close the session the index of 'sequence_number' is not updated. Just a stupid mistake.