Hey Cyllo community! Is it possible to search on a computed field? I'm having trouble finding anything in the search bar related to my computed field. Any tips or tricks?
Welcome!
Share and discuss the best content and new marketing ideas, build your professional profile and become a better marketer together.
This question has been flagged
Here's how you can add a custom search method to enable searching on a computed field in Odoo. This approach avoids the need to store the computed field in the database. from odoo import api, fields, models class ProductTemplate(models.Model): _inherit = 'product.template' price_with_tax = fields.Float( compute="_compute_price_with_tax", search="_search_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 _search_price_with_tax(self, operator, value): tax_ids = self.env['account.tax'].search([]) tax_rate = sum(tax_ids.mapped('amount')) / 100 adjusted_value = value / (1 + tax_rate) return [('list_price', operator, adjusted_value)]