I have this existing field:
picking_code = fields.Selection(
related='picking_id.picking_type_id.code',
readonly=True,
)
And I want to inherit it, remove the related
parameter and add a compute
one to set its value depending on some conditions.
My attempt:
@api.depends('picking_id', 'picking_id.picking_type_id',
'picking_id.picking_type_id.code',
'move_id', 'move_id.picking_type_id',
'move_id.picking_type_id.code')
def _compute_picking_code(self):
_logger.critical('NEVER EXECUTES THIS' * 80)
for line in self:
if line.picking_id:
line.picking_code = line.picking_id.picking_type_id.code
else:
line.picking_code = line.move_id.picking_type_id.code
picking_code = fields.Selection(
related=False,
compute='_compute_picking_code',
)
The problem is that the compute method is never executed and I get the following error, which makes sense since if the compute method is not executed, no selection value is set to the field:
AssertionError: Field stock.move.line.picking_code without selection - - -
Solved, if anyone is interested on the subject, it is a Selection
field, so if remove the related
parameter I have to specify again the list of tuples for the selection
parameter.
picking_code = fields.Selection(
selection=[
('incoming', 'Receipt'),
('outgoing', 'Delivery'),
('internal', 'Internal Transfer'),
],
compute='_compute_picking_code',
related=False,
readonly=True,
)