-
Notifications
You must be signed in to change notification settings - Fork 103
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by sebastienbeau
- Loading branch information
Showing
11 changed files
with
53 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 1 addition & 0 deletions
1
setup/shopinvader_promotion_rule/odoo/addons/shopinvader_promotion_rule
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
../../../../shopinvader_promotion_rule |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import setuptools | ||
|
||
setuptools.setup( | ||
setup_requires=['setuptools-odoo'], | ||
odoo_addon=True, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<?xml version="1.0" encoding="UTF-8" ?> | ||
<odoo> | ||
|
||
<record id="cart_init" model="shopinvader.cart.step"> | ||
<field name="name">Shopping</field> | ||
<field name="code">cart_init</field> | ||
</record> | ||
|
||
</odoo> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1 @@ | ||
# -*- coding: utf-8 -*- | ||
# Copyright 2020 ACSONE SA/NV (<http://acsone.eu>) | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). | ||
from . import sale_order |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,17 @@ | ||
# -*- coding: utf-8 -*- | ||
# Copyright 2020 ACSONE SA/NV (<http://acsone.eu>) | ||
# 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 | ||
:return: | ||
""" | ||
result = super(SaleOrder, self).reset_price_tax() | ||
result = super().reset_price_tax() | ||
if self.has_promotion_rules: | ||
self.apply_promotions() | ||
return result |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
from . import abstract_sale_service | ||
from . import cart |
12 changes: 12 additions & 0 deletions
12
shopinvader_promotion_rule/services/abstract_sale_service.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
# Copyright 2017 Akretion (http://www.akretion.com) | ||
# @author Benoît GUILLOT <[email protected]> | ||
# 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,21 +2,20 @@ | |
# Benoît GUILLOT <[email protected]> | ||
# 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) | ||
super().setUp(*args, **kwargs) | ||
self.set_up("shopinvader.sale_order_2") | ||
self.product_1 = self.env.ref("product.product_product_4b") | ||
|
||
|
@@ -41,7 +40,7 @@ def test_add_coupon(self): | |
"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], | ||
|
@@ -62,7 +61,7 @@ def test_add_coupon(self): | |
"rule_type": "coupon", | ||
"discount_type": "percentage", | ||
"code": "ELDONGHUT", | ||
"name": u"Best Promo", | ||
"name": "Best Promo", | ||
"discount_amount": 20.0, | ||
}, | ||
promotion_rule_coupon, | ||
|
@@ -89,7 +88,7 @@ def test_add_coupon(self): | |
"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], | ||
|
@@ -100,6 +99,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} | ||
) | ||
|
@@ -140,10 +140,8 @@ 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.cart.write_with_onchange({"fiscal_position_id": fiscal_position.id}) | ||
self.assertAlmostEqual( | ||
self.cart.amount_total, | ||
save_price_with_promo, | ||
places=self.price_precision_digits, | ||
|