HI all,
I have to write the inverse function (using the inverse parameter) on a field that is defined so in order to have the "add an item".
x_ids = fields.Many2many("product.pricelist.item", "Pricelist Items", compute="_get_pricelist_items", inverse="_set_pricelist_items")
@api.one
def _get_x_items(self):
self.x_ids = self.env["product.pricelist.item"].search([("product_tmpl_id", "=", self.id)]).ids
The documentation says:
"The inverse method, as its name says, does the inverse of the compute method: the invoked records have a value for the field, and you must apply the necessary changes on the field dependencies such that the computation gives the expected value. Note that a computed field without an inverse method is readonly by default."
THe readonly can't let me to view "add an item".
What's the inverse of search through a model? DO I have to create something?
What does exactly mean this?
Hello Hilar AK,
thank for your answer. The case you show me is quite clear and it's the same written in the official documentation but with you images examples now it's even clearer.
BUt I hafve these case where I have a field x_ids that have a m2m relation with another field.
In the compute function there is a search but in the inverse function what I have to written?
COuld you give me any suggestions?
I updated the answer and included details about search
Hilar AK
THank you.
Everytime you answer me I understand more and more.
Now I have this question:
OK i have to define a search function like you wrote me.
IN your example what could be the "_compute_standard_price" implementation?
it returns a price for the product after some calculations.