mirror of
https://gitlab.com/flectra-community/partner-contact.git
synced 2024-12-25 05:41:47 +00:00
44 lines
1.3 KiB
Python
44 lines
1.3 KiB
Python
|
# Copyright 2021 Tecnativa - Carlos Dauden
|
||
|
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
||
|
|
||
|
from flectra import _, api, fields, models
|
||
|
from flectra.exceptions import UserError
|
||
|
|
||
|
|
||
|
class Pricelist(models.Model):
|
||
|
_inherit = "res.partner"
|
||
|
|
||
|
property_product_pricelist = fields.Many2one(
|
||
|
search="_search_property_product_pricelist"
|
||
|
)
|
||
|
|
||
|
@api.model
|
||
|
def _search_property_product_pricelist(self, operator, value):
|
||
|
if operator == "=":
|
||
|
|
||
|
def filter_func(partner):
|
||
|
return partner.property_product_pricelist.id == value
|
||
|
|
||
|
elif operator == "!=":
|
||
|
|
||
|
def filter_func(partner):
|
||
|
return partner.property_product_pricelist.id != value
|
||
|
|
||
|
elif operator == "in":
|
||
|
|
||
|
def filter_func(partner):
|
||
|
return partner.property_product_pricelist.id in value
|
||
|
|
||
|
elif operator == "not in":
|
||
|
|
||
|
def filter_func(partner):
|
||
|
return partner.property_product_pricelist.id not in value
|
||
|
|
||
|
else:
|
||
|
raise UserError(
|
||
|
_("Pricelist field do not support search with the operator '%s'.")
|
||
|
% operator
|
||
|
)
|
||
|
partners = self.with_context(prefetch_fields=False).search([])
|
||
|
return [("id", "in", partners.filtered(filter_func).ids)]
|