[TEST] add unit test to ensure POS only considere product taxes from current session...
[odoo/odoo.git] / addons / point_of_sale / test / 01_order_to_payment.yml
1 - |
2   In order to test the Point of Sale in module, I will do a full flow from the sale to the payment and invoicing.
3   I will use two products, one with price including a 10% tax, the other one with 5% tax excluded from the price.
4 - |
5   I create a VAT tax of 10%, included in the public price
6
7   !record {model: account.tax, id: account_tax_10_incl}:
8     name: VAT 10 perc Incl
9     type: percent
10     amount: 0.10
11     account_paid_id: account.iva
12     account_collected_id: account.iva
13     price_include: 1
14 -
15   I assign this 10 percent tax on the PC1 product as a sale tax
16 -
17   !record {model: product.product, id: product.product_product_pc1}:
18     taxes_id: [account_tax_10_incl]
19 - |
20   I create a VAT tax of 5%, which is added to the public price
21
22   !record {model: account.tax, id: account_tax_05_incl}:
23     name: VAT 05 perc Excl
24     type: percent
25     amount: 0.05
26     account_paid_id: account.iva
27     account_collected_id: account.iva
28     price_include: 0
29 -
30   I will create a second VAT tax of 5% but this time for a child company, to
31   ensure that only product taxes of the current session's company are considered
32   (this tax should be ignore when computing order's taxes in following tests)
33 -
34   !record {model: account.tax, id: account_tax_05_incl_chicago}:
35     name: VAT 05 perc Excl (US)
36     type: percent
37     amount: 0.05
38     account_paid_id: account.iva
39     account_collected_id: account.iva
40     price_include: 0
41     company_id: stock.res_company_1
42 -
43   I assign those 5 percent taxes on the PC2 product as a sale taxes
44 -
45   !record {model: product.product, id: product.product_product_pc2}:
46     taxes_id: [account_tax_05_incl, account_tax_05_incl_chicago]
47 -
48   I create a PoS order with 2 units of PC1 at 450 EUR (Tax Incl) and 3 units of PC2 at 300 EUR. (Tax Excl)
49 -
50   !record {model: pos.order, id: pos_order_pos0}:
51     company_id: base.main_company
52     lines:
53       - name: OL/0001
54         product_id: product.product_product_pc1
55         price_unit: 450
56         discount: 0.0
57         qty: 2.0
58       - name: OL/0002
59         product_id: product.product_product_pc2
60         price_unit: 300
61         discount: 0.0
62         qty: 3.0
63
64   I check that the total of the order is equal to 450*2 + 300*3*1.05 and the tax of the order is equal to 900 -(450 * 2 / 1.1) + 300*0.05*3
65
66   !python {model: pos.order}: |
67     order = self.browse(cr, uid, ref('pos_order_pos0'))
68     assert(abs(order.amount_total - (450*2 + 300*3*1.05)) < 0.01), "The order has a wrong amount, tax included"
69     assert(abs(order.amount_tax - (900-(450*2/1.1) + 300*0.05*3)) < 0.01), "The order has a wrong tax amount"
70
71   I want to add a global discount of 5 percent using the wizard
72
73   !record {model: pos.discount, id: pos_discount_0}:
74     discount: 5.0
75
76   I click the apply button to set the discount on all lines
77
78   !python {model: pos.discount}: |
79     self.apply_discount(cr, uid, [ref("pos_discount_0")], {"active_model": "pos.order",
80       "active_ids": [ref("pos_order_pos0")], "active_id": ref("pos_order_pos0"), })
81
82   I check that the total of the order is now equal to (450*2 + 300*3*1.05)*0.95
83
84   !python {model: pos.order}: |
85     order = self.browse(cr, uid, ref('pos_order_pos0'))
86     assert(abs(order.amount_total - (450*2 + 300*3*1.05)*0.95) < 0.01), "The order has a wrong total including tax and discounts"
87 -
88   I click on the "Make Payment" wizard to pay the PoS order with a partial amount of 100.0 EUR
89
90   !record {model: pos.make.payment, id: pos_make_payment_0, context: '{"active_id": ref("pos_order_pos0"), "active_ids": [ref("pos_order_pos0")]}' }:
91     amount: 100.0
92 -
93   I click on the validate button to register the payment.
94 -
95   !python {model: pos.make.payment}: |
96     self.check(cr, uid, [ref('pos_make_payment_0')], context={'active_id': ref('pos_order_pos0'), 'lang':'en_US', 'active_model': 'pos.order', 'tz': False, 'active_ids': [ref('pos_order_pos0')]} )
97 - |
98   I check that the order is not marked as paid yet
99 -
100   !assert {model: pos.order, id: pos_order_pos0}:
101      - state == 'draft'
102 - |
103   On the second payment proposition, I check that it proposes me the remaining balance which is 1790.0 EUR
104
105   !python {model: pos.make.payment}: |
106      defs = self.default_get(cr, uid, ['amount'], {'active_id': ref('pos_order_pos0')})
107      assert abs(defs['amount'] - ((450*2 + 300*3*1.05)*0.95-100.0)) < 0.01, "The remaining balance is incorrect"
108 -
109   I pay the remaining balance.
110
111   !record {model: pos.make.payment, id: pos_make_payment_1, context: '{"active_id": ref("pos_order_pos0"), "active_ids": [ref("pos_order_pos0")]}' }:
112     amount: !eval >
113       (450*2 + 300*3*1.05)*0.95-100.0
114 -
115   I click on the validate button to register the payment.
116 -
117   !python {model: pos.make.payment}: |
118     self.check(cr, uid, [ref('pos_make_payment_1')], context={'active_id': ref('pos_order_pos0')} )
119 - |
120   I check that the order is marked as paid
121 -
122   !assert {model: pos.order, id: pos_order_pos0}:
123      - state == 'paid'
124
125   I generate the journal entries
126 -
127   !python {model: pos.order}: |
128     self.create_account_move(cr, uid, [ref('pos_order_pos0')], {})
129 -
130   I test that the generated journal entry is attached to the PoS order
131 -
132   !assert {model: pos.order, id: pos_order_pos0}:
133      - bool(account_move)
134   
135
136
137