Skip ke Konten
Menu
Pertanyaan ini telah diberikan tanda
1 Balas
6024 Tampilan

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
Buang
Jawaban Terbai

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
Buang
Penulis

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.

Post Terkait Replies Tampilan Aktivitas
2
Des 20
4107
2
Jan 25
42955
2
Jul 25
2957
2
Jun 25
1787
0
Mei 25
14