Debian Codegraph @

addons/sale_loyalty/tests/test_sale_invoicing.py

raw symbols SCIP
1 # Part of Odoo. See LICENSE file for full copyright and licensing details.
2
3 from odoo.tests import tagged
4
5 from odoo.addons.sale_loyalty.tests.common import TestSaleCouponCommon
6
7
8 @tagged('post_install', '-at_install')
9 class TestSaleInvoicing(TestSaleCouponCommon):
10
11 def test_invoicing_order_with_promotions(self):
12 discount_coupon_program = self.env['loyalty.program'].create({
13 'name': '10% Discount',
14 'program_type': 'coupons',
15 'applies_on': 'current',
16 'trigger': 'auto',
17 'rule_ids': [(0, 0, {})],
18 'reward_ids': [(0, 0, {
19 'reward_type': 'discount',
20 'discount': 10,
21 'discount_mode': 'percent',
22 'discount_applicability': 'order',
23 })]
24 })
25
26 product = self.env['product.product'].create({
27 'invoice_policy': 'delivery',
28 'name': 'Product invoiced on delivery',
29 'lst_price': 500,
30 })
31
32 order = self.empty_order
33 order.write({
34 'order_line': [
35 (0, 0, {
36 'product_id': product.id,
37 })
38 ]
39 })
40
41 #Check default invoice_policy on discount product
42 self.assertEqual(discount_coupon_program.reward_ids.discount_line_product_id.invoice_policy, 'order')
43
44 order._update_programs_and_rewards()
45 self._claim_reward(order, discount_coupon_program)
46 # Order is not confirmed, there shouldn't be any invoiceable line
47 invoiceable_lines = order._get_invoiceable_lines()
48 self.assertEqual(len(invoiceable_lines), 0)
49
50 order.action_confirm()
51 invoiceable_lines = order._get_invoiceable_lines()
52 # Product was not delivered, the order invoice status is 'No' as invoicing it should not be
53 # promoted, but the reward line should still be invoiceable, if users wants to invoice it
54 self.assertEqual(order.invoice_status, 'no')
55 self.assertEqual(len(invoiceable_lines), 1)
56
57 inv = order._create_invoices()
58 self.assertEqual(len(inv.invoice_line_ids), 1)
59 invoiceable_lines = order._get_invoiceable_lines()
60 self.assertEqual(len(invoiceable_lines), 0)
61 inv.button_cancel()
62
63 order.order_line[0].qty_delivered = 1
64 # Product is delivered, the two lines can be invoiced.
65 self.assertEqual(order.invoice_status, 'to invoice')
66 invoiceable_lines = order._get_invoiceable_lines()
67 self.assertEqual(order.order_line, invoiceable_lines)
68 account_move = order._create_invoices()
69 self.assertEqual(len(account_move.invoice_line_ids), 2)
70
71 def test_coupon_on_order_sequence(self):
72 discount_coupon_program = self.env['loyalty.program'].create({
73 'name': '10% Discount',
74 'program_type': 'coupons',
75 'applies_on': 'current',
76 'trigger': 'auto',
77 'rule_ids': [(0, 0, {})],
78 'reward_ids': [(0, 0, {
79 'reward_type': 'discount',
80 'discount': 10,
81 'discount_mode': 'percent',
82 'discount_applicability': 'order',
83 })]
84 })
85
86 order = self.empty_order
87
88 product_6 = self.env['product.product'].create({
89 'name': 'Large Cabinet',
90 })
91 # orderline1
92 self.env['sale.order.line'].create({
93 'product_id': product_6.id,
94 'name': 'largeCabinet',
95 'product_uom_qty': 1.0,
96 'order_id': order.id,
97 })
98
99 #Check default invoice_policy on discount product
100 self.assertEqual(discount_coupon_program.reward_ids.discount_line_product_id.invoice_policy, 'order')
101
102 self._auto_rewards(order, discount_coupon_program)
103
104 self.assertEqual(len(order.order_line), 2, 'Coupon correctly applied')
105
106 product_11 = self.env['product.product'].create({
107 'name': 'Conference Chair',
108 })
109
110 # orderline2
111 self.env['sale.order.line'].create({
112 'product_id': product_11.id,
113 'name': 'conferenceChair',
114 'product_uom_qty': 1.0,
115 'order_id': order.id,
116 })
117
118 order._update_programs_and_rewards()
119 self.assertEqual(len(order.order_line), 3, 'Coupon correctly applied')
120
121 self.assertTrue(order.order_line.sorted(lambda x: x.sequence)[-1].is_reward_line, 'Global coupons appear on the last line')