This question has been flagged
1 Reply
4066 Views

hello everyone,

I'm trying to find a way to prevent recursive calls to On_change functions.

Here is the situation : I have 4 fields : cost, price, margin, and coef which are related using these simple formulas : price = cost + margin coef = (price)/cost

Now I have defined 3 on_change fucntions (one for each field except cost) which updates the other fields. i.e. : on change(margin) will update price and coef, on_change(price) will update margin and coef, and on_change(coef)will update price and margin.

These 3 functions work correctly, however they trigger each other recursively and indefinitly ! Since on_change(margin) update price and coef, it will trigger on_change(coef) and on_change(price) etc, etc...

Is there a way to prevent this behaviour? Thank you.

===== FR =====

Bonjour à tous,

je recherche une solution pour eviter des appels récursifs sur des fonctions on_change.

La situation : J'ai 4 champs : cout, prix, marge et coef, ces 4 champs sont liés par les formules suivantes : prix = cout + marge coef = prix/cout

J'ai défini 3 fonctions on_change pour les champs prix, marge et coef de telle façon que ces 3 champs soient mis à jour. par exemple : on_change(marge) met a jour le prix et le coef, on_change(coef) met à jour le prix et la marge...

Les 3 fonctions fonctionnent correctement, hormis le fait qu'elles se déclenchent les uns les autres de façon récursive et infinie ! Puisque la fonction on_change(margin) met a jour les champs prix et coef, les deux fonctions on_chnage(prix) et on_chnage(coef) s'executent aussi, etc, etc....

Existe t il un moyen d'éviter ce comportement ? Merci d'avance !

Avatar
Discard
Author Best Answer

Update. I find the answer using the solution listed here :

h**p://help.openerp.com/question/24702/infinite-loop-with-on_change/

returning empty dict when nothing changes !

Avatar
Discard