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...