In Odoo 16, I have 2 computed fields:
rec_name = fields.Char('Rec name', compute='_compute_rec_name', store=True, translate=True)
located_between = fields.Char('Located between', compute='_compute_located_between', store=True)
And the 2 functions of theses fields are:
@api.depends('name', 'line_type', 'located_between')
def _compute_rec_name(self):
for rec in self:
print("Rec name")
if rec.name:
rec.rec_name = rec.name
else:
line_type_string = dict(rec._fields['line_type']._description_selection(self.env)).get(rec.line_type)
rec.rec_name = _('%s between %s', line_type_string, rec.located_between)
@api.depends('sequence')
def _compute_located_between(self):
for rec in self:
print("Located between")
if not rec.activable:
all_previous_activable_line = self.search([('track_table_id', '=', rec.track_table_id.id), ('activable', '=', True), ('sequence', '<', rec.sequence)])
all_next_activable_line = self.search([('track_table_id', '=', rec.track_table_id.id), ('activable', '=', True), ('sequence', '>', rec.sequence)])
if len(all_previous_activable_line) > 0 and len(all_next_activable_line) > 0:
rec.located_between = _('%s and %s', all_previous_activable_line[-1].name, all_next_activable_line[0].name)
else:
rec.located_between = _('No activable line before or after this one')
else:
rec.located_between = ''
The problem is that the _compute_rec_name
function is called before _compute_located_between
(check with print) and the result is false because _compute_rec_name
take old value of located_between
instead of newest.
I tried:
- to remove the dependencies of
located_between
for the function_compute_rec_name
and the function isn’t called as expected. - to put
_compute_rec_name
after_compute_located_between
in the code but it doesn’t work
Is there any way to change the order of execution?