diff --git a/partner_pricelist_search/README.rst b/partner_pricelist_search/README.rst new file mode 100644 index 00000000000..f7cf3c2a36c --- /dev/null +++ b/partner_pricelist_search/README.rst @@ -0,0 +1,87 @@ +======================== +Partner pricelist search +======================== + +.. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png + :target: https://odoo-community.org/page/development-status + :alt: Beta +.. |badge2| image:: https://img.shields.io/badge/licence-AGPL--3-blue.png + :target: http://www.gnu.org/licenses/agpl-3.0-standalone.html + :alt: License: AGPL-3 +.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fpartner--contact-lightgray.png?logo=github + :target: https://github.com/OCA/partner-contact/tree/15.0/partner_pricelist_search + :alt: OCA/partner-contact +.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png + :target: https://translation.odoo-community.org/projects/partner-contact-15-0/partner-contact-15-0-partner_pricelist_search + :alt: Translate me on Weblate +.. |badge5| image:: https://img.shields.io/badge/runbot-Try%20me-875A7B.png + :target: https://runbot.odoo-community.org/runbot/134/15.0 + :alt: Try me on Runbot + +|badge1| |badge2| |badge3| |badge4| |badge5| + +This module adds search by pricelist field option in partners. + +Also add a new smart button called "Customers" in pricelist form view to show +partners with that pricelist. + +**Table of contents** + +.. contents:: + :local: + +Known issues / Roadmap +====================== + +With many partner records the search can be slow because all partners are +computed. + +No grouping is allowed. + +Bug Tracker +=========== + +Bugs are tracked on `GitHub Issues `_. +In case of trouble, please check there if your issue has already been reported. +If you spotted it first, help us smashing it by providing a detailed and welcomed +`feedback `_. + +Do not contact contributors directly about support or help with technical issues. + +Credits +======= + +Authors +~~~~~~~ + +* Tecnativa + +Contributors +~~~~~~~~~~~~ + +* `Tecnativa `_: + + * Carlos Dauden + * Víctor Martínez + +Maintainers +~~~~~~~~~~~ + +This module is maintained by the OCA. + +.. image:: https://odoo-community.org/logo.png + :alt: Odoo Community Association + :target: https://odoo-community.org + +OCA, or the Odoo Community Association, is a nonprofit organization whose +mission is to support the collaborative development of Odoo features and +promote its widespread use. + +This module is part of the `OCA/partner-contact `_ project on GitHub. + +You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. diff --git a/partner_pricelist_search/__init__.py b/partner_pricelist_search/__init__.py new file mode 100644 index 00000000000..0650744f6bc --- /dev/null +++ b/partner_pricelist_search/__init__.py @@ -0,0 +1 @@ +from . import models diff --git a/partner_pricelist_search/__manifest__.py b/partner_pricelist_search/__manifest__.py new file mode 100644 index 00000000000..da2e23e6c28 --- /dev/null +++ b/partner_pricelist_search/__manifest__.py @@ -0,0 +1,14 @@ +# Copyright 2021 Tecnativa - Carlos Dauden +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl) + +{ + "name": "Partner pricelist search", + "version": "15.0.1.0.0", + "author": "Tecnativa,Odoo Community Association (OCA)", + "website": "https://github.com/OCA/partner-contact", + "category": "Partner Management", + "depends": ["product"], + "data": ["views/product_pricelist_views.xml"], + "installable": True, + "license": "AGPL-3", +} diff --git a/partner_pricelist_search/i18n/es.po b/partner_pricelist_search/i18n/es.po new file mode 100644 index 00000000000..83c0ce259ea --- /dev/null +++ b/partner_pricelist_search/i18n/es.po @@ -0,0 +1,63 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * partner_pricelist_search +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 12.0\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2021-01-15 14:06+0000\n" +"PO-Revision-Date: 2021-01-15 15:07+0100\n" +"Last-Translator: Carlos Dauden \n" +"Language-Team: \n" +"Language: es\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: 8bit\n" +"Plural-Forms: nplurals=2; plural=(n != 1);\n" +"X-Generator: Poedit 2.3\n" + +#. module: partner_pricelist_search +#: model:ir.model,name:partner_pricelist_search.model_res_partner +msgid "Contact" +msgstr "Contacto" + +#. module: partner_pricelist_search +#: model_terms:ir.ui.view,arch_db:partner_pricelist_search.product_pricelist_view +msgid "Customers" +msgstr "Clientes" + +#. module: partner_pricelist_search +#: model:ir.model.fields,field_description:partner_pricelist_search.field_product_pricelist__display_name +#: model:ir.model.fields,field_description:partner_pricelist_search.field_res_partner__display_name +msgid "Display Name" +msgstr "" + +#. module: partner_pricelist_search +#: model:ir.model.fields,field_description:partner_pricelist_search.field_product_pricelist__id +#: model:ir.model.fields,field_description:partner_pricelist_search.field_res_partner__id +msgid "ID" +msgstr "" + +#. module: partner_pricelist_search +#: model:ir.model.fields,field_description:partner_pricelist_search.field_product_pricelist____last_update +#: model:ir.model.fields,field_description:partner_pricelist_search.field_res_partner____last_update +msgid "Last Modified on" +msgstr "" + +#. module: partner_pricelist_search +#: model:ir.model,name:partner_pricelist_search.model_product_pricelist +#: model:ir.model.fields,field_description:partner_pricelist_search.field_res_partner__property_product_pricelist +#: model:ir.model.fields,field_description:partner_pricelist_search.field_res_users__property_product_pricelist +msgid "Pricelist" +msgstr "Tarifa" + +#. module: partner_pricelist_search +#: model:ir.model.fields,help:partner_pricelist_search.field_res_partner__property_product_pricelist +#: model:ir.model.fields,help:partner_pricelist_search.field_res_users__property_product_pricelist +msgid "" +"This pricelist will be used, instead of the default one, for sales to the " +"current partner" +msgstr "" +"Esta tarifa se utilizará, en lugar de la por defecto, para las ventas de la " +"empresa actual" diff --git a/partner_pricelist_search/i18n/partner_pricelist_search.pot b/partner_pricelist_search/i18n/partner_pricelist_search.pot new file mode 100644 index 00000000000..10fa093ef4a --- /dev/null +++ b/partner_pricelist_search/i18n/partner_pricelist_search.pot @@ -0,0 +1,57 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * partner_pricelist_search +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 14.0\n" +"Report-Msgid-Bugs-To: \n" +"Last-Translator: \n" +"Language-Team: \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: \n" + +#. module: partner_pricelist_search +#: model:ir.model,name:partner_pricelist_search.model_res_partner +msgid "Contact" +msgstr "" + +#. module: partner_pricelist_search +#: model_terms:ir.ui.view,arch_db:partner_pricelist_search.product_pricelist_view +msgid "Customers" +msgstr "" + +#. module: partner_pricelist_search +#: model:ir.model.fields,field_description:partner_pricelist_search.field_product_pricelist__display_name +#: model:ir.model.fields,field_description:partner_pricelist_search.field_res_partner__display_name +msgid "Display Name" +msgstr "" + +#. module: partner_pricelist_search +#: model:ir.model.fields,field_description:partner_pricelist_search.field_product_pricelist__id +#: model:ir.model.fields,field_description:partner_pricelist_search.field_res_partner__id +msgid "ID" +msgstr "" + +#. module: partner_pricelist_search +#: model:ir.model.fields,field_description:partner_pricelist_search.field_product_pricelist____last_update +#: model:ir.model.fields,field_description:partner_pricelist_search.field_res_partner____last_update +msgid "Last Modified on" +msgstr "" + +#. module: partner_pricelist_search +#: model:ir.model,name:partner_pricelist_search.model_product_pricelist +#: model:ir.model.fields,field_description:partner_pricelist_search.field_res_partner__property_product_pricelist +#: model:ir.model.fields,field_description:partner_pricelist_search.field_res_users__property_product_pricelist +msgid "Pricelist" +msgstr "" + +#. module: partner_pricelist_search +#: model:ir.model.fields,help:partner_pricelist_search.field_res_partner__property_product_pricelist +#: model:ir.model.fields,help:partner_pricelist_search.field_res_users__property_product_pricelist +msgid "" +"This pricelist will be used, instead of the default one, for sales to the " +"current partner" +msgstr "" diff --git a/partner_pricelist_search/models/__init__.py b/partner_pricelist_search/models/__init__.py new file mode 100644 index 00000000000..978a9c74806 --- /dev/null +++ b/partner_pricelist_search/models/__init__.py @@ -0,0 +1,2 @@ +from . import product_pricelist +from . import res_partner diff --git a/partner_pricelist_search/models/product_pricelist.py b/partner_pricelist_search/models/product_pricelist.py new file mode 100644 index 00000000000..d0fbde9ff4f --- /dev/null +++ b/partner_pricelist_search/models/product_pricelist.py @@ -0,0 +1,14 @@ +# Copyright 2021 Tecnativa - Carlos Dauden +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl) + +from odoo import models + + +class Pricelist(models.Model): + _inherit = "product.pricelist" + + def show_pricelist_partners(self): + xmlid = "base.action_partner_form" + action = self.env["ir.actions.act_window"]._for_xml_id(xmlid) + action["domain"] = [("property_product_pricelist", "in", self.ids)] + return action diff --git a/partner_pricelist_search/models/res_partner.py b/partner_pricelist_search/models/res_partner.py new file mode 100644 index 00000000000..052f66a65cb --- /dev/null +++ b/partner_pricelist_search/models/res_partner.py @@ -0,0 +1,38 @@ +# Copyright 2021 Tecnativa - Carlos Dauden +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from odoo import api, fields, models + + +class ResPartner(models.Model): + _inherit = "res.partner" + + property_product_pricelist = fields.Many2one( + search="_search_property_product_pricelist" + ) + + @api.model + 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, + ) + + @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)] diff --git a/partner_pricelist_search/readme/CONTRIBUTORS.rst b/partner_pricelist_search/readme/CONTRIBUTORS.rst new file mode 100644 index 00000000000..0bd598fcf7d --- /dev/null +++ b/partner_pricelist_search/readme/CONTRIBUTORS.rst @@ -0,0 +1,4 @@ +* `Tecnativa `_: + + * Carlos Dauden + * Víctor Martínez diff --git a/partner_pricelist_search/readme/DESCRIPTION.rst b/partner_pricelist_search/readme/DESCRIPTION.rst new file mode 100644 index 00000000000..f8ad3983139 --- /dev/null +++ b/partner_pricelist_search/readme/DESCRIPTION.rst @@ -0,0 +1,4 @@ +This module adds search by pricelist field option in partners. + +Also add a new smart button called "Customers" in pricelist form view to show +partners with that pricelist. diff --git a/partner_pricelist_search/readme/ROADMAP.rst b/partner_pricelist_search/readme/ROADMAP.rst new file mode 100644 index 00000000000..2568d59b2a1 --- /dev/null +++ b/partner_pricelist_search/readme/ROADMAP.rst @@ -0,0 +1,4 @@ +With many partner records the search can be slow because all partners are +computed. + +No grouping is allowed. diff --git a/partner_pricelist_search/static/description/icon.png b/partner_pricelist_search/static/description/icon.png new file mode 100644 index 00000000000..3a0328b516c Binary files /dev/null and b/partner_pricelist_search/static/description/icon.png differ diff --git a/partner_pricelist_search/static/description/index.html b/partner_pricelist_search/static/description/index.html new file mode 100644 index 00000000000..8ae9acc1b55 --- /dev/null +++ b/partner_pricelist_search/static/description/index.html @@ -0,0 +1,432 @@ + + + + + + +Partner pricelist search + + + + + + diff --git a/partner_pricelist_search/tests/__init__.py b/partner_pricelist_search/tests/__init__.py new file mode 100644 index 00000000000..06c448861fe --- /dev/null +++ b/partner_pricelist_search/tests/__init__.py @@ -0,0 +1 @@ +from . import test_partner_pricelist_search diff --git a/partner_pricelist_search/tests/test_partner_pricelist_search.py b/partner_pricelist_search/tests/test_partner_pricelist_search.py new file mode 100644 index 00000000000..7762fa52e35 --- /dev/null +++ b/partner_pricelist_search/tests/test_partner_pricelist_search.py @@ -0,0 +1,83 @@ +# Copyright 2021 Tecnativa - Carlos Dauden +# Copyright 2022 Tecnativa - Víctor Martínez +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl) + +from odoo.tests import common + + +class TestPartnerPricelistSearch(common.TransactionCase): + @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.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)] + ) + 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, + ) + ] + ) + 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)] + ) + 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, + ) + ] + ) + self.assertNotIn(self.customer_1, partners) + self.assertNotIn(self.customer_2, partners) + + 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): + res = self.pricelist_1.show_pricelist_partners() + 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) + ) diff --git a/partner_pricelist_search/views/product_pricelist_views.xml b/partner_pricelist_search/views/product_pricelist_views.xml new file mode 100644 index 00000000000..09e7c9dedee --- /dev/null +++ b/partner_pricelist_search/views/product_pricelist_views.xml @@ -0,0 +1,20 @@ + + + + product.pricelist + + + +
+
+
+
+
+
diff --git a/setup/partner_pricelist_search/odoo/addons/partner_pricelist_search b/setup/partner_pricelist_search/odoo/addons/partner_pricelist_search new file mode 120000 index 00000000000..79e3220d1b2 --- /dev/null +++ b/setup/partner_pricelist_search/odoo/addons/partner_pricelist_search @@ -0,0 +1 @@ +../../../../partner_pricelist_search \ No newline at end of file diff --git a/setup/partner_pricelist_search/setup.py b/setup/partner_pricelist_search/setup.py new file mode 100644 index 00000000000..28c57bb6403 --- /dev/null +++ b/setup/partner_pricelist_search/setup.py @@ -0,0 +1,6 @@ +import setuptools + +setuptools.setup( + setup_requires=['setuptools-odoo'], + odoo_addon=True, +)