Debian Codegraph @

addons/sale_loyalty/tests/test_program_without_code_operations.py

raw symbols SCIP
1 # Part of Odoo. See LICENSE file for full copyright and licensing details.
2
3 from odoo.addons.sale_loyalty.tests.common import TestSaleCouponCommon
4
5
6 class TestProgramWithoutCodeOperations(TestSaleCouponCommon):
7 # Test some basic operation (create, write, unlink) on an immediate coupon program on which we should
8 # apply or remove the reward automatically, as there's no program code.
9
10 def test_immediate_program_basic_operation(self):
11
12 # 2 products A are needed
13 self.immediate_promotion_program.rule_ids.write({'minimum_qty': 2.0})
14 order = self.empty_order
15 # Test case 1 (1 A): Assert that no reward is given, as the product B is missing
16 order.write({'order_line': [
17 (0, False, {
18 'product_id': self.product_A.id,
19 'name': '1 Product A',
20 'product_uom_qty': 1.0,
21 })
22 ]})
23 order._update_programs_and_rewards()
24 self._claim_reward(order, self.immediate_promotion_program)
25 self.assertEqual(len(order.order_line.ids), 1, "The promo offer shouldn't have been applied as the product B isn't in the order")
26
27 # Test case 2 (1 A 1 B): Assert that no reward is given, as the product A is not present in the correct quantity
28 order.write({'order_line': [
29 (0, False, {
30 'product_id': self.product_B.id,
31 'name': '2 Product B',
32 'product_uom_qty': 1.0,
33 })
34 ]})
35 order._update_programs_and_rewards()
36 self._claim_reward(order, self.immediate_promotion_program)
37 self.assertEqual(len(order.order_line.ids), 2, "The promo offer shouldn't have been applied as 2 product A aren't in the order")
38
39 # Test case 3 (2 A 1 B): Assert that the reward is given as the product B is now in the order
40 order.write({'order_line': [(1, order.order_line[0].id, {'product_uom_qty': 2.0})]})
41 order._update_programs_and_rewards()
42 self._claim_reward(order, self.immediate_promotion_program)
43 self.assertEqual(len(order.order_line.ids), 3, "The promo offer should have been applied, the discount is not created")
44
45 # Test case 4 (1 A 1 B): Assert that the reward is removed as we don't buy 2 products B anymore
46 order.write({'order_line': [(1, order.order_line[0].id, {'product_uom_qty': 1.0})]})
47 order._update_programs_and_rewards()
48 self._claim_reward(order, self.immediate_promotion_program)
49 self.assertEqual(len(order.order_line.ids), 2, "The promo reward should have been removed as the rules are not matched anymore")
50 self.assertEqual(order.order_line[0].product_id.id, self.product_A.id, "The wrong line has been removed")
51 self.assertEqual(order.order_line[1].product_id.id, self.product_B.id, "The wrong line has been removed")
52
53 # Test case 5 (1 B): Assert that the reward is removed when the order is modified and doesn't match the rules anymore
54 order.write({'order_line': [
55 (1, order.order_line[0].id, {'product_uom_qty': 2.0}),
56 (2, order.order_line[0].id, False)
57 ]})
58 order._update_programs_and_rewards()
59 self._claim_reward(order, self.immediate_promotion_program)
60 self.assertEqual(len(order.order_line.ids), 1, "The promo reward should have been removed as the rules are not matched anymore")
61 self.assertEqual(order.order_line.product_id.id, self.product_B.id, "The wrong line has been removed")