From d944880478264c784b6a0b3ffed4d87a61b5c11f Mon Sep 17 00:00:00 2001 From: Telmo Santos Date: Tue, 16 Jan 2024 07:31:57 +0100 Subject: [PATCH] [ADD] sale_loyalty_industry --- sale_loyalty_industry/README.rst | 76 ++++ sale_loyalty_industry/__init__.py | 1 + sale_loyalty_industry/__manifest__.py | 19 + sale_loyalty_industry/i18n/fr.po | 22 + .../i18n/sale_loyalty_industry.pot | 36 ++ sale_loyalty_industry/models/__init__.py | 2 + .../models/loyalty_program.py | 15 + sale_loyalty_industry/models/sale_order.py | 26 ++ sale_loyalty_industry/readme/CONTRIBUTORS.rst | 1 + sale_loyalty_industry/readme/DESCRIPTION.rst | 1 + .../static/description/index.html | 421 ++++++++++++++++++ sale_loyalty_industry/tests/__init__.py | 1 + .../tests/test_program_rules.py | 97 ++++ .../views/loyalty_program_views.xml | 12 + .../odoo/addons/sale_loyalty_industry | 1 + setup/sale_loyalty_industry/setup.py | 6 + 16 files changed, 737 insertions(+) create mode 100644 sale_loyalty_industry/README.rst create mode 100644 sale_loyalty_industry/__init__.py create mode 100644 sale_loyalty_industry/__manifest__.py create mode 100644 sale_loyalty_industry/i18n/fr.po create mode 100644 sale_loyalty_industry/i18n/sale_loyalty_industry.pot create mode 100644 sale_loyalty_industry/models/__init__.py create mode 100644 sale_loyalty_industry/models/loyalty_program.py create mode 100644 sale_loyalty_industry/models/sale_order.py create mode 100644 sale_loyalty_industry/readme/CONTRIBUTORS.rst create mode 100644 sale_loyalty_industry/readme/DESCRIPTION.rst create mode 100644 sale_loyalty_industry/static/description/index.html create mode 100644 sale_loyalty_industry/tests/__init__.py create mode 100644 sale_loyalty_industry/tests/test_program_rules.py create mode 100644 sale_loyalty_industry/views/loyalty_program_views.xml create mode 120000 setup/sale_loyalty_industry/odoo/addons/sale_loyalty_industry create mode 100644 setup/sale_loyalty_industry/setup.py diff --git a/sale_loyalty_industry/README.rst b/sale_loyalty_industry/README.rst new file mode 100644 index 000000000..e9ee8614f --- /dev/null +++ b/sale_loyalty_industry/README.rst @@ -0,0 +1,76 @@ +====================== +Sale loyality industry +====================== + +.. + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! source digest: sha256:88249b5ea969933e22011aa34eac20d073bfec55af55c7f447f3b27993ea5e51 + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |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%2Fsale--promotion-lightgray.png?logo=github + :target: https://github.com/OCA/sale-promotion/tree/16.0/sale_loyalty_industry + :alt: OCA/sale-promotion +.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png + :target: https://translation.odoo-community.org/projects/sale-promotion-16-0/sale-promotion-16-0-sale_loyalty_industry + :alt: Translate me on Weblate +.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png + :target: https://runboat.odoo-community.org/builds?repo=OCA/sale-promotion&target_branch=16.0 + :alt: Try me on Runboat + +|badge1| |badge2| |badge3| |badge4| |badge5| + +This module allow to restrict the industries in which the sale loyalty program applies. + +**Table of contents** + +.. contents:: + :local: + +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 to smash it by providing a detailed and welcomed +`feedback `_. + +Do not contact contributors directly about support or help with technical issues. + +Credits +======= + +Authors +~~~~~~~ + +* Camptocamp + +Contributors +~~~~~~~~~~~~ + +* Telmo Santos + +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/sale-promotion `_ project on GitHub. + +You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. diff --git a/sale_loyalty_industry/__init__.py b/sale_loyalty_industry/__init__.py new file mode 100644 index 000000000..0650744f6 --- /dev/null +++ b/sale_loyalty_industry/__init__.py @@ -0,0 +1 @@ +from . import models diff --git a/sale_loyalty_industry/__manifest__.py b/sale_loyalty_industry/__manifest__.py new file mode 100644 index 000000000..73a3c5b03 --- /dev/null +++ b/sale_loyalty_industry/__manifest__.py @@ -0,0 +1,19 @@ +# Copyright 2023 Camptocamp SA +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). +{ + "name": "Sale loyality industry", + "summary": "Sale of loyalty program restricted to industries.", + "version": "16.0.1.0.0", + "author": "Camptocamp, Odoo Community Association (OCA)", + "website": "https://github.com/OCA/sale-promotion", + "license": "AGPL-3", + "category": "Others", + "depends": [ + "sale_loyalty", + "partner_industry_secondary", + ], + "data": [ + "views/loyalty_program_views.xml", + ], + "installable": True, +} diff --git a/sale_loyalty_industry/i18n/fr.po b/sale_loyalty_industry/i18n/fr.po new file mode 100644 index 000000000..0b863f11c --- /dev/null +++ b/sale_loyalty_industry/i18n/fr.po @@ -0,0 +1,22 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * sale_loyalty_industry +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 16.0+e\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2023-12-15 14:23+0000\n" +"PO-Revision-Date: 2023-12-15 14:23+0000\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: sale_loyalty_industry +#: model:ir.model.fields,help:sale_loyalty_industry.field_loyalty_program__industry_ids +msgid "The loyalty program is applied in these industries." +msgstr "Le programme de fidélité est appliqué dans ces secteurs." diff --git a/sale_loyalty_industry/i18n/sale_loyalty_industry.pot b/sale_loyalty_industry/i18n/sale_loyalty_industry.pot new file mode 100644 index 000000000..d6c1f53fc --- /dev/null +++ b/sale_loyalty_industry/i18n/sale_loyalty_industry.pot @@ -0,0 +1,36 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * sale_loyalty_industry +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 16.0+e\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2023-12-15 14:23+0000\n" +"PO-Revision-Date: 2023-12-15 14:23+0000\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: sale_loyalty_industry +#: model:ir.model.fields,field_description:sale_loyalty_industry.field_loyalty_program__industry_ids +msgid "Industries" +msgstr "" + +#. module: sale_loyalty_industry +#: model:ir.model,name:sale_loyalty_industry.model_loyalty_program +msgid "Loyalty Program" +msgstr "" + +#. module: sale_loyalty_industry +#: model:ir.model,name:sale_loyalty_industry.model_sale_order +msgid "Sales Order" +msgstr "" + +#. module: sale_loyalty_industry +#: model:ir.model.fields,help:sale_loyalty_industry.field_loyalty_program__industry_ids +msgid "The loyalty program is applied in these industries." +msgstr "" diff --git a/sale_loyalty_industry/models/__init__.py b/sale_loyalty_industry/models/__init__.py new file mode 100644 index 000000000..f668597f1 --- /dev/null +++ b/sale_loyalty_industry/models/__init__.py @@ -0,0 +1,2 @@ +from . import loyalty_program +from . import sale_order diff --git a/sale_loyalty_industry/models/loyalty_program.py b/sale_loyalty_industry/models/loyalty_program.py new file mode 100644 index 000000000..071eccedd --- /dev/null +++ b/sale_loyalty_industry/models/loyalty_program.py @@ -0,0 +1,15 @@ +# Copyright 2023 Camptocamp SA +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl) + + +from odoo import fields, models + + +class LoyaltyProgram(models.Model): + _inherit = "loyalty.program" + + industry_ids = fields.Many2many( + "res.partner.industry", + string="Industries", + help="The loyalty program is applied in these industries.", + ) diff --git a/sale_loyalty_industry/models/sale_order.py b/sale_loyalty_industry/models/sale_order.py new file mode 100644 index 000000000..e05c4231e --- /dev/null +++ b/sale_loyalty_industry/models/sale_order.py @@ -0,0 +1,26 @@ +# Copyright 2023 Camptocamp SA +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl) + + +from odoo import models +from odoo.osv import expression + + +class SaleOrder(models.Model): + _inherit = "sale.order" + + def _get_program_domain(self): + base_expression = super()._get_program_domain() + domain = expression.AND( + [ + base_expression, + [ + "|", + "|", + ("industry_ids", "=", False), + ("industry_ids", "child_of", self.partner_id.industry_id.ids), + ("industry_ids", "parent_of", self.partner_id.industry_id.ids), + ], + ] + ) + return domain diff --git a/sale_loyalty_industry/readme/CONTRIBUTORS.rst b/sale_loyalty_industry/readme/CONTRIBUTORS.rst new file mode 100644 index 000000000..8ed3aebac --- /dev/null +++ b/sale_loyalty_industry/readme/CONTRIBUTORS.rst @@ -0,0 +1 @@ +* Telmo Santos diff --git a/sale_loyalty_industry/readme/DESCRIPTION.rst b/sale_loyalty_industry/readme/DESCRIPTION.rst new file mode 100644 index 000000000..fb6135d48 --- /dev/null +++ b/sale_loyalty_industry/readme/DESCRIPTION.rst @@ -0,0 +1 @@ +This module allow to restrict the industries in which the sale loyalty program applies. \ No newline at end of file diff --git a/sale_loyalty_industry/static/description/index.html b/sale_loyalty_industry/static/description/index.html new file mode 100644 index 000000000..5e323e7fd --- /dev/null +++ b/sale_loyalty_industry/static/description/index.html @@ -0,0 +1,421 @@ + + + + + + +Sale loyality industry + + + +
+

