Browse Source

[IMP] partner_pricelist_search: black, isort, prettier

14.0
Pedro M. Baeza 4 years ago
committed by Víctor Martínez
parent
commit
e2526b7166
  1. 11
      partner_pricelist_search/__manifest__.py
  2. 4
      partner_pricelist_search/models/product_pricelist.py
  3. 18
      partner_pricelist_search/models/res_partner.py
  4. 81
      partner_pricelist_search/tests/test_partner_pricelist_search.py
  5. 14
      partner_pricelist_search/views/product_pricelist_views.xml

11
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",
}

4
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

18
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)]

81
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)
)

14
partner_pricelist_search/views/product_pricelist_views.xml

@ -1,13 +1,17 @@
<?xml version="1.0" encoding="utf-8"?>
<?xml version="1.0" encoding="utf-8" ?>
<odoo>
<record id="product_pricelist_view" model="ir.ui.view">
<field name="model">product.pricelist</field>
<field name="inherit_id" ref="product.product_pricelist_view"/>
<field name="inherit_id" ref="product.product_pricelist_view" />
<field name="arch" type="xml">
<button name="toggle_active" position="before">
<button name="show_pricelist_partners" type="object"
string="Customers"
class="oe_stat_button" icon="fa-users"/>
<button
name="show_pricelist_partners"
type="object"
string="Customers"
class="oe_stat_button"
icon="fa-users"
/>
</button>
</field>
</record>

Loading…
Cancel
Save