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.

38 lines
1.2 KiB

  1. # Copyright 2021 Tecnativa - Carlos Dauden
  2. # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
  3. from odoo import api, fields, models
  4. class ResPartner(models.Model):
  5. _inherit = "res.partner"
  6. property_product_pricelist = fields.Many2one(
  7. search="_search_property_product_pricelist"
  8. )
  9. @api.model
  10. def search(self, args, offset=0, limit=None, order=None, count=False):
  11. # Substitute pricelist tuple
  12. partner_domain = [
  13. (1, "=", 1)
  14. if (isinstance(x, (list, tuple)) and x[0] == "property_product_pricelist")
  15. else x
  16. for x in args
  17. ]
  18. return super(
  19. ResPartner, self.with_context(search_partner_domain=partner_domain)
  20. ).search(
  21. args,
  22. offset=offset,
  23. limit=limit,
  24. order=order,
  25. count=count,
  26. )
  27. @api.model
  28. def _search_property_product_pricelist(self, operator, value):
  29. domain = self.env.context.get("search_partner_domain", [])
  30. partners = self.with_context(prefetch_fields=False).search(domain)
  31. key = "property_product_pricelist"
  32. return [("id", "in", partners.filtered_domain([(key, operator, value)]).ids)]