Sale loyality industry

+ + +

Beta License: AGPL-3 OCA/sale-promotion Translate me on Weblate Try me on Runboat

+

This module allow to restrict the industries in which the sale loyalty program applies.

+

Table of contents

+ +
+

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 to smash it by providing a detailed and welcomed +feedback.

+

Do not contact contributors directly about support or help with technical issues.

+
+
+

Credits

+
+

Authors

+
    +
  • Camptocamp
  • +
+
+ +
+

Maintainers

+

This module is maintained by the OCA.

+Odoo Community Association +

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/sale-promotion project on GitHub.

+

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.

+
+
+
+ + diff --git a/sale_loyalty_industry/tests/__init__.py b/sale_loyalty_industry/tests/__init__.py new file mode 100644 index 000000000..db8bc8a0b --- /dev/null +++ b/sale_loyalty_industry/tests/__init__.py @@ -0,0 +1 @@ +from . import test_program_rules diff --git a/sale_loyalty_industry/tests/test_program_rules.py b/sale_loyalty_industry/tests/test_program_rules.py new file mode 100644 index 000000000..4facbabd2 --- /dev/null +++ b/sale_loyalty_industry/tests/test_program_rules.py @@ -0,0 +1,97 @@ +# Copyright 2023 Camptocamp SA +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl) + +from odoo.addons.sale_loyalty.tests.common import TestSaleCouponCommon + + +class TestProgramRules(TestSaleCouponCommon): + @classmethod + def setUpClass(cls): + super(TestProgramRules, cls).setUpClass() + cls.industry_model = cls.env["res.partner.industry"] + cls.industry_main = cls.industry_model.create({"name": "Main Industry"}) + cls.industry_A = cls.env.ref("base.res_partner_industry_A") + cls.industry_A.parent_id = cls.industry_main + cls.industry_B = cls.env.ref("base.res_partner_industry_B") + cls.industry_B.parent_id = cls.industry_main + + def _create_sale_order(self): + order = self.env["sale.order"].create({"partner_id": self.steve.id}) + order.write( + { + "order_line": [ + ( + 0, + False, + { + "product_id": self.product_A.id, + "name": "1 Product A", + "product_uom": self.uom_unit.id, + "product_uom_qty": 10.0, + }, + ), + ( + 0, + False, + { + "product_id": self.product_B.id, + "name": "2 Product B", + "product_uom": self.uom_unit.id, + "product_uom_qty": 1.0, + }, + ), + ] + } + ) + return order + + def test_program_rules_no_industry(self): + self.immediate_promotion_program.industry_ids = False + + order = self._create_sale_order() + self._auto_rewards(order, self.immediate_promotion_program) + self.assertEqual( + len(order.order_line.ids), + 3, + "The promo offer should have been applied as no industry is set.", + ) + + def test_program_applied_on_customer_industry(self): + self.immediate_promotion_program.industry_ids = self.industry_A + self.steve.industry_id = self.industry_B + order = self._create_sale_order() + self._auto_rewards(order, self.immediate_promotion_program) + self.assertEqual( + len(order.order_line.ids), + 2, + "The promo offer is not applied to industry_B.", + ) + self.immediate_promotion_program.industry_ids = self.industry_B + order = self._create_sale_order() + self._auto_rewards(order, self.immediate_promotion_program) + self.assertEqual( + len(order.order_line.ids), + 3, + "The promo offer should have been applied as to industry_B", + ) + + def test_program_rules_with_customer_parent_industry(self): + self.steve.industry_id = self.industry_main + order = self._create_sale_order() + self._auto_rewards(order, self.immediate_promotion_program) + self.assertEqual( + len(order.order_line.ids), + 3, + "Promo offer applied as the main_industry is a parent industry_B", + ) + + def test_program_rules_with_customer_child_industry(self): + self.steve.industry_id = self.industry_B + self.immediate_promotion_program.industry_ids = self.industry_main + order = self._create_sale_order() + self._auto_rewards(order, self.immediate_promotion_program) + self.assertEqual( + len(order.order_line.ids), + 3, + "Promo offer applied as industry_B is a child of main_industry", + ) diff --git a/sale_loyalty_industry/views/loyalty_program_views.xml b/sale_loyalty_industry/views/loyalty_program_views.xml new file mode 100644 index 000000000..8b163b897 --- /dev/null +++ b/sale_loyalty_industry/views/loyalty_program_views.xml @@ -0,0 +1,12 @@ + + + + + loyalty.program + + + + + + + diff --git a/setup/sale_loyalty_industry/odoo/addons/sale_loyalty_industry b/setup/sale_loyalty_industry/odoo/addons/sale_loyalty_industry new file mode 120000 index 000000000..eae6d1337 --- /dev/null +++ b/setup/sale_loyalty_industry/odoo/addons/sale_loyalty_industry @@ -0,0 +1 @@ +../../../../sale_loyalty_industry \ No newline at end of file diff --git a/setup/sale_loyalty_industry/setup.py b/setup/sale_loyalty_industry/setup.py new file mode 100644 index 000000000..28c57bb64 --- /dev/null +++ b/setup/sale_loyalty_industry/setup.py @@ -0,0 +1,6 @@ +import setuptools + +setuptools.setup( + setup_requires=['setuptools-odoo'], + odoo_addon=True, +)