You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

43 lines
1.3 KiB

  1. # Copyright 2021 Tecnativa - Carlos Dauden
  2. # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
  3. from odoo import _, api, fields, models
  4. from odoo.exceptions import UserError
  5. class Pricelist(models.Model):
  6. _inherit = "res.partner"
  7. property_product_pricelist = fields.Many2one(
  8. search="_search_property_product_pricelist"
  9. )
  10. @api.model
  11. def _search_property_product_pricelist(self, operator, value):
  12. if operator == "=":
  13. def filter_func(partner):
  14. return partner.property_product_pricelist.id == value
  15. elif operator == "!=":
  16. def filter_func(partner):
  17. return partner.property_product_pricelist.id != value
  18. elif operator == "in":
  19. def filter_func(partner):
  20. return partner.property_product_pricelist.id in value
  21. elif operator == "not in":
  22. def filter_func(partner):
  23. return partner.property_product_pricelist.id not in value
  24. else:
  25. raise UserError(
  26. _("Pricelist field do not support search with the operator '%s'.")
  27. % operator
  28. )
  29. partners = self.with_context(prefetch_fields=False).search([])
  30. return [("id", "in", partners.filtered(filter_func).ids)]