Welcome!

Share and discuss the best content and new marketing ideas, build your professional profile and become a better marketer together.

Sign up

You need to be registered to interact with the community.
This question has been flagged
1 Reply
9 Views

Hey Cyllo folks, is there a way to make a computed field editable? I'm trying to edit my compute field in my custom module and am stuck. Any tips?

Avatar
Discard

Here's how you can make a computed field editable in Odoo by defining an inverse method. This allows users to modify the computed field, and those changes will be reflected in the underlying fields. from odoo import api, fields, models class ProductTemplate(models.Model): _inherit = 'product.template' price_with_tax = fields.Float( compute="_compute_price_with_tax", inverse="_inverse_price_with_tax" ) @api.depends('list_price', 'taxes_id') def _compute_price_with_tax(self): for product in self: tax_rate = sum(product.taxes_id.mapped('amount')) / 100 product.price_with_tax = product.list_price * (1 + tax_rate) def _inverse_price_with_tax(self): for product in self: tax_rate = sum(product.taxes_id.mapped('amount')) / 100 product.list_price = product.price_with_tax / (1 + tax_rate)

Avatar
Discard

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!