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

Avatar
Discard

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)]

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!