Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[14.0][FIX] sale_coupon_reward_fixed_price #147

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions sale_coupon_reward_fixed_price/views/coupon_program_view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,12 @@
<xpath expr="//label[@for='discount_type']" position="attributes">
<attribute
name="attrs"
>{"invisible": [("reward_type", "in", ("product", "free_shipping", "fixed_price"))]}</attribute>
>{"invisible": [("reward_type", "in", ("product", "free_shipping", "fixed_price", "discount_line"))]}</attribute>
</xpath>
<xpath expr="//field[@name='discount_type']/.." position="attributes">
<attribute
name="attrs"
>{"invisible": [("reward_type", "in", ("product", "free_shipping", "fixed_price"))]}</attribute>
>{"invisible": [("reward_type", "in", ("product", "free_shipping", "fixed_price", "discount_line"))]}</attribute>
</xpath>
<xpath expr="//label[@for='discount_max_amount']" position="attributes">
<attribute
Expand Down
1 change: 1 addition & 0 deletions sale_promotion_discount_in_field/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
from . import models
from . import wizard
Original file line number Diff line number Diff line change
Expand Up @@ -264,3 +264,48 @@ def test_program_reward_discount_line_on_next_order_no_code_needed(self):
1,
"You should get a coupon for you next order that will offer 10% discount",
)

def _apply_coupon(self, order, coupon_code):
return self.env["sale.coupon.apply.code"].apply_coupon(order, coupon_code)

def test_program_reward_discount_line_with_applicability(self):
coupon_code = "test_coupon"

# Create a program with specific conditions
program = self.env["coupon.program"].create(
{
"name": "10% reduction program",
"promo_code_usage": "no_code_needed",
"reward_type": "discount_line",
"program_type": "promotion_program",
"discount_type": "percentage",
"discount_percentage": 10.0,
"active": True,
"discount_apply_on": "on_order",
"promo_code": coupon_code,
"promo_applicability": "on_current_order",
}
)

error_status = program._check_promo_code(self.order, coupon_code)
self.assertFalse(error_status)

self.assertEqual(
self._apply_coupon(self.order, "wrong_coupon"),
{"not_found": "This coupon is invalid (wrong_coupon)."},
msg="coupon must not be found",
)

# Apply the program
self._apply_coupon(self.order, coupon_code)
self.assertEqual(
self.order.code_promo_program_id,
program,
msg="program must be added to order",
)

self.assertEqual(
self.order.amount_total,
2475.0,
"The order total with programs should be 2475.00",
)
1 change: 1 addition & 0 deletions sale_promotion_discount_in_field/wizard/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import sale_coupon_apply_code
27 changes: 27 additions & 0 deletions sale_promotion_discount_in_field/wizard/sale_coupon_apply_code.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
from odoo import models
from odoo.osv import expression


class SaleCouponApplyCode(models.TransientModel):
_inherit = "sale.coupon.apply.code"

def apply_coupon(self, order, coupon_code):
# OVERRIDE to apply the program to the order without reward lines
error_status = {}
program_domain = order._get_coupon_program_domain()
program_domain = expression.AND(
[program_domain, [("promo_code", "=", coupon_code)]]
)
program = self.env["coupon.program"].search(program_domain)
if (
program
and program.reward_type == "discount_line"
and program.promo_applicability != "on_next_order"
):
error_status = program._check_promo_code(order, coupon_code)
if not error_status:
order._create_reward_line(program)
order.code_promo_program_id = program
else:
return super().apply_coupon(order, coupon_code)
return error_status
Loading