[IMP] hr: onboarding
[odoo/odoo.git] / addons / account_voucher / test / case4_cad_chf.yml
1 -
2   In order to check the Account_voucher module with multi-currency in OpenERP,
3   I create an invoice in CAD and make its Payment in CHF based on the currency rating on that particular date.
4 -
5   I set the income and expense currency accounts on the main company
6 -
7   !python {model: res.company}: |
8     from datetime import datetime
9     vals = {
10       'income_currency_exchange_account_id': ref('account.o_expense'),
11       'expense_currency_exchange_account_id': ref('account.o_expense')}
12     self.write(cr, uid, ref('base.main_company'), vals)
13 -
14   I create currency CAD in OpenERP for January of 1.338800 Rate
15 -
16   !record {model: res.currency.rate, id: jan_cad}:
17     currency_id: base.CAD
18     name: !eval "'%s-01-01' %(datetime.now().year)"
19     rate: 1.338800
20 -
21   I create currency CAD in OpenERP for March of 2.000000 Rate
22 -
23   !record {model: res.currency.rate, id: mar_cad}:
24     currency_id: base.CAD
25     name: !eval "'%s-03-01' %(datetime.now().year)"
26     rate: 2.000000
27 -
28   I create currency CHF in OpenERP for January of 1.308600 Rate
29 -
30   !record {model: res.currency.rate, id: jan_chf}:
31     currency_id: base.CHF
32     name: !eval "'%s-01-01' %(datetime.now().year)"
33     rate: 1.308600
34 -
35   I create currency CHF in OpenERP for March of 1.250000 Rate
36 -
37   !record {model: res.currency.rate, id: mar_chf}:
38     currency_id: base.CHF
39     name: !eval "'%s-03-01' %(datetime.now().year)"
40     rate: 1.25000
41 -
42   I create a cash account with currency CHF
43 -
44   !record {model: account.account, id: account_cash_chf_id}:
45     currency_id: base.CHF
46     name: "cash account in chf"
47     code: "Xcash chf"
48     type: 'liquidity'
49     user_type: "account.data_account_type_cash"
50
51 -
52   I create a bank journal with CHF as currency
53 -
54   !record {model: account.journal, id: bank_journal_CHF}:
55     name: Bank Journal(CHF)
56     code: BCHF
57     type: bank
58     analytic_journal_id: analytic.sit
59     sequence_id: account.sequence_bank_journal
60     default_debit_account_id: account_cash_chf_id
61     default_credit_account_id: account_cash_chf_id
62     currency: base.CHF
63     company_id: base.main_company
64 -
65   I create the first invoice on 1st January for 200 CAD
66 -
67   !record {model: account.invoice, id: account_first_invoice_jan_cad}:
68     account_id: account.a_recv
69     company_id: base.main_company
70     currency_id: base.CAD
71     date_invoice: !eval "'%s-01-01' %(datetime.now().year)"
72     period_id: account.period_1
73     invoice_line:
74       - account_id: account.a_sale
75         name: '[PCSC234] PC Assemble SC234'
76         price_unit: 200.0
77         quantity: 1.0
78         product_id: product.product_product_3
79         uos_id: product.product_uom_unit
80     journal_id: account.sales_journal
81     partner_id: base.res_partner_19
82     reference_type: none
83 -
84   I Validate invoice by clicking on Validate button
85 -
86   !workflow {model: account.invoice, action: invoice_open, ref: account_first_invoice_jan_cad}
87 -
88   I check that first invoice move is correct for debtor account (debit - credit == 149.39)
89 -
90   !python {model: account.invoice}: |
91     from openerp.tools import float_compare
92     invoice_id = self.browse(cr, uid, ref("account_first_invoice_jan_cad"))
93     assert invoice_id.move_id, "Move not created for open invoice"
94     move_line_obj = self.pool.get('account.move.line')
95     move_lines = move_line_obj.search(cr, uid, [('move_id', '=', invoice_id.move_id.id), ('account_id', '=', invoice_id.account_id.id)])
96     move_line = move_line_obj.browse(cr, uid, move_lines[0])
97     assert (float_compare(move_line.debit - move_line.credit, 149.39, precision_digits=2) == 0), "Invoice move is incorrect for debtors account"
98 -
99   I set the context that will be used for the encoding of all the vouchers of this file
100 -
101   !context
102     'type': 'receipt'
103 -
104   I create the first voucher of payment with values 200 CHF, journal CHF
105 -
106   !record {model: account.voucher, id: account_voucher_1_case4, view: view_vendor_receipt_form}:
107     account_id: account.cash
108     amount: 200
109     company_id: base.main_company
110     journal_id: bank_journal_CHF
111     partner_id: base.res_partner_19
112     period_id: account.period_3
113     date: !eval time.strftime("%Y-03-01")
114     payment_option: 'with_writeoff'
115     writeoff_acc_id: account.a_expense
116     comment: 'Write Off'
117     name: 'First payment: Case 4'
118 -
119   I completly pay the invoice of 200 CAD
120 -
121   !python {model: account.voucher}: |
122     import time
123     from openerp import netsvc
124     from openerp.tools import float_compare
125     vals = {}
126     voucher_id = self.browse(cr, uid, ref('account_voucher_1_case4'))
127     data = []
128     for item in voucher_id.line_cr_ids:
129         if float_compare(item.amount_unreconciled, 186.74, precision_digits=2) == 0:
130             data += [(item.id, 186.74)]
131         else:
132             data += [(item.id, 0.0)]
133     for line_id, amount in data:
134         self.pool.get('account.voucher.line').write(cr, uid, [line_id], {'amount': amount})
135     assert (voucher_id.state=='draft'), "Voucher is not in draft state"
136 -
137   I check that writeoff amount computed is 13.26
138 -
139   !python {model: account.voucher}: |
140     from openerp.tools import float_compare
141     voucher = self.search(cr, uid, [('name', '=', 'First payment: Case 4'), ('partner_id', '=', ref('base.res_partner_19'))])
142     voucher_id = self.browse(cr, uid, voucher[0])
143     assert (float_compare(round(voucher_id.writeoff_amount,2), 13.26, precision_digits=2) == 0), "Writeoff amount is not 13.26 CHF"
144 -
145   I confirm the voucher
146 -
147   !python {model: account.voucher}: |
148     voucher = self.search(cr, uid, [('name', '=', 'First payment: Case 4'), ('partner_id', '=', ref('base.res_partner_19'))])
149     self.signal_workflow(cr, uid, voucher, 'proforma_voucher')
150
151 -
152   I check that the move of my voucher is valid
153 -
154   !python {model: account.voucher}: |
155     voucher = self.search(cr, uid, [('name', '=', 'First payment: Case 4'), ('partner_id', '=', ref('base.res_partner_19'))])
156     voucher_id = self.browse(cr, uid, voucher[0])
157     move_line_obj = self.pool.get('account.move.line')
158     move_lines = move_line_obj.search(cr, uid, [('move_id', '=', voucher_id.move_id.id)])
159     for move_line in move_line_obj.browse(cr, uid, move_lines):
160         assert move_line.state == 'valid', "Voucher move is not valid"
161     assert voucher_id.state == 'posted', "Voucher state is not posted"
162 -
163   I check that my debtor account is correct
164 -
165   I check that the debtor account has 1 new line with -298.78 as amount_currency columns and 149.39 of credit and currency is CAD.
166 -
167   I check that my currency rate difference is correct. 0 in debit with 98.78 CAD as amount_currency
168 -
169   I check that my writeoff is correct. 11.05 credit and -13.26 amount_currency
170 -
171   !python {model: account.voucher}: |
172     from openerp.tools import float_compare
173     voucher = self.search(cr, uid, [('name', '=', 'First payment: Case 4'), ('partner_id', '=', ref('base.res_partner_19'))])
174     voucher_id = self.browse(cr, uid, voucher[0])
175     move_line_obj = self.pool.get('account.move.line')
176     move_lines = move_line_obj.search(cr, uid, [('move_id', '=', voucher_id.move_id.id)])
177     assert move_lines, "Voucher move has no lines"
178     for move_line in move_line_obj.browse(cr, uid, move_lines):
179         if float_compare(move_line.amount_currency, 200, precision_digits=2) == 0:
180             assert float_compare(move_line.debit, 160.00, precision_digits=2) == 0, "Bank account has wrong entry."
181         elif float_compare(move_line.amount_currency, -298.78, precision_digits=2) == 0 :
182             assert float_compare(move_line.credit, 149.39, precision_digits=2) == 0, "Debtor account has wrong entry."
183         elif float_compare(move_line.debit, 0.00, precision_digits=2) == 0 and float_compare(move_line.credit, 0.00, precision_digits=2) == 0:
184             assert float_compare(move_line.amount_currency, 98.78, precision_digits=2) == 0, "Incorrect Currency Difference, got %s as amount_currency (expected 98.78)." % (move_line.amount_currency)
185             assert move_line.currency_id.id == ref('base.CAD'), "Incorrect Currency Difference, got %s (expected 'CAD')" % (move_line.currency_id.name)
186         elif float_compare(move_line.credit, 10.61, precision_digits=2) == 0:
187             assert float_compare(move_line.amount_currency, -13.26, precision_digits=2) == 0, "Writeoff amount is wrong."
188         else:
189             assert False, "Wrong entry"
190 -
191   I check the residual amount of Invoice1, should be 0 in residual currency and 0 in amount_residual and paid
192 -
193   !python {model: account.invoice}: |
194     from openerp.tools import float_compare
195     invoice_id = self.browse(cr, uid, ref("account_first_invoice_jan_cad"))
196     move_line_obj = self.pool.get('account.move.line')
197     move_lines = move_line_obj.search(cr, uid, [('move_id', '=', invoice_id.move_id.id), ('invoice', '=', invoice_id.id), ('account_id', '=', invoice_id.account_id.id)])
198     move_line = move_line_obj.browse(cr, uid, move_lines[0])
199     assert (float_compare(move_line.amount_residual_currency, 0.0, precision_digits=2) == 0 and float_compare(move_line.amount_residual, 0.0, precision_digits=2) == 0 and invoice_id.state == 'paid') , "Residual amount is not correct for first Invoice"