[TEST]
[odoo/odoo.git] / addons / account / test / price_accuracy00.yml
1 -   |
2     Tax Scenario:
3     In order to check that the accounting entries and tax engine works
4     efficiently with all kind of price accuracies we run this test scenario.
5 -  
6     Given the price accuracy for the account module is configured with two
7     digits
8 -  
9     !record {model: decimal.precision, id: product.decimal_account}:
10       digits: 2
11 -  
12     And we have a tax defined
13 -  
14     !record {model: account.tax, id: tax196}:
15       name: Tax 19.6%
16       amount: &tax 0.196
17 -  
18     And we define an invoice with one invoice line with a tax of *tax
19 -  
20     !record {model: account.invoice, id: invoice1}: &invoice
21         name: Precision Test
22         type: out_invoice
23         partner_id: base.res_partner_2
24         account_id: account.a_recv
25         date_invoice: !eval time.strftime('%Y-%m-%d')
26         invoice_line:
27             - product_id: product.product_product_3
28               quantity: &qty 11.11
29               account_id: account.a_sale
30               uos_id: product.product_uom_unit
31               price_unit: &price 12.34
32               name: test
33               invoice_line_tax_id:
34                   - tax196
35 -  
36     When I press on the CREATE button on the invoice to open it.
37 -  
38     !python {model: account.invoice}: |
39         self.action_move_create(cr, uid, [ref("invoice1")])  
40 -  
41     Then I should see an account entry linked to this invoice.
42 -  
43     !assert {model: account.invoice, id: invoice1}:
44       test:
45         - bool(move_id)
46 -  
47     # This is not working, find a way to do that in YAML, *qty is not
48     # interpreted because it's not a node.
49     And this account entry must have a credit equals to 163.97€ which is
50     equal to *qty x *price x (1 + *tax)
51 -  
52     !assert {model: account.invoice, id: invoice1}:
53         test:
54             - abs(sum(x.credit for x in move_id.line_id) - 163.97) < 0.000001
55 -  
56     And this account entry must have a credit equals to the debit
57 -  
58     !assert {model: account.invoice, id: invoice1}:
59         test:
60             - abs(sum(x.credit - x.debit for x in move_id.line_id)) < 0.000001
61 -  
62     Then, I change the precision of numbers to 3 digits.
63 -  
64     !record {model: decimal.precision, id: product.decimal_account}:
65       digits: 3
66 -  
67     And I create another invoice with the same content.
68 -  
69     !record {model: account.invoice, id: invoice2}:
70         *invoice
71 -  
72     When I press on the CREATE button on the invoice to open it.
73 -  
74     !python {model: account.invoice}: |
75         self.action_move_create(cr, uid, [ref("invoice2")])  
76 -    
77     Then this account entry must have a credit equals to the debit
78 -  
79     !assert {model: account.invoice, id: invoice2}:
80         test:
81             - abs(sum(x.credit - x.debit for x in move_id.line_id)) < 0.000001
82 -
83     And this account entry must have a credit equals to 163.968€ which is
84     equal to *qty x *price x (1 + *tax)
85 -  
86     !python {model: account.invoice}: |
87         xid = "invoice2"
88         invoice = self.browse(cr, uid, ref(xid))
89         sum_of_credits = sum(x.credit for x in invoice.move_id.line_id)
90         log("The sum of credits for %s is %f", xid, sum_of_credits)
91         expected_value = 163.968
92         assert (sum_of_credits - expected_value) < 0.000001, "Wrong sum of credits: %f <> %f" % (sum_of_credits, expected_value)
93