From fdfce0c92a922ef717fbbf805c06370cda0afd69 Mon Sep 17 00:00:00 2001 From: pilarvargas-tecnativa Date: Thu, 14 Mar 2024 18:04:00 +0100 Subject: [PATCH] [ADD] sale_loyalty_order_suggestion_multi_gift: New module TT48349 --- .../README.rst | 97 ++++ .../__init__.py | 2 + .../__manifest__.py | 14 + .../models/__init__.py | 1 + .../models/sale_order.py | 24 + .../readme/CONTRIBUTORS.rst | 3 + .../readme/DESCRIPTION.rst | 2 + .../readme/ROADMAP.rst | 4 + .../readme/USAGE.rst | 6 + .../static/description/icon.png | Bin 0 -> 6248 bytes .../static/description/index.html | 444 ++++++++++++++++++ .../tests/__init__.py | 2 + ...ale_loyalty_order_suggestion_multi_gift.py | 176 +++++++ .../wizard/__init__.py | 1 + .../wizard/sale_loyalty_reward_wizard.py | 47 ++ .../sale_loyalty_order_suggestion_multi_gift | 1 + .../setup.py | 6 + 17 files changed, 830 insertions(+) create mode 100644 sale_loyalty_order_suggestion_multi_gift/README.rst create mode 100644 sale_loyalty_order_suggestion_multi_gift/__init__.py create mode 100644 sale_loyalty_order_suggestion_multi_gift/__manifest__.py create mode 100644 sale_loyalty_order_suggestion_multi_gift/models/__init__.py create mode 100644 sale_loyalty_order_suggestion_multi_gift/models/sale_order.py create mode 100644 sale_loyalty_order_suggestion_multi_gift/readme/CONTRIBUTORS.rst create mode 100644 sale_loyalty_order_suggestion_multi_gift/readme/DESCRIPTION.rst create mode 100644 sale_loyalty_order_suggestion_multi_gift/readme/ROADMAP.rst create mode 100644 sale_loyalty_order_suggestion_multi_gift/readme/USAGE.rst create mode 100644 sale_loyalty_order_suggestion_multi_gift/static/description/icon.png create mode 100644 sale_loyalty_order_suggestion_multi_gift/static/description/index.html create mode 100644 sale_loyalty_order_suggestion_multi_gift/tests/__init__.py create mode 100644 sale_loyalty_order_suggestion_multi_gift/tests/test_sale_loyalty_order_suggestion_multi_gift.py create mode 100644 sale_loyalty_order_suggestion_multi_gift/wizard/__init__.py create mode 100644 sale_loyalty_order_suggestion_multi_gift/wizard/sale_loyalty_reward_wizard.py create mode 120000 setup/sale_loyalty_order_suggestion_multi_gift/odoo/addons/sale_loyalty_order_suggestion_multi_gift create mode 100644 setup/sale_loyalty_order_suggestion_multi_gift/setup.py diff --git a/sale_loyalty_order_suggestion_multi_gift/README.rst b/sale_loyalty_order_suggestion_multi_gift/README.rst new file mode 100644 index 00000000..9ac34a10 --- /dev/null +++ b/sale_loyalty_order_suggestion_multi_gift/README.rst @@ -0,0 +1,97 @@ +======================================== +Sale Loyalty Order Suggestion Multi Gift +======================================== + +.. + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! source digest: sha256:3d28a9d1cda5d30a6d82161cb677692ee77bd9708deadb6b8b1cdbe2a3b4aa02 + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |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_order_suggestion_multi_gift + :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_order_suggestion_multi_gift + :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 extends the functionality of `sale_loyalty_order_suggestion` by giving hints +of available promotions whose reward is multi-gift and whose rules require a minimum quantity of products. + +**Table of contents** + +.. contents:: + :local: + +Usage +===== + +To use this module: + +* Configure or create a promotion and set in its rules a minimum quantity of products required. +* Create a sales order and add one of the products that were part of the rewards to the order lines. This line will be marked with an icon (🎁) that will appear at the bottom right. +* Click on the icon and the wizard will open with the available promotions. +* Select the promotion and the products needed to apply it. + +Known issues / Roadmap +====================== + +For the moment only suggestions for promotions whose multi-gift rewards include products +added to the sales order and whose rules have product-based criteria will be taken into +account. This module could be extended to take into account other types of rules in the +loyalty programs to be able to apply the promotion from the wizard. + +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 +~~~~~~~ + +* Tecnativa + +Contributors +~~~~~~~~~~~~ + +* `Tecnativa `_: + + * Pilar Vargas + +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_order_suggestion_multi_gift/__init__.py b/sale_loyalty_order_suggestion_multi_gift/__init__.py new file mode 100644 index 00000000..9b429614 --- /dev/null +++ b/sale_loyalty_order_suggestion_multi_gift/__init__.py @@ -0,0 +1,2 @@ +from . import models +from . import wizard diff --git a/sale_loyalty_order_suggestion_multi_gift/__manifest__.py b/sale_loyalty_order_suggestion_multi_gift/__manifest__.py new file mode 100644 index 00000000..f45c2b82 --- /dev/null +++ b/sale_loyalty_order_suggestion_multi_gift/__manifest__.py @@ -0,0 +1,14 @@ +# Copyright 2024 Tecnativa - Pilar Vargas +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). +{ + "name": "Sale Loyalty Order Suggestion Multi Gift", + "summary": "Suggest promotions with rewards multi gift in the sale order line", + "version": "16.0.1.0.0", + "development_status": "Beta", + "category": "Sale", + "website": "https://github.com/OCA/sale-promotion", + "author": "Tecnativa, Odoo Community Association (OCA)", + "license": "AGPL-3", + "depends": ["sale_loyalty_order_suggestion", "sale_loyalty_multi_gift"], + "installable": True, +} diff --git a/sale_loyalty_order_suggestion_multi_gift/models/__init__.py b/sale_loyalty_order_suggestion_multi_gift/models/__init__.py new file mode 100644 index 00000000..6aacb753 --- /dev/null +++ b/sale_loyalty_order_suggestion_multi_gift/models/__init__.py @@ -0,0 +1 @@ +from . import sale_order diff --git a/sale_loyalty_order_suggestion_multi_gift/models/sale_order.py b/sale_loyalty_order_suggestion_multi_gift/models/sale_order.py new file mode 100644 index 00000000..6fa30967 --- /dev/null +++ b/sale_loyalty_order_suggestion_multi_gift/models/sale_order.py @@ -0,0 +1,24 @@ +# Copyright 2024 Tecnativa - Pilar Vargas +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). +from odoo import models + + +class SaleOrder(models.Model): + _inherit = "sale.order" + + def _available_programs(self): + self.ensure_one() + filtered_programs = self._filter_programs_by_rules_with_products() + programs_with_reward_multi_gift = filtered_programs.filtered( + lambda x: any(reward.reward_type == "multi_gift" for reward in x.reward_ids) + ) + programs = self.env["loyalty.program"] + if programs_with_reward_multi_gift: + product_id = self.env.context.get("product_id") + programs += programs_with_reward_multi_gift.filtered( + lambda x: any( + product_id in reward.loyalty_multi_gift_ids.reward_product_ids.ids + for reward in x.reward_ids + ) + ) + return super()._available_programs() + programs diff --git a/sale_loyalty_order_suggestion_multi_gift/readme/CONTRIBUTORS.rst b/sale_loyalty_order_suggestion_multi_gift/readme/CONTRIBUTORS.rst new file mode 100644 index 00000000..44075b9f --- /dev/null +++ b/sale_loyalty_order_suggestion_multi_gift/readme/CONTRIBUTORS.rst @@ -0,0 +1,3 @@ +* `Tecnativa `_: + + * Pilar Vargas diff --git a/sale_loyalty_order_suggestion_multi_gift/readme/DESCRIPTION.rst b/sale_loyalty_order_suggestion_multi_gift/readme/DESCRIPTION.rst new file mode 100644 index 00000000..363c12fd --- /dev/null +++ b/sale_loyalty_order_suggestion_multi_gift/readme/DESCRIPTION.rst @@ -0,0 +1,2 @@ +This module extends the functionality of `sale_loyalty_order_suggestion` by giving hints +of available promotions whose reward is multi-gift and whose rules require a minimum quantity of products. diff --git a/sale_loyalty_order_suggestion_multi_gift/readme/ROADMAP.rst b/sale_loyalty_order_suggestion_multi_gift/readme/ROADMAP.rst new file mode 100644 index 00000000..3f80d60b --- /dev/null +++ b/sale_loyalty_order_suggestion_multi_gift/readme/ROADMAP.rst @@ -0,0 +1,4 @@ +For the moment only suggestions for promotions whose multi-gift rewards include products +added to the sales order and whose rules have product-based criteria will be taken into +account. This module could be extended to take into account other types of rules in the +loyalty programs to be able to apply the promotion from the wizard. diff --git a/sale_loyalty_order_suggestion_multi_gift/readme/USAGE.rst b/sale_loyalty_order_suggestion_multi_gift/readme/USAGE.rst new file mode 100644 index 00000000..1f64ad0f --- /dev/null +++ b/sale_loyalty_order_suggestion_multi_gift/readme/USAGE.rst @@ -0,0 +1,6 @@ +To use this module: + +* Configure or create a promotion and set in its rules a minimum quantity of products required. +* Create a sales order and add one of the products that were part of the rewards to the order lines. This line will be marked with an icon (🎁) that will appear at the bottom right. +* Click on the icon and the wizard will open with the available promotions. +* Select the promotion and the products needed to apply it. diff --git a/sale_loyalty_order_suggestion_multi_gift/static/description/icon.png b/sale_loyalty_order_suggestion_multi_gift/static/description/icon.png new file mode 100644 index 0000000000000000000000000000000000000000..f8d4426158c3926825016c22ad906af27ed778c7 GIT binary patch literal 6248 zcmXY02RK|$v|qhMkGfU_t45SqC5W9bJothFz2><}7H8o&{_%{AuAt%MxA3Bv4 z@C}8##&b^qfFtT(AxK&~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#-@CfC3*4m)#Y8{Rkcb&Ol-JTlDv<>X&Q$ zdL3GJI*vI=5hX;r0XR)qF?~31ukwxCYx1>@v>6xa* zKEr-Z)I^-!)Cuh<)~YLb;1dT&ns6)a=da%=1Vmfw<+P9{3b!7o83%!PtRYIkBj)-@9;~-d=-~Hzvy@V8U}*O z-C4kX9~*_=7F6TpOiYq*VbX+M3O(#YDDzfh~Qx!fl%m^cJmChU5C5L79J5Cut*`Ieh|7r(qG{CK7%a&5mNXc z%=PH5Ok#MSIZ+~=%c($EZ|^@Yfcw(Yp-K3LrE^>{G4Q%GpNP64+WfR@%_A4bO7bsl zuPGJBg6)LyODg`Yh%4f)%y=zcOo6E5)muE?18harS6-h^!)J%GLFPWN? zhYmm`2GJ-RFw(g$wMAOkg(snVq9%(t)-U;Deg59@n$YlY zik|J4q|InxiW*3*Lr+BKM`bW2sDg6x;-P7VUUR$e}NP$#FmVOEJleVnc5`GB(ovjF<)dYF zP6NHo^!}keHRe(s2VcJbxVjkH;16N%LNz?LVNesl?-CA pB(}Dh0Rx}TPSxxXY5uw;W3FcoeE#)h2LG1;psD&4_5o@W_CKN9**5?H literal 0 HcmV?d00001 diff --git a/sale_loyalty_order_suggestion_multi_gift/static/description/index.html b/sale_loyalty_order_suggestion_multi_gift/static/description/index.html new file mode 100644 index 00000000..a5e39aa3 --- /dev/null +++ b/sale_loyalty_order_suggestion_multi_gift/static/description/index.html @@ -0,0 +1,444 @@ + + + + + + +Sale Loyalty Order Suggestion Multi Gift + + + +
+

Sale Loyalty Order Suggestion Multi Gift

+ + +

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

+

This module extends the functionality of sale_loyalty_order_suggestion by giving hints +of available promotions whose reward is multi-gift and whose rules require a minimum quantity of products.

+

Table of contents

+ +
+

Usage

+

To use this module:

+
    +
  • Configure or create a promotion and set in its rules a minimum quantity of products required.
  • +
  • Create a sales order and add one of the products that were part of the rewards to the order lines. This line will be marked with an icon (🎁) that will appear at the bottom right.
  • +
  • Click on the icon and the wizard will open with the available promotions.
  • +
  • Select the promotion and the products needed to apply it.
  • +
+
+
+

Known issues / Roadmap

+

For the moment only suggestions for promotions whose multi-gift rewards include products +added to the sales order and whose rules have product-based criteria will be taken into +account. This module could be extended to take into account other types of rules in the +loyalty programs to be able to apply the promotion from the wizard.

+
+
+

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

+
    +
  • Tecnativa
  • +
+
+
+

Contributors

+ +
+
+

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_order_suggestion_multi_gift/tests/__init__.py b/sale_loyalty_order_suggestion_multi_gift/tests/__init__.py new file mode 100644 index 00000000..6e3e00e4 --- /dev/null +++ b/sale_loyalty_order_suggestion_multi_gift/tests/__init__.py @@ -0,0 +1,2 @@ +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). +from . import test_sale_loyalty_order_suggestion_multi_gift diff --git a/sale_loyalty_order_suggestion_multi_gift/tests/test_sale_loyalty_order_suggestion_multi_gift.py b/sale_loyalty_order_suggestion_multi_gift/tests/test_sale_loyalty_order_suggestion_multi_gift.py new file mode 100644 index 00000000..ef79996e --- /dev/null +++ b/sale_loyalty_order_suggestion_multi_gift/tests/test_sale_loyalty_order_suggestion_multi_gift.py @@ -0,0 +1,176 @@ +# Copyright 2024 Tecnativa - Pilar Vargas +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). +from odoo.tests.common import Form, TransactionCase + + +class TestSaleLoyaltyOrderSuggestion(TransactionCase): + @classmethod + def setUpClass(cls): + super().setUpClass() + cls.env = cls.env(context=dict(cls.env.context, tracking_disable=True)) + cls.pricelist = cls.env["product.pricelist"].create( + { + "name": "Test pricelist", + "item_ids": [ + ( + 0, + 0, + { + "applied_on": "3_global", + "compute_price": "formula", + "base": "list_price", + }, + ) + ], + } + ) + cls.partner = cls.env["res.partner"].create( + {"name": "Mr. Odoo", "property_product_pricelist": cls.pricelist.id} + ) + cls.product_1 = cls.env["product.product"].create( + {"name": "Test 1", "sale_ok": True, "list_price": 50} + ) + cls.product_2 = cls.env["product.product"].create( + {"name": "Test 2", "sale_ok": False, "list_price": 60} + ) + cls.product_3 = cls.env["product.product"].create( + {"name": "Test 3", "sale_ok": False, "list_price": 70} + ) + cls.product_4 = cls.env["product.product"].create( + {"name": "Test 4", "sale_ok": False, "list_price": 80} + ) + cls.loyalty_program_form = cls.env["loyalty.program"].create( + { + "name": "Test Multi Gift Program", + "program_type": "promotion", + "trigger": "auto", + "applies_on": "current", + "rule_ids": [ + ( + 0, + 0, + { + "reward_point_mode": "order", + "minimum_qty": 2, + "minimum_amount": 0, + }, + ), + ], + "reward_ids": [ + ( + 0, + 0, + { + "reward_type": "multi_gift", + "required_points": 1, + "loyalty_multi_gift_ids": [ + ( + 0, + 0, + { + "reward_product_ids": [(4, cls.product_2.id)], + "reward_product_quantity": 2, + }, + ), + ( + 0, + 0, + { + "reward_product_ids": [ + (4, cls.product_3.id), + (4, cls.product_4.id), + ], + "reward_product_quantity": 3, + }, + ), + ], + }, + ) + ], + } + ) + sale_form = Form(cls.env["sale.order"]) + sale_form.partner_id = cls.partner + with sale_form.order_line.new() as line_form: + line_form.product_id = cls.product_1 + line_form.product_uom_qty = 1 + with sale_form.order_line.new() as line_form: + line_form.product_id = cls.product_2 + line_form.product_uom_qty = 1 + cls.sale = sale_form.save() + + def _open_suggested_promotion_wizard(self, suggested_reward_ids): + self.sale._update_programs_and_rewards() + wizard = ( + self.env["sale.loyalty.reward.wizard"] + .with_context(active_id=self.sale) + .create({"order_id": self.sale.id}) + ) + wizard.reward_ids = suggested_reward_ids + return wizard + + def test_01_suggested_promotion_for_product_no_applicable(self): + # In this test a suggestion is made for a promotion which contains in its rewards + # multi-gift product added to the order lines but does not meet all of the + # requirements to be applied so it will be necessary to configure the products in the + # products in the wizard. + self.sale.order_line.filtered(lambda x: x.product_id == self.product_1).unlink() + line_2 = self.sale.order_line.filtered(lambda x: x.product_id == self.product_2) + wizard = self._open_suggested_promotion_wizard(line_2.suggested_reward_ids) + self.assertEqual(wizard.reward_ids, line_2.suggested_promotion_ids.reward_ids) + self.assertTrue( + self.loyalty_program_form in line_2.suggested_reward_ids.program_id + ) + # Select promotion to apply + wizard.selected_reward_id = self.loyalty_program_form.reward_ids[0].id + # The promotion is not directly applicable as it does not comply with all the rules. + self.assertFalse(wizard.applicable_program) + # The wizard contains all the products to add as no specific product has been + # set but among these products is the product added to the order lines and this + # is the one we will proceed with the test. + self.assertTrue(len(wizard.loyalty_rule_line_ids) > 0) + wiz_line_2 = wizard.loyalty_rule_line_ids.filtered( + lambda x: x.product_id == self.product_2 + ) + self.assertEqual(wiz_line_2.units_included, 1) + self.assertEqual(wiz_line_2.units_required, 2) + self.assertEqual(wiz_line_2.units_to_include, 0) + # More units are added to make the promotion compliant and applicable. + # If more quantity of the reward product is added from the wizard to apply the + # promotion, it is considered that more quantity of product is wanted in addition + # to the reward so the initial quantity added to the sales order will be respected. + wiz_line_2.units_to_include = 1 + wizard.action_apply() + self.assertEqual( + self.sale.order_line.filtered( + lambda x: x.product_id == self.product_2 and not x.is_reward_line + ).product_uom_qty, + 2, + ) + self.assertEqual( + self.sale.order_line.filtered( + lambda x: x.product_id == self.product_2 and x.is_reward_line + ).product_uom_qty, + 2, + ) + self.assertEqual( + self.sale.order_line.filtered( + lambda x: x.product_id == self.product_3 and x.is_reward_line + ).product_uom_qty, + 3, + ) + self.assertFalse( + self.sale.order_line.filtered( + lambda x: x.product_id == self.product_4 and x.is_reward_line + ) + ) + + def test_02_no_suggested_promotion_for_product_1(self): + # This test checks that the promotion containing reward products is not found + # in the suggested promotions as product_1 is not part of the rewards. + self.loyalty_program_form.rule_ids.minimum_amount = 200 + self.loyalty_program_form.rule_ids.minimum_qty = 0 + line_1 = self.sale.order_line.filtered(lambda x: x.product_id == self.product_1) + self.assertFalse( + self.loyalty_program_form in line_1.suggested_reward_ids.program_id + ) diff --git a/sale_loyalty_order_suggestion_multi_gift/wizard/__init__.py b/sale_loyalty_order_suggestion_multi_gift/wizard/__init__.py new file mode 100644 index 00000000..1ca11a9d --- /dev/null +++ b/sale_loyalty_order_suggestion_multi_gift/wizard/__init__.py @@ -0,0 +1 @@ +from . import sale_loyalty_reward_wizard diff --git a/sale_loyalty_order_suggestion_multi_gift/wizard/sale_loyalty_reward_wizard.py b/sale_loyalty_order_suggestion_multi_gift/wizard/sale_loyalty_reward_wizard.py new file mode 100644 index 00000000..e4ba14c2 --- /dev/null +++ b/sale_loyalty_order_suggestion_multi_gift/wizard/sale_loyalty_reward_wizard.py @@ -0,0 +1,47 @@ +from odoo import models + + +class SaleLoyaltyRewardWizard(models.TransientModel): + _inherit = "sale.loyalty.reward.wizard" + + def action_apply(self): + res = super().action_apply() + # It's necessary to adjust the order line when suggestions are made on order + # lines that contain products that are part of a multi-gift reward, i.e. if product A is + # added to the order and a promotion is suggested that has product A as a reward, + # that order line will become an order reward line or the quantity indicated in + # the promotion reward. + if self.multi_gift_reward: + for gift_line in self.loyalty_gift_line_ids: + selected_product = gift_line.selected_gift_id + product_qty = gift_line.line_id.reward_product_quantity + order_line = self.order_id.order_line.filtered( + lambda x: x.product_id == selected_product and not x.is_reward_line + ) + units_to_include = ( + self.loyalty_rule_line_ids.filtered( + lambda x: x.product_id == selected_product + ).units_to_include + or False + ) + if not units_to_include: + update_qty = order_line.product_uom_qty - product_qty + if update_qty < 1: + order_line.unlink() + else: + self._update_order_line_with_units(order_line, -abs(update_qty)) + return res + + +class SaleLoyaltyRewardProductLineWizard(models.TransientModel): + _inherit = "sale.loyalty.reward.product_line.wizard" + + def _compute_selected_gift_id(self): + res = super()._compute_selected_gift_id() + for wizard in self: + if ( + wizard.wizard_id.multi_gift_reward + and wizard.wizard_id.product_id in wizard.gift_ids._origin + ): + wizard.selected_gift_id = wizard.wizard_id.product_id + return res diff --git a/setup/sale_loyalty_order_suggestion_multi_gift/odoo/addons/sale_loyalty_order_suggestion_multi_gift b/setup/sale_loyalty_order_suggestion_multi_gift/odoo/addons/sale_loyalty_order_suggestion_multi_gift new file mode 120000 index 00000000..54e59c45 --- /dev/null +++ b/setup/sale_loyalty_order_suggestion_multi_gift/odoo/addons/sale_loyalty_order_suggestion_multi_gift @@ -0,0 +1 @@ +../../../../sale_loyalty_order_suggestion_multi_gift \ No newline at end of file diff --git a/setup/sale_loyalty_order_suggestion_multi_gift/setup.py b/setup/sale_loyalty_order_suggestion_multi_gift/setup.py new file mode 100644 index 00000000..28c57bb6 --- /dev/null +++ b/setup/sale_loyalty_order_suggestion_multi_gift/setup.py @@ -0,0 +1,6 @@ +import setuptools + +setuptools.setup( + setup_requires=['setuptools-odoo'], + odoo_addon=True, +)