Skip to Content
Menu
This question has been flagged
2 Replies
2971 Views

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?
Avatar
Discard

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!!

Best Answer

Have you considered Automated Actions?

This can allow you to update multiple fields (in one model) and trigger other actions.

Start by enabling developer mode and navigating to Settings / Technical / Automated Actions.

If you cannot find this option, you may need to install the module “Automated Action Rules”.

First remove the “Apps” filter by clicking on the ‘X’:

Then search for “Automated”

If it’s not installed, click on ‘INSTALL’.


https://odootricks.tips/automated-actions/

 

Avatar
Discard