Skip to content

Commit c94c2f0

Browse files
committed
saved
1 parent ce008c5 commit c94c2f0

File tree

1 file changed

+121
-7
lines changed

1 file changed

+121
-7
lines changed

tg_sale_loyalty/tests/test_accumulative.py

Lines changed: 121 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,17 +19,35 @@ def setUpClass(cls):
1919
}
2020
)
2121

22+
cls.product_B = cls.env["product.product"].create(
23+
{
24+
"name": "Product B",
25+
"list_price": 100,
26+
"sale_ok": True,
27+
"taxes_id": [(5,)],
28+
}
29+
)
30+
31+
cls.product_C = cls.env["product.product"].create(
32+
{
33+
"name": "Product C",
34+
"list_price": 100,
35+
"sale_ok": True,
36+
"taxes_id": [(5,)],
37+
}
38+
)
39+
40+
cls.user_salemanager = new_test_user(
41+
cls.env, login="user_salemanager", groups="sales_team.group_sale_manager"
42+
)
43+
2244
def _make_programs_and_order(
2345
self, is_program1_accumulative, is_program2_accumulative
2446
):
25-
user_salemanager = new_test_user(
26-
self.env, login="user_salemanager", groups="sales_team.group_sale_manager"
27-
)
28-
2947
LoyaltyProgram = self.env["loyalty.program"]
3048
LoyaltyProgram.create(
3149
{
32-
"name": "Promo 1 (accumulative)",
50+
"name": "Discount code 1 (accumulative)",
3351
"trigger": "with_code",
3452
"program_type": "promo_code",
3553
"applies_on": "current",
@@ -55,9 +73,10 @@ def _make_programs_and_order(
5573
],
5674
}
5775
)
76+
5877
LoyaltyProgram.create(
5978
{
60-
"name": "Promo 2 (non-accumulative)",
79+
"name": "Discount code 2 (non-accumulative)",
6180
"trigger": "with_code",
6281
"program_type": "promo_code",
6382
"applies_on": "current",
@@ -86,7 +105,7 @@ def _make_programs_and_order(
86105

87106
order = (
88107
self.env["sale.order"]
89-
.with_user(user_salemanager)
108+
.with_user(self.user_salemanager)
90109
.create(
91110
{
92111
"partner_id": self.partner_a.id,
@@ -123,3 +142,98 @@ def test_accumulative_04(self):
123142
order = self._make_programs_and_order(False, True)
124143
self.assertNotIn("error", order._try_apply_code("test_10pc1"))
125144
self.assertIn("error", order._try_apply_code("test_10pc2"))
145+
146+
def test_promotion_accumulative(self):
147+
LoyaltyProgram = self.env["loyalty.program"]
148+
LoyaltyProgram.create(
149+
{
150+
"name": "Promotion 1 (accumulative)",
151+
"trigger": "auto",
152+
"program_type": "promotion",
153+
"applies_on": "current",
154+
"is_accumulative": True,
155+
"rule_ids": [
156+
(
157+
0,
158+
0,
159+
{
160+
"reward_point_mode": "unit",
161+
"reward_point_amount": 1,
162+
"product_ids": [self.product_A.id],
163+
},
164+
)
165+
],
166+
"reward_ids": [
167+
Command.create(
168+
{
169+
"reward_type": "discount",
170+
"discount_mode": "percent",
171+
"discount": 10,
172+
"discount_applicability": "order",
173+
"required_points": 1,
174+
}
175+
)
176+
],
177+
}
178+
)
179+
LoyaltyProgram.create(
180+
{
181+
"name": "Promotion 2 (non-accumulative)",
182+
"trigger": "auto",
183+
"program_type": "promotion",
184+
"applies_on": "current",
185+
"is_accumulative": True,
186+
"rule_ids": [
187+
(
188+
0,
189+
0,
190+
{
191+
"reward_point_mode": "unit",
192+
"reward_point_amount": 1,
193+
"product_ids": [self.product_B.id],
194+
},
195+
)
196+
],
197+
"reward_ids": [
198+
Command.create(
199+
{
200+
"reward_type": "discount",
201+
"discount_mode": "percent",
202+
"discount": 10,
203+
"discount_applicability": "order",
204+
"required_points": 1,
205+
}
206+
)
207+
],
208+
}
209+
)
210+
211+
order = (
212+
self.env["sale.order"]
213+
.with_user(self.user_salemanager)
214+
.create(
215+
{
216+
"partner_id": self.partner_a.id,
217+
"order_line": [
218+
Command.create(
219+
{
220+
"product_id": self.product_A.id,
221+
"tax_id": False,
222+
}
223+
),
224+
Command.create(
225+
{
226+
"product_id": self.product_B.id,
227+
"tax_id": False,
228+
}
229+
),
230+
],
231+
}
232+
)
233+
)
234+
235+
order._update_programs_and_rewards()
236+
claimable_rewards = order._get_claimable_rewards()
237+
for coupon, rewards in claimable_rewards.items():
238+
res = order._apply_program_reward(rewards, coupon)
239+
self.assertFalse(bool(res))

0 commit comments

Comments
 (0)