Browse Source

Merge PR #1384 into 14.0

Signed-off-by pedrobaeza
14.0
OCA-git-bot 2 years ago
parent
commit
945924b5c6
  1. 57
      partner_pricelist_search/models/res_partner.py
  2. 14
      partner_pricelist_search/tests/test_partner_pricelist_search.py

57
partner_pricelist_search/models/res_partner.py

@ -1,11 +1,10 @@
# Copyright 2021 Tecnativa - Carlos Dauden # Copyright 2021 Tecnativa - Carlos Dauden
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
from odoo import _, api, fields, models
from odoo.exceptions import UserError
from odoo import api, fields, models
class Pricelist(models.Model):
class ResPartner(models.Model):
_inherit = "res.partner" _inherit = "res.partner"
property_product_pricelist = fields.Many2one( property_product_pricelist = fields.Many2one(
@ -13,31 +12,27 @@ class Pricelist(models.Model):
) )
@api.model @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 search(self, args, offset=0, limit=None, order=None, count=False):
# Substitute pricelist tuple
partner_domain = [
(1, "=", 1)
if (isinstance(x, (list, tuple)) and x[0] == "property_product_pricelist")
else x
for x in args
]
return super(
ResPartner, self.with_context(search_partner_domain=partner_domain)
).search(
args,
offset=offset,
limit=limit,
order=order,
count=count,
)
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)]
@api.model
def _search_property_product_pricelist(self, operator, value):
domain = self.env.context.get("search_partner_domain", [])
partners = self.with_context(prefetch_fields=False).search(domain)
key = "property_product_pricelist"
return [("id", "in", partners.filtered_domain([(key, operator, value)]).ids)]

14
partner_pricelist_search/tests/test_partner_pricelist_search.py

@ -1,7 +1,6 @@
# Copyright 2021 Tecnativa - Carlos Dauden # Copyright 2021 Tecnativa - Carlos Dauden
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl) # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl)
from odoo.exceptions import UserError
from odoo.tests import common from odoo.tests import common
@ -66,12 +65,13 @@ class TestPartnerPricelistSearch(common.SavepointCase):
self.assertNotIn(self.customer_1, partners) self.assertNotIn(self.customer_1, partners)
self.assertNotIn(self.customer_2, partners) self.assertNotIn(self.customer_2, partners)
def test_partner_pricelist_search_not_implemented(self):
"""Test search not implemented"""
with self.assertRaises(UserError):
self.partner_obj.search(
[("property_product_pricelist", "ilike", "pricelist xx")]
)
def test_partner_pricelist_search_ilike(self):
"""Test search 'ilike'"""
partners = self.partner_obj.search(
[("property_product_pricelist", "ilike", "Test pricelist 1")]
)
self.assertIn(self.customer_1, partners)
self.assertNotIn(self.customer_2, partners)
def test_show_pricelist_partners(self): def test_show_pricelist_partners(self):
res = self.pricelist_1.show_pricelist_partners() res = self.pricelist_1.show_pricelist_partners()

Loading…
Cancel
Save