Skip to Content
Menu
This question has been flagged
1 Reply
5860 Views

Hello, 

I am writing a code that changes the Fiscal position in the sale order with the following code:

order.write({'fiscal_position_id': fp_id})

This works well, but now the onchange function for Fiscal position is not triggered?
How can I trigger the onchange function for fiscal position automatically?

For now I added the function manually in the code and this works:

order._compute_tax_id()

Is this normal that this function isn't triggered when the field is changed from the code?

Thanks for the replies

 


Avatar
Discard
Best Answer

Never ever use an onchange to add business logic to your model. This is a very bad idea since onchanges are not automatically triggered when creating a record programmatically; they are only triggered in the form view. 


On change is never triggered when creating / updating records via code, only when Users leverage the Odoo UI to create / update them.


From https://www.odoo.com/documentation/14.0/developer/howtos/rdtraining/09_compute_onchange.html#how-to-use-them 

Avatar
Discard
Author

Thank you for your reply. This is what I thought it was but I couldn't find the official explanation.
So when inheriting a module that uses the onchange on a field. If I want to trigger it after programmatically altering it. Calling the onchange function is the only way to get this done.
Now I just have to hope that I haven't overlooked an other function that has the onchange api for this field as well.

Related Posts Replies Views Activity
2
Dec 20
3978
2
Jan 25
42368
2
Jun 25
1405
0
May 25
12
2
Jan 25
2959