Skip to Content
Меню
Вам необхідно зареєструватися, щоб взаємодіяти зі спільнотою.
Це запитання позначене
1 Відповісти
6233 Переглядів

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.

Related Posts Відповіді Переглядів Дія
2
груд. 20
4262
2
січ. 25
43463
1
лип. 25
2338
2
лип. 25
7827
2
лип. 25
4220