diff --git a/partner_pricelist_search/__manifest__.py b/partner_pricelist_search/__manifest__.py index 84efccb2c..3447fdae5 100644 --- a/partner_pricelist_search/__manifest__.py +++ b/partner_pricelist_search/__manifest__.py @@ -4,16 +4,11 @@ { "name": "Partner pricelist search", "version": "12.0.1.0.0", - "author": "Tecnativa," - "Odoo Community Association (OCA)", + "author": "Tecnativa," "Odoo Community Association (OCA)", "website": "https://github.com/OCA/partner-contact", "category": "Partner Management", - "depends": [ - "product", - ], - "data": [ - "views/product_pricelist_views.xml", - ], + "depends": ["product",], + "data": ["views/product_pricelist_views.xml",], "installable": True, "license": "AGPL-3", } diff --git a/partner_pricelist_search/models/product_pricelist.py b/partner_pricelist_search/models/product_pricelist.py index 35706dd88..ed2ea12c6 100644 --- a/partner_pricelist_search/models/product_pricelist.py +++ b/partner_pricelist_search/models/product_pricelist.py @@ -15,7 +15,7 @@ class Pricelist(models.Model): partners = self.env["res.partner"].search(domain) action = self.env.ref("base.action_partner_form") res = action.read()[0] - res['domain'] = [ - ('id', 'in', partners.ids), + res["domain"] = [ + ("id", "in", partners.ids), ] return res diff --git a/partner_pricelist_search/models/res_partner.py b/partner_pricelist_search/models/res_partner.py index 6b1c82756..aa5066030 100644 --- a/partner_pricelist_search/models/res_partner.py +++ b/partner_pricelist_search/models/res_partner.py @@ -9,25 +9,35 @@ class Pricelist(models.Model): _inherit = "res.partner" property_product_pricelist = fields.Many2one( - search="_search_property_product_pricelist") + 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) + 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)] diff --git a/partner_pricelist_search/tests/test_partner_pricelist_search.py b/partner_pricelist_search/tests/test_partner_pricelist_search.py index 5d0eedbf0..435f96ff9 100644 --- a/partner_pricelist_search/tests/test_partner_pricelist_search.py +++ b/partner_pricelist_search/tests/test_partner_pricelist_search.py @@ -9,69 +9,74 @@ class TestPartnerPricelistSearch(common.SavepointCase): @classmethod def setUpClass(cls): super().setUpClass() - cls.pricelist_1 = cls.env["product.pricelist"].create({ - "name": "Test pricelist 1", - }) - cls.pricelist_2 = cls.env["product.pricelist"].create({ - "name": "Test pricelist 2", - }) - cls.customer_1 = cls.env["res.partner"].create({ - "name": "Test customer 1", - "property_product_pricelist": cls.pricelist_1, - }) - cls.customer_2 = cls.env["res.partner"].create({ - "name": "Test customer 2", - "property_product_pricelist": cls.pricelist_2, - }) + cls.pricelist_1 = cls.env["product.pricelist"].create( + {"name": "Test pricelist 1",} + ) + cls.pricelist_2 = cls.env["product.pricelist"].create( + {"name": "Test pricelist 2",} + ) + cls.customer_1 = cls.env["res.partner"].create( + {"name": "Test customer 1", "property_product_pricelist": cls.pricelist_1,} + ) + cls.customer_2 = cls.env["res.partner"].create( + {"name": "Test customer 2", "property_product_pricelist": cls.pricelist_2,} + ) cls.partner_obj = cls.env["res.partner"] def test_partner_pricelist_search_equal(self): """ Test search '=' """ - partners = self.partner_obj.search([ - ("property_product_pricelist", "=", - self.pricelist_1.id) - ]) + partners = self.partner_obj.search( + [("property_product_pricelist", "=", self.pricelist_1.id)] + ) self.assertEqual(partners, self.customer_1) def test_partner_pricelist_search_in(self): """ Test search 'in' """ - partners = self.partner_obj.search([ - ("property_product_pricelist", "in", - (self.pricelist_1 | self.pricelist_2).ids) - ]) + partners = self.partner_obj.search( + [ + ( + "property_product_pricelist", + "in", + (self.pricelist_1 | self.pricelist_2).ids, + ) + ] + ) self.assertIn(self.customer_1, partners) self.assertIn(self.customer_2, partners) def test_partner_pricelist_search_not_equal(self): """ Test search 'not equal' """ - partners = self.partner_obj.search([ - ("property_product_pricelist", "!=", - self.pricelist_1.id) - ]) + partners = self.partner_obj.search( + [("property_product_pricelist", "!=", self.pricelist_1.id)] + ) self.assertNotIn(self.customer_1, partners) self.assertIn(self.customer_2, partners) def test_partner_pricelist_search_not_in(self): """ Test search 'not in' """ - partners = self.partner_obj.search([ - ("property_product_pricelist", "not in", - (self.pricelist_1 | self.pricelist_2).ids) - ]) + partners = self.partner_obj.search( + [ + ( + "property_product_pricelist", + "not in", + (self.pricelist_1 | self.pricelist_2).ids, + ) + ] + ) self.assertNotIn(self.customer_1, 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") - ]) + self.partner_obj.search( + [("property_product_pricelist", "ilike", "pricelist xx")] + ) def test_show_pricelist_partners(self): res = self.pricelist_1.show_pricelist_partners() - self.assertEqual(self.partner_obj.search(res["domain"]), - self.customer_1) + self.assertEqual(self.partner_obj.search(res["domain"]), self.customer_1) res = (self.pricelist_1 | self.pricelist_2).show_pricelist_partners() - self.assertEqual(self.partner_obj.search(res["domain"]), - (self.customer_1 | self.customer_2)) + self.assertEqual( + self.partner_obj.search(res["domain"]), (self.customer_1 | self.customer_2) + ) diff --git a/partner_pricelist_search/views/product_pricelist_views.xml b/partner_pricelist_search/views/product_pricelist_views.xml index 8c5e95038..0bf277111 100644 --- a/partner_pricelist_search/views/product_pricelist_views.xml +++ b/partner_pricelist_search/views/product_pricelist_views.xml @@ -1,13 +1,17 @@ - + product.pricelist - +