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.

33 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. @api.model
  10. def _search_property_product_pricelist(self, operator, value):
  11. if operator == "=":
  12. def filter_func(partner):
  13. return partner.property_product_pricelist.id == value
  14. elif operator == "!=":
  15. def filter_func(partner):
  16. return partner.property_product_pricelist.id != value
  17. elif operator == "in":
  18. def filter_func(partner):
  19. return partner.property_product_pricelist.id in value
  20. elif operator == "not in":
  21. def filter_func(partner):
  22. return partner.property_product_pricelist.id not in value
  23. else:
  24. raise UserError(_(
  25. "Pricelist field do not support search with the operator '%s'."
  26. ) % operator)
  27. partners = self.with_context(prefetch_fields=False).search([])
  28. return [("id", "in", partners.filtered(filter_func).ids)]