Odoo Help


This community is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.


Can I use function fields as store triggers in other function fields?

Daniele Bondì
on 2/20/14, 5:47 AM 1,066 views

I have a setup similar to this

_name = "ies.review"

"sale_price": fields.float("Price"),

"cost": fields.function(_cost, type="float", store={
    "ies.review.line": (_review_from_lines, ["price", "quantity"], 10),
}, multi="all"),

"value_added": fields.function(_cost, type="float", store={
    "ies.review": (_ids, ["sale_price"], 10),
    "ies.review.line": (_review_from_lines, ["price", "quantity"], 10),
}, multi="all"),

"value_added_percent": fields.function(_cost, type="float", store={
    "ies.review": (_ids, ["sale_price"], 10),
    "ies.review.line": (_review_from_lines, ["price", "quantity"], 10),
}, multi="all"),

"cost" should be updated whenever there is a change in a one2many field, and that's ok.

"value_added" fields should be updated whenever there is a change in cost or price. I have no problems with the price, but if I add the "cost" field in the list of triggering fields nothing happens (I guess because the change is applied only after all the conditions are evaluated?). Then I though of adding them to a multi group, so that the _cost function called by "cost" would be responsible for updating value_addeds too in a single call, but it seems like if no condition is met, the field doesn't get passed to the function "field_names" parameter

def _cost(self, cr, uid, ids, field_names, arg, context)

and if I return them in the dict they seem to be just ignored. Changing the priority also didn't seem to have any effect.

I had to add the second condition, that allows the fields to be recomputed in the same occasions as the cost. However it looks messy and it's logically wrong.

Is there a correct way to use function fields as triggers?

And as a secondary question, a bit of printf debugging tells me _cost is called twice each time. Is that normal?

This is a question I really desire to be answered. No one knows...

Gregor Heger
on 12/8/15, 1:44 PM

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

0 follower(s)


Asked: 2/20/14, 5:47 AM
Seen: 1066 times
Last updated: 12/8/15, 1:43 PM