跳至內容
選單
此問題已被標幟
1 回覆
6218 瀏覽次數

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

 


頭像
捨棄
最佳答案

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 

頭像
捨棄
作者

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.

相關帖文 回覆 瀏覽次數 活動
2
12月 20
4257
2
1月 25
43440
1
7月 25
2328
2
7月 25
7810
2
7月 25
4210