Odoo 15 website_sale - search for custom attribute

44 Views Asked by At

I need to search for a custom attribute (text - i created a controller in my custom module and added this code:

from odoo.addons.website_sale.controllers.main import WebsiteSale
from odoo.osv.expression import OR

class WebsiteSaleInherit(WebsiteSale):
    def _get_search_domain(self, search, category, attrib_values, search_in_description=False):
        print("in custom controller")
        # Call the super method to get the initial domain
        domain = super()._get_search_domain(
            search, category, attrib_values,
            search_in_description=search_in_description
        )

        if search:
            domain = OR([domain, [('wine_award', 'ilike', search)]])
            print(domain)
        return domain

The code get's called, but the filter doesn't have any effect (doesn't work)

The attribute is defined like this:

class Wine(models.Model): _inherit = 'product.template' wine_award = fields.Text(string="Wine award")

I've implemented the code and when i print from the code i can see, that the controller is called and the domain gets changed:

print(domain) in the controller gives:

['|', '&', '&', ('sale_ok', '=', True), ('website_id', 'in', (False, 4)), '|', '|', ('name', 'ilike', 'Yves'), ('wine_award', 'ilike', 'Yves'), ('product_variant_ids.default_code', 'ilike', 'Yves'), ('wine_award', 'ilike', 'Yves')]

0

There are 0 best solutions below