I have a custom module with a computed field that overwrites _compute_is_shipped() from purchase_order model. If the state of a picking changes, the field is computed. At the same time I would like to calculate and process an account correction but it seems that writing to other fields does not work inside a compute method. I got a weird KeyError that occurs only occasionally:
KeyError: <odoo.api.Environment object at 0x7ffa6c70da90>
and I found this hint: https://www.odoo.com/forum/help-1/question/keyerror-odoo-api-environment-object-at-0x7ffa6c70da90-141072
As documentation is sparse it would be great if someone could explain why writing to other fields is not possible and what I can do instead. I want to detect the picking change and do whatever I want in the method some_corrections().
@api.depends('picking_ids', 'picking_ids.state')
def _compute_is_shipped(self):
res = super(PurchaseOrder, self)._compute_is_shipped()
for order in self:
if order.is_shipped:
order.some_corrections()
I already tried to decorate the function some_corrections() with @api.depends without success.
~~~~~~~~~~~~~~~~~~~~~~~~~~
Thanks Chris,
this might be a way to go. Could you also explain why it is not possible to write arbitrary fields while executing a compute method?
Sorry, I can't. There are other people here with much more technical knowledge than me. I just figure out how to do things with the bare minimum of programming!!