From 3a8e400d3b96ca645b0aa63bc345a8272349676b Mon Sep 17 00:00:00 2001 From: Pierrick Brun Date: Wed, 15 Apr 2020 11:08:50 +0200 Subject: [PATCH 1/7] [MIG] 12.0 promotion_rule --- shopinvader_promotion_rule/__manifest__.py | 4 ++-- shopinvader_promotion_rule/tests/test_cart.py | 14 +++++++------- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/shopinvader_promotion_rule/__manifest__.py b/shopinvader_promotion_rule/__manifest__.py index 0c11b59b56..caed9d89e2 100644 --- a/shopinvader_promotion_rule/__manifest__.py +++ b/shopinvader_promotion_rule/__manifest__.py @@ -4,12 +4,12 @@ { "name": "Shopvinvader Promotion Rule", "summary": "Module to manage Promotion Rule with shopinvader", - "version": "10.0.1.0.0", + "version": "12.0.1.0.0", "category": "Sale", "website": "https://github.com/shopinvader/odoo-shopinvader", "author": "Akretion, " "ACSONE SA / NV", "license": "AGPL-3", "application": False, - "installable": False, + "installable": True, "depends": ["shopinvader", "component", "sale_promotion_rule"], } diff --git a/shopinvader_promotion_rule/tests/test_cart.py b/shopinvader_promotion_rule/tests/test_cart.py index 961b6419eb..b5dabdcdd0 100644 --- a/shopinvader_promotion_rule/tests/test_cart.py +++ b/shopinvader_promotion_rule/tests/test_cart.py @@ -35,13 +35,13 @@ def test_add_coupon(self): promotion_rules_auto = cart["promotion_rules_auto"] promotion_rule_coupon = cart["promotion_rule_coupon"] self.assertDictEqual({}, promotion_rule_coupon) - self.assertEquals(1, len(promotion_rules_auto)) + self.assertEqual(1, len(promotion_rules_auto)) self.assertDictEqual( { "rule_type": "auto", "discount_type": "percentage", "code": None, - "name": u"Best Promo Automatic", + "name": "Best Promo Automatic", "discount_amount": 10.0, }, promotion_rules_auto[0], @@ -56,13 +56,13 @@ def test_add_coupon(self): promotion_rule_coupon = cart["promotion_rule_coupon"] # we see that the auto rule are still applied on the SO event if it's # without effect on line since the coupon is the best promotion - self.assertEquals(1, len(promotion_rules_auto)) + self.assertEqual(1, len(promotion_rules_auto)) self.assertDictEqual( { "rule_type": "coupon", "discount_type": "percentage", "code": "ELDONGHUT", - "name": u"Best Promo", + "name": "Best Promo", "discount_amount": 20.0, }, promotion_rule_coupon, @@ -83,13 +83,13 @@ def test_add_coupon(self): promotion_rules_auto = cart["promotion_rules_auto"] promotion_rule_coupon = cart["promotion_rule_coupon"] self.assertDictEqual({}, promotion_rule_coupon) - self.assertEquals(1, len(promotion_rules_auto)) + self.assertEqual(1, len(promotion_rules_auto)) self.assertDictEqual( { "rule_type": "auto", "discount_type": "percentage", "code": None, - "name": u"Best Promo Automatic", + "name": "Best Promo Automatic", "discount_amount": 10.0, }, promotion_rules_auto[0], @@ -103,7 +103,7 @@ def test_promotion_on_item(self): self.service.dispatch( "add_item", params={"product_id": self.product_1.id, "item_qty": 2} ) - self.assertEquals(count_existing_lines + 1, len(self.cart.order_line)) + self.assertEqual(count_existing_lines + 1, len(self.cart.order_line)) # the promotion is applied on all lines for line in self.cart.order_line: self.check_discount_rule_set(line, self.promotion_rule_coupon) From bb9858dec8c831e1c8246b808b2ff49a68dee010 Mon Sep 17 00:00:00 2001 From: Pierrick Brun Date: Wed, 27 May 2020 17:11:38 +0200 Subject: [PATCH 2/7] [IMP] new stage cart_init Do not compute promotions when customer is shopping Only when the customer is reviewing the cart --- shopinvader_promotion_rule/__manifest__.py | 1 + shopinvader_promotion_rule/data/cart_step.xml | 9 +++++++++ shopinvader_promotion_rule/services/cart.py | 9 ++++++--- shopinvader_promotion_rule/tests/test_cart.py | 1 + 4 files changed, 17 insertions(+), 3 deletions(-) create mode 100644 shopinvader_promotion_rule/data/cart_step.xml diff --git a/shopinvader_promotion_rule/__manifest__.py b/shopinvader_promotion_rule/__manifest__.py index caed9d89e2..fa79553c1a 100644 --- a/shopinvader_promotion_rule/__manifest__.py +++ b/shopinvader_promotion_rule/__manifest__.py @@ -12,4 +12,5 @@ "application": False, "installable": True, "depends": ["shopinvader", "component", "sale_promotion_rule"], + "data": ["data/cart_step.xml"], } diff --git a/shopinvader_promotion_rule/data/cart_step.xml b/shopinvader_promotion_rule/data/cart_step.xml new file mode 100644 index 0000000000..f959db20b1 --- /dev/null +++ b/shopinvader_promotion_rule/data/cart_step.xml @@ -0,0 +1,9 @@ + + + + + Shopping + cart_init + + + diff --git a/shopinvader_promotion_rule/services/cart.py b/shopinvader_promotion_rule/services/cart.py index 7fe8bf4f85..75ae466075 100644 --- a/shopinvader_promotion_rule/services/cart.py +++ b/shopinvader_promotion_rule/services/cart.py @@ -50,17 +50,20 @@ def _update(self, cart, params): def _add_item(self, cart, params): res = super(CartService, self)._add_item(cart, params) - cart.apply_promotions() + if cart.current_step_id and cart.current_step_id.code != "cart_init": + cart.apply_promotions() return res def _update_item(self, cart, params, item=False): res = super(CartService, self)._update_item(cart, params, item) - cart.apply_promotions() + if cart.current_step_id and cart.current_step_id.code != "cart_init": + cart.apply_promotions() return res def _delete_item(self, cart, params): res = super(CartService, self)._delete_item(cart, params) - cart.apply_promotions() + if cart.current_step_id and cart.current_step_id.code != "cart_init": + cart.apply_promotions() return res # Validator diff --git a/shopinvader_promotion_rule/tests/test_cart.py b/shopinvader_promotion_rule/tests/test_cart.py index b5dabdcdd0..f40bbd2949 100644 --- a/shopinvader_promotion_rule/tests/test_cart.py +++ b/shopinvader_promotion_rule/tests/test_cart.py @@ -100,6 +100,7 @@ def test_promotion_on_item(self): count_existing_lines = len(self.cart.order_line) # each time we add an item the promotion is recomputed and the coupon # code is preserved + self.cart.current_step_id = self.env.ref("shopinvader.cart_index").id self.service.dispatch( "add_item", params={"product_id": self.product_1.id, "item_qty": 2} ) From a8535faf08fd9d4bb6d35f1f648c2c55951df656 Mon Sep 17 00:00:00 2001 From: Quentin Groulard Date: Wed, 24 Feb 2021 16:56:23 +0100 Subject: [PATCH 3/7] [MIG] shopinvader_promotion_rule: Migration to 13.0 --- shopinvader_promotion_rule/__manifest__.py | 2 +- shopinvader_promotion_rule/models/sale_order.py | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/shopinvader_promotion_rule/__manifest__.py b/shopinvader_promotion_rule/__manifest__.py index fa79553c1a..67589d905e 100644 --- a/shopinvader_promotion_rule/__manifest__.py +++ b/shopinvader_promotion_rule/__manifest__.py @@ -4,7 +4,7 @@ { "name": "Shopvinvader Promotion Rule", "summary": "Module to manage Promotion Rule with shopinvader", - "version": "12.0.1.0.0", + "version": "13.0.1.0.0", "category": "Sale", "website": "https://github.com/shopinvader/odoo-shopinvader", "author": "Akretion, " "ACSONE SA / NV", diff --git a/shopinvader_promotion_rule/models/sale_order.py b/shopinvader_promotion_rule/models/sale_order.py index b10341bfbc..43ad7d4b93 100644 --- a/shopinvader_promotion_rule/models/sale_order.py +++ b/shopinvader_promotion_rule/models/sale_order.py @@ -1,13 +1,12 @@ # -*- coding: utf-8 -*- # Copyright 2020 ACSONE SA/NV () # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). -from odoo import api, models +from odoo import models class SaleOrder(models.Model): _inherit = "sale.order" - @api.multi def reset_price_tax(self): """ Inherit to apply the promotion rules when prices are updated From 03f89573b8e30fc4bafda4b4ee030fea78ed9c9d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Honor=C3=A9?= Date: Tue, 10 Aug 2021 15:02:41 +0200 Subject: [PATCH 4/7] [IMP] shopinvader_promotion_rule: black, isort, prettier --- .../odoo/addons/shopinvader_promotion_rule | 1 + setup/shopinvader_promotion_rule/setup.py | 6 ++++++ shopinvader_promotion_rule/__manifest__.py | 2 +- shopinvader_promotion_rule/data/cart_step.xml | 2 +- shopinvader_promotion_rule/models/__init__.py | 1 - shopinvader_promotion_rule/models/sale_order.py | 1 - shopinvader_promotion_rule/services/cart.py | 3 ++- shopinvader_promotion_rule/tests/test_cart.py | 11 ++++------- 8 files changed, 15 insertions(+), 12 deletions(-) create mode 120000 setup/shopinvader_promotion_rule/odoo/addons/shopinvader_promotion_rule create mode 100644 setup/shopinvader_promotion_rule/setup.py diff --git a/setup/shopinvader_promotion_rule/odoo/addons/shopinvader_promotion_rule b/setup/shopinvader_promotion_rule/odoo/addons/shopinvader_promotion_rule new file mode 120000 index 0000000000..36a713bad0 --- /dev/null +++ b/setup/shopinvader_promotion_rule/odoo/addons/shopinvader_promotion_rule @@ -0,0 +1 @@ +../../../../shopinvader_promotion_rule \ No newline at end of file diff --git a/setup/shopinvader_promotion_rule/setup.py b/setup/shopinvader_promotion_rule/setup.py new file mode 100644 index 0000000000..28c57bb640 --- /dev/null +++ b/setup/shopinvader_promotion_rule/setup.py @@ -0,0 +1,6 @@ +import setuptools + +setuptools.setup( + setup_requires=['setuptools-odoo'], + odoo_addon=True, +) diff --git a/shopinvader_promotion_rule/__manifest__.py b/shopinvader_promotion_rule/__manifest__.py index 67589d905e..be38a7238b 100644 --- a/shopinvader_promotion_rule/__manifest__.py +++ b/shopinvader_promotion_rule/__manifest__.py @@ -4,7 +4,7 @@ { "name": "Shopvinvader Promotion Rule", "summary": "Module to manage Promotion Rule with shopinvader", - "version": "13.0.1.0.0", + "version": "14.0.1.0.0", "category": "Sale", "website": "https://github.com/shopinvader/odoo-shopinvader", "author": "Akretion, " "ACSONE SA / NV", diff --git a/shopinvader_promotion_rule/data/cart_step.xml b/shopinvader_promotion_rule/data/cart_step.xml index f959db20b1..c779b5f0b4 100644 --- a/shopinvader_promotion_rule/data/cart_step.xml +++ b/shopinvader_promotion_rule/data/cart_step.xml @@ -1,4 +1,4 @@ - + diff --git a/shopinvader_promotion_rule/models/__init__.py b/shopinvader_promotion_rule/models/__init__.py index c97a6637a8..082aba7710 100644 --- a/shopinvader_promotion_rule/models/__init__.py +++ b/shopinvader_promotion_rule/models/__init__.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- # Copyright 2020 ACSONE SA/NV () # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). from . import sale_order diff --git a/shopinvader_promotion_rule/models/sale_order.py b/shopinvader_promotion_rule/models/sale_order.py index 43ad7d4b93..bec8d249bd 100644 --- a/shopinvader_promotion_rule/models/sale_order.py +++ b/shopinvader_promotion_rule/models/sale_order.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- # Copyright 2020 ACSONE SA/NV () # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). from odoo import models diff --git a/shopinvader_promotion_rule/services/cart.py b/shopinvader_promotion_rule/services/cart.py index 75ae466075..4c2c6c9e54 100644 --- a/shopinvader_promotion_rule/services/cart.py +++ b/shopinvader_promotion_rule/services/cart.py @@ -4,10 +4,11 @@ import logging -from odoo.addons.component.core import AbstractComponent, Component from odoo.exceptions import UserError from odoo.tools.translate import _ +from odoo.addons.component.core import AbstractComponent, Component + _logger = logging.getLogger(__name__) diff --git a/shopinvader_promotion_rule/tests/test_cart.py b/shopinvader_promotion_rule/tests/test_cart.py index f40bbd2949..d8c12d44cf 100644 --- a/shopinvader_promotion_rule/tests/test_cart.py +++ b/shopinvader_promotion_rule/tests/test_cart.py @@ -2,18 +2,17 @@ # Benoît GUILLOT # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). +from odoo.exceptions import UserError + from odoo.addons.sale_promotion_rule.tests.test_promotion import ( AbstractCommonPromotionCase, ) from odoo.addons.shopinvader.tests.test_cart import CommonConnectedCartCase -from odoo.exceptions import UserError class TestCart(CommonConnectedCartCase, AbstractCommonPromotionCase): def add_coupon_code(self, coupon_code): - return self.service.dispatch( - "update", params={"coupon_code": coupon_code} - ) + return self.service.dispatch("update", params={"coupon_code": coupon_code}) def setUp(self, *args, **kwargs): super(TestCart, self).setUp(*args, **kwargs) @@ -141,9 +140,7 @@ def test_promotion_rule_applied_after_fiscal_pos_update(self): ) # Update the fiscal position to have reset_price # set to True (cfr shopinvader module) - self.cart.write_with_onchange( - {"fiscal_position_id": fiscal_position.id} - ) + self.cart.write_with_onchange({"fiscal_position_id": fiscal_position.id}) self.assertAlmostEquals( self.cart.amount_total, save_price_with_promo, From 9bb47c78c8c2b8e8a13230f2d3652527fb941b52 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Honor=C3=A9?= Date: Tue, 10 Aug 2021 15:31:34 +0200 Subject: [PATCH 5/7] [14.0][MIG] shopinvader_promotion_rule from 13.0 --- .../models/sale_order.py | 2 +- .../services/__init__.py | 1 + .../services/abstract_sale_service.py | 12 ++++++++++ shopinvader_promotion_rule/services/cart.py | 24 +++++++------------ shopinvader_promotion_rule/tests/test_cart.py | 4 ++-- 5 files changed, 24 insertions(+), 19 deletions(-) create mode 100644 shopinvader_promotion_rule/services/abstract_sale_service.py diff --git a/shopinvader_promotion_rule/models/sale_order.py b/shopinvader_promotion_rule/models/sale_order.py index bec8d249bd..47d0302981 100644 --- a/shopinvader_promotion_rule/models/sale_order.py +++ b/shopinvader_promotion_rule/models/sale_order.py @@ -11,7 +11,7 @@ def reset_price_tax(self): Inherit to apply the promotion rules when prices are updated :return: """ - result = super(SaleOrder, self).reset_price_tax() + result = super().reset_price_tax() if self.has_promotion_rules: self.apply_promotions() return result diff --git a/shopinvader_promotion_rule/services/__init__.py b/shopinvader_promotion_rule/services/__init__.py index d98a08bc7f..2c9209656f 100644 --- a/shopinvader_promotion_rule/services/__init__.py +++ b/shopinvader_promotion_rule/services/__init__.py @@ -1 +1,2 @@ +from . import abstract_sale_service from . import cart diff --git a/shopinvader_promotion_rule/services/abstract_sale_service.py b/shopinvader_promotion_rule/services/abstract_sale_service.py new file mode 100644 index 0000000000..870aeec2f3 --- /dev/null +++ b/shopinvader_promotion_rule/services/abstract_sale_service.py @@ -0,0 +1,12 @@ +# Copyright 2017 Akretion (http://www.akretion.com) +# @author Benoît GUILLOT +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). +from odoo.addons.component.core import AbstractComponent + + +class AbstractSaleService(AbstractComponent): + _inherit = "shopinvader.abstract.sale.service" + + def _is_item(self, line): + res = super()._is_item(line) + return res and not line.is_promotion_line diff --git a/shopinvader_promotion_rule/services/cart.py b/shopinvader_promotion_rule/services/cart.py index 4c2c6c9e54..040c29ed23 100644 --- a/shopinvader_promotion_rule/services/cart.py +++ b/shopinvader_promotion_rule/services/cart.py @@ -7,19 +7,11 @@ from odoo.exceptions import UserError from odoo.tools.translate import _ -from odoo.addons.component.core import AbstractComponent, Component +from odoo.addons.component.core import Component _logger = logging.getLogger(__name__) -class AbstractSaleService(AbstractComponent): - _inherit = "shopinvader.abstract.sale.service" - - def _is_item(self, line): - res = super(AbstractSaleService, self)._is_item(line) - return res and not line.is_promotion_line - - class CartService(Component): _inherit = "shopinvader.cart.service" @@ -35,7 +27,7 @@ def _update(self, cart, params): "not be done in the same call" ) ) - res = super(CartService, self)._update(cart, params) + res = super()._update(cart, params) if is_coupon_code_specified: if coupon_code: cart.add_coupon(coupon_code) @@ -50,37 +42,37 @@ def _update(self, cart, params): return res def _add_item(self, cart, params): - res = super(CartService, self)._add_item(cart, params) + res = super()._add_item(cart, params) if cart.current_step_id and cart.current_step_id.code != "cart_init": cart.apply_promotions() return res def _update_item(self, cart, params, item=False): - res = super(CartService, self)._update_item(cart, params, item) + res = super()._update_item(cart, params, item) if cart.current_step_id and cart.current_step_id.code != "cart_init": cart.apply_promotions() return res def _delete_item(self, cart, params): - res = super(CartService, self)._delete_item(cart, params) + res = super()._delete_item(cart, params) if cart.current_step_id and cart.current_step_id.code != "cart_init": cart.apply_promotions() return res # Validator def _validator_update(self): - res = super(CartService, self)._validator_update() + res = super()._validator_update() res["coupon_code"] = {"type": "string", "nullable": True} return res # converter def _convert_one_sale(self, sale): - res = super(CartService, self)._convert_one_sale(sale) + res = super()._convert_one_sale(sale) res.update(self._get_promotions_info(sale)) return res def _convert_one_line(self, line): - res = super(CartService, self)._convert_one_line(line) + res = super()._convert_one_line(line) res.update(self._get_promotions_info(line)) return res diff --git a/shopinvader_promotion_rule/tests/test_cart.py b/shopinvader_promotion_rule/tests/test_cart.py index d8c12d44cf..90521e2779 100644 --- a/shopinvader_promotion_rule/tests/test_cart.py +++ b/shopinvader_promotion_rule/tests/test_cart.py @@ -15,7 +15,7 @@ def add_coupon_code(self, coupon_code): return self.service.dispatch("update", params={"coupon_code": coupon_code}) def setUp(self, *args, **kwargs): - super(TestCart, self).setUp(*args, **kwargs) + super().setUp(*args, **kwargs) self.set_up("shopinvader.sale_order_2") self.product_1 = self.env.ref("product.product_product_4b") @@ -141,7 +141,7 @@ def test_promotion_rule_applied_after_fiscal_pos_update(self): # Update the fiscal position to have reset_price # set to True (cfr shopinvader module) self.cart.write_with_onchange({"fiscal_position_id": fiscal_position.id}) - self.assertAlmostEquals( + self.assertAlmostEqual( self.cart.amount_total, save_price_with_promo, places=self.price_precision_digits, From e0a8341eae09dce78b0c05fee37976011aa18fd5 Mon Sep 17 00:00:00 2001 From: Denis Roussel Date: Wed, 17 Nov 2021 10:33:28 +0100 Subject: [PATCH 6/7] [14.0][IMP] shopinvader_promotion_rule: Add option to always apply promotions --- shopinvader_promotion_rule/__manifest__.py | 2 +- shopinvader_promotion_rule/models/__init__.py | 3 +-- .../models/shopinvader_backend.py | 12 ++++++++++++ shopinvader_promotion_rule/services/cart.py | 16 +++++++++++++--- .../views/shopinvader_backend.xml | 17 +++++++++++++++++ 5 files changed, 44 insertions(+), 6 deletions(-) create mode 100644 shopinvader_promotion_rule/models/shopinvader_backend.py create mode 100644 shopinvader_promotion_rule/views/shopinvader_backend.xml diff --git a/shopinvader_promotion_rule/__manifest__.py b/shopinvader_promotion_rule/__manifest__.py index be38a7238b..9d33c0c4d6 100644 --- a/shopinvader_promotion_rule/__manifest__.py +++ b/shopinvader_promotion_rule/__manifest__.py @@ -12,5 +12,5 @@ "application": False, "installable": True, "depends": ["shopinvader", "component", "sale_promotion_rule"], - "data": ["data/cart_step.xml"], + "data": ["data/cart_step.xml", "views/shopinvader_backend.xml"], } diff --git a/shopinvader_promotion_rule/models/__init__.py b/shopinvader_promotion_rule/models/__init__.py index 082aba7710..e9bf355be5 100644 --- a/shopinvader_promotion_rule/models/__init__.py +++ b/shopinvader_promotion_rule/models/__init__.py @@ -1,3 +1,2 @@ -# Copyright 2020 ACSONE SA/NV () -# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). from . import sale_order +from . import shopinvader_backend diff --git a/shopinvader_promotion_rule/models/shopinvader_backend.py b/shopinvader_promotion_rule/models/shopinvader_backend.py new file mode 100644 index 0000000000..5fed814f53 --- /dev/null +++ b/shopinvader_promotion_rule/models/shopinvader_backend.py @@ -0,0 +1,12 @@ +# Copyright 2021 ACSONE SA/NV () +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). +from odoo import fields, models + + +class ShopinvaderBackend(models.Model): + _inherit = "shopinvader.backend" + + always_apply_promotion = fields.Boolean( + default=True, + help="Uncheck this if you want to not apply promotion on init cart step", + ) diff --git a/shopinvader_promotion_rule/services/cart.py b/shopinvader_promotion_rule/services/cart.py index 040c29ed23..e15869fb27 100644 --- a/shopinvader_promotion_rule/services/cart.py +++ b/shopinvader_promotion_rule/services/cart.py @@ -15,6 +15,16 @@ class CartService(Component): _inherit = "shopinvader.cart.service" + def _can_apply_promotions(self, cart): + """ + Allow to determine if we can apply promotions + """ + if self.shopinvader_backend.always_apply_promotion or ( + cart.current_step_id and cart.current_step_id.code != "cart_init" + ): + return True + return False + def _update(self, cart, params): is_coupon_code_specified = "coupon_code" in params coupon_code = params.pop("coupon_code", None) @@ -43,19 +53,19 @@ def _update(self, cart, params): def _add_item(self, cart, params): res = super()._add_item(cart, params) - if cart.current_step_id and cart.current_step_id.code != "cart_init": + if self._can_apply_promotions(cart): cart.apply_promotions() return res def _update_item(self, cart, params, item=False): res = super()._update_item(cart, params, item) - if cart.current_step_id and cart.current_step_id.code != "cart_init": + if self._can_apply_promotions(cart): cart.apply_promotions() return res def _delete_item(self, cart, params): res = super()._delete_item(cart, params) - if cart.current_step_id and cart.current_step_id.code != "cart_init": + if self._can_apply_promotions(cart): cart.apply_promotions() return res diff --git a/shopinvader_promotion_rule/views/shopinvader_backend.xml b/shopinvader_promotion_rule/views/shopinvader_backend.xml new file mode 100644 index 0000000000..981478db47 --- /dev/null +++ b/shopinvader_promotion_rule/views/shopinvader_backend.xml @@ -0,0 +1,17 @@ + + + + + shopinvader.backend + shopinvader.backend.form (in shopinvader_promotion_rule) + + + + + + + + From ac7c55a986789a465c06abe40af20244f3bcc272 Mon Sep 17 00:00:00 2001 From: Denis Roussel Date: Wed, 17 Nov 2021 10:55:09 +0100 Subject: [PATCH 7/7] [14.0][IMP] shopinvader_promotion_rule: Remove conditional promotion apply As it was done on previous versions for performance problems, remove it as we don't have them anymore --- .pre-commit-config.yaml | 1 - shopinvader_promotion_rule/__manifest__.py | 2 +- shopinvader_promotion_rule/models/__init__.py | 1 - .../models/shopinvader_backend.py | 12 ------------ shopinvader_promotion_rule/services/cart.py | 19 +++---------------- .../views/shopinvader_backend.xml | 17 ----------------- 6 files changed, 4 insertions(+), 48 deletions(-) delete mode 100644 shopinvader_promotion_rule/models/shopinvader_backend.py delete mode 100644 shopinvader_promotion_rule/views/shopinvader_backend.xml diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 1cf3f95fa0..4d22dd31fb 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -8,7 +8,6 @@ exclude: | ^shopinvader_demo_app/| ^shopinvader_locomotive_contact_company/| ^shopinvader_locomotive_elasticsearch/| - ^shopinvader_promotion_rule/| ^shopinvader_sale_communication/| ^shopinvader_sale_report/| # END NOT INSTALLABLE ADDONS diff --git a/shopinvader_promotion_rule/__manifest__.py b/shopinvader_promotion_rule/__manifest__.py index 9d33c0c4d6..be38a7238b 100644 --- a/shopinvader_promotion_rule/__manifest__.py +++ b/shopinvader_promotion_rule/__manifest__.py @@ -12,5 +12,5 @@ "application": False, "installable": True, "depends": ["shopinvader", "component", "sale_promotion_rule"], - "data": ["data/cart_step.xml", "views/shopinvader_backend.xml"], + "data": ["data/cart_step.xml"], } diff --git a/shopinvader_promotion_rule/models/__init__.py b/shopinvader_promotion_rule/models/__init__.py index e9bf355be5..6aacb75313 100644 --- a/shopinvader_promotion_rule/models/__init__.py +++ b/shopinvader_promotion_rule/models/__init__.py @@ -1,2 +1 @@ from . import sale_order -from . import shopinvader_backend diff --git a/shopinvader_promotion_rule/models/shopinvader_backend.py b/shopinvader_promotion_rule/models/shopinvader_backend.py deleted file mode 100644 index 5fed814f53..0000000000 --- a/shopinvader_promotion_rule/models/shopinvader_backend.py +++ /dev/null @@ -1,12 +0,0 @@ -# Copyright 2021 ACSONE SA/NV () -# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). -from odoo import fields, models - - -class ShopinvaderBackend(models.Model): - _inherit = "shopinvader.backend" - - always_apply_promotion = fields.Boolean( - default=True, - help="Uncheck this if you want to not apply promotion on init cart step", - ) diff --git a/shopinvader_promotion_rule/services/cart.py b/shopinvader_promotion_rule/services/cart.py index e15869fb27..18cf59a37d 100644 --- a/shopinvader_promotion_rule/services/cart.py +++ b/shopinvader_promotion_rule/services/cart.py @@ -15,16 +15,6 @@ class CartService(Component): _inherit = "shopinvader.cart.service" - def _can_apply_promotions(self, cart): - """ - Allow to determine if we can apply promotions - """ - if self.shopinvader_backend.always_apply_promotion or ( - cart.current_step_id and cart.current_step_id.code != "cart_init" - ): - return True - return False - def _update(self, cart, params): is_coupon_code_specified = "coupon_code" in params coupon_code = params.pop("coupon_code", None) @@ -53,20 +43,17 @@ def _update(self, cart, params): def _add_item(self, cart, params): res = super()._add_item(cart, params) - if self._can_apply_promotions(cart): - cart.apply_promotions() + cart.apply_promotions() return res def _update_item(self, cart, params, item=False): res = super()._update_item(cart, params, item) - if self._can_apply_promotions(cart): - cart.apply_promotions() + cart.apply_promotions() return res def _delete_item(self, cart, params): res = super()._delete_item(cart, params) - if self._can_apply_promotions(cart): - cart.apply_promotions() + cart.apply_promotions() return res # Validator diff --git a/shopinvader_promotion_rule/views/shopinvader_backend.xml b/shopinvader_promotion_rule/views/shopinvader_backend.xml deleted file mode 100644 index 981478db47..0000000000 --- a/shopinvader_promotion_rule/views/shopinvader_backend.xml +++ /dev/null @@ -1,17 +0,0 @@ - - - - - shopinvader.backend - shopinvader.backend.form (in shopinvader_promotion_rule) - - - - - - - -