Skip to content

Commit

Permalink
Merge PR #1064 into 14.0
Browse files Browse the repository at this point in the history
Signed-off-by sebastienbeau
  • Loading branch information
shopinvader-git-bot committed Jun 14, 2023
2 parents c1d6acb + ac7c55a commit 5c02053
Show file tree
Hide file tree
Showing 11 changed files with 53 additions and 38 deletions.
1 change: 0 additions & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,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
Expand Down
6 changes: 6 additions & 0 deletions setup/shopinvader_promotion_rule/setup.py
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,
)
5 changes: 3 additions & 2 deletions shopinvader_promotion_rule/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@
{
"name": "Shopvinvader Promotion Rule",
"summary": "Module to manage Promotion Rule with shopinvader",
"version": "10.0.1.0.0",
"version": "14.0.1.0.0",
"category": "Sale",
"website": "https:/shopinvader/odoo-shopinvader",
"author": "Akretion, " "ACSONE SA / NV",
"license": "AGPL-3",
"application": False,
"installable": False,
"installable": True,
"depends": ["shopinvader", "component", "sale_promotion_rule"],
"data": ["data/cart_step.xml"],
}
9 changes: 9 additions & 0 deletions shopinvader_promotion_rule/data/cart_step.xml
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>
3 changes: 0 additions & 3 deletions shopinvader_promotion_rule/models/__init__.py
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
6 changes: 2 additions & 4 deletions shopinvader_promotion_rule/models/sale_order.py
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
1 change: 1 addition & 0 deletions shopinvader_promotion_rule/services/__init__.py
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 shopinvader_promotion_rule/services/abstract_sale_service.py
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
25 changes: 9 additions & 16 deletions shopinvader_promotion_rule/services/cart.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,12 @@

import logging

from odoo.addons.component.core import AbstractComponent, Component
from odoo.exceptions import UserError
from odoo.tools.translate import _

_logger = logging.getLogger(__name__)

from odoo.addons.component.core import Component

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
_logger = logging.getLogger(__name__)


class CartService(Component):
Expand All @@ -34,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)
Expand All @@ -49,34 +42,34 @@ 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)
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)
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)
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

Expand Down
22 changes: 10 additions & 12 deletions shopinvader_promotion_rule/tests/test_cart.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")

Expand All @@ -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],
Expand All @@ -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,
Expand All @@ -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],
Expand All @@ -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}
)
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit 5c02053

Please sign in to comment.