Ir al contenido
Menú
Se marcó esta pregunta
1 Responder
6108 Vistas

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
Descartar
Mejor respuesta

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
Descartar
Autor

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.

Publicaciones relacionadas Respuestas Vistas Actividad
2
dic 20
4182
2
ene 25
43157
1
jul 25
1390
2
jul 25
7061
2
jul 25
3422