[IMP] hr: onboarding
[odoo/odoo.git] / addons / account_voucher / test / case2_usd_eur_debtor_in_eur.yml
1 -
2   In order to check the Account_voucher module with multi-currency in OpenERP, 
3   I create 2 Invoices in USD and make 2 Payments one in USD and another in EUR, 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 modify the debtor account in order to make sure there is no currency_id linked
15 -
16   !python {model: account.account}: |
17     from datetime import datetime
18     ids = self.search(cr, uid, [('name', 'ilike', 'debtor')])
19     self.write(cr, uid, ids, {'currency_id': False})
20 -
21   I create currency USD in OpenERP for January of 1.333333 Rate
22 -
23   !python {model: res.currency.rate}: |
24     from datetime import datetime
25     curr_id = self.pool.get('res.currency').search(cr, uid, [('name', '=', 'USD')])[0]
26     date = '%s-01-01' %(datetime.now().year)
27     ids = self.search(cr, uid, [('currency_id', '=', curr_id), ('name', '=', date)])
28     self.write(cr, uid, ids, {'rate': 1.333333})
29 -
30   I create currency USD in OpenERP for February of 1.250000 Rate
31 -
32   !record {model: res.currency.rate, id: feb_usd}:
33     currency_id: base.USD
34     name: !eval "'%s-02-01' %(datetime.now().year)"
35     rate: 1.250000
36 -
37   I create currency USD in OpenERP for March of 1.111111 Rate
38 -
39   !record {model: res.currency.rate, id: mar_usd}:
40     currency_id: base.USD
41     name: !eval "'%s-03-01' %(datetime.now().year)"
42     rate: 1.111111
43 -
44   I create currency USD in OpenERP for April of 1.052632 Rate
45 -
46   !record {model: res.currency.rate, id: apr_usd}:
47     currency_id: base.USD
48     name: !eval "'%s-04-01' %(datetime.now().year)"
49     rate: 1.052632
50 -
51   I create a bank journal with EUR as currency
52 -
53   !record {model: account.journal, id: bank_journal_EUR}:
54     name: Bank Journal(EUR)
55     code: BEUR
56     type: bank
57     analytic_journal_id: analytic.sit
58     sequence_id: account.sequence_bank_journal
59     default_debit_account_id: account.cash
60     default_credit_account_id: account.cash
61     company_id: base.main_company
62 -
63   I create a bank journal with USD as currency
64 -
65   !record {model: account.journal, id: bank_journal_USD}:
66     name: Bank Journal(USD)
67     code: BUSD
68     type: bank
69     analytic_journal_id: analytic.sit
70     sequence_id: account.sequence_bank_journal
71     default_debit_account_id: account_cash_usd_id
72     default_credit_account_id: account_cash_usd_id
73     currency: base.USD
74     company_id: base.main_company
75 -
76   I create the first invoice on 1st January for 200 USD
77 -
78   !record {model: account.invoice, id: account_first_invoice_jan}:
79     account_id: account.a_recv
80     company_id: base.main_company
81     currency_id: base.USD
82     date_invoice: !eval "'%s-01-01' %(datetime.now().year)"
83     period_id: account.period_1
84     invoice_line:
85       - account_id: account.a_sale
86         name: '[PCSC234] PC Assemble SC234'
87         price_unit: 200.0
88         quantity: 1.0
89         product_id: product.product_product_3
90         uos_id: product.product_uom_unit
91     journal_id: account.sales_journal
92     partner_id: base.res_partner_19
93     reference_type: none
94 -
95   I Validate invoice by clicking on Validate button
96 -
97   !workflow {model: account.invoice, action: invoice_open, ref: account_first_invoice_jan}
98 -
99   I check that first invoice move is correct for debtor account(debit - credit == 150)
100 -
101   !python {model: account.invoice}: |
102     from openerp.tools import float_compare
103     invoice_id = self.browse(cr, uid, ref("account_first_invoice_jan"))
104     assert invoice_id.move_id, "Move not created for open invoice"
105     move_line_obj = self.pool.get('account.move.line')
106     move_lines = move_line_obj.search(cr, uid, [('move_id', '=', invoice_id.move_id.id), ('account_id', '=', invoice_id.account_id.id)])
107     move_line = move_line_obj.browse(cr, uid, move_lines[0])
108     assert (float_compare(move_line.debit - move_line.credit, 150.00, precision_digits=2) == 0), "Invoice move is incorrect for debtors account"
109 -
110   I create the second invoice on 1st February for 100 USD
111 -
112   !record {model: account.invoice, id: account_second_invoice_feb}:
113     account_id: account.a_recv
114     company_id: base.main_company
115     currency_id: base.USD
116     date_invoice: !eval "'%s-02-01' %(datetime.now().year)"
117     period_id: account.period_2
118     invoice_line:
119       - account_id: account.a_sale
120         name: '[PCSC234] PC Assemble SC234'
121         price_unit: 100.0
122         quantity: 1.0
123         product_id: product.product_product_3
124         uos_id: product.product_uom_unit
125     journal_id: account.sales_journal
126     partner_id: base.res_partner_19
127     reference_type: none
128 -
129   I Validate invoice by clicking on Validate button
130 -
131   !workflow {model: account.invoice, action: invoice_open, ref: account_second_invoice_feb}
132 -
133   I check that second invoice move is correct for debtor account (debit - credit == 80)
134 -
135   !python {model: account.invoice}: |
136     from openerp.tools import float_compare
137     invoice_id = self.browse(cr, uid, ref("account_second_invoice_feb"))
138     assert invoice_id.move_id, "Move not created for open invoice"
139     move_line_obj = self.pool.get('account.move.line')
140     move_lines = move_line_obj.search(cr, uid, [('move_id', '=', invoice_id.move_id.id), ('account_id', '=', invoice_id.account_id.id)])
141     move_line = move_line_obj.browse(cr, uid, move_lines[0])
142     assert (float_compare(move_line.debit - move_line.credit, 80, precision_digits=2) == 0), "Invoice move is incorrect for debtors account"
143 -
144   I set the context that will be used for the encoding of all the vouchers of this file
145 -
146   !context
147     'type': 'receipt'
148 -
149   I create the first voucher of payment with values 200 EUR, journal EUR 
150 -
151   !record {model: account.voucher, id: account_voucher_1_case2a, view: view_vendor_receipt_form}:
152     account_id: account.cash
153     amount: 200.0
154     company_id: base.main_company
155     journal_id: bank_journal_EUR
156     partner_id: base.res_partner_19
157     period_id: account.period_3
158     date: !eval time.strftime("%Y-03-01")
159     payment_option: 'with_writeoff'
160     writeoff_acc_id: account.a_expense
161     comment: 'Write Off'
162     name: 'First payment: Case 2 USD/EUR DR EUR'
163
164 -
165   I fill amounts 130 for the invoice of 200$ and 70 for the invoice of 100$
166 -
167   !python {model: account.voucher}: |
168     from openerp.tools import float_compare
169     import time
170     from openerp import netsvc
171     vals = {}
172     voucher_id = self.browse(cr, uid, ref('account_voucher_1_case2a'))
173     data = []
174     for item in voucher_id.line_cr_ids:
175         if float_compare(item.amount_unreconciled, 150.00, precision_digits=2) == 0:
176             data += [(item.id, 130.0)]
177         else:
178             data += [(item.id, 70.0)]
179     for line_id, amount in data:
180         self.pool.get('account.voucher.line').write(cr, uid, [line_id], {'amount': amount})
181     assert (voucher_id.state=='draft'), "Voucher is not in draft state"
182 -
183   I confirm the voucher
184 -
185   !python {model: account.voucher}: |
186     from openerp import netsvc
187     voucher = self.search(cr, uid, [('name', '=', 'First payment: Case 2 USD/EUR DR EUR'), ('partner_id', '=', ref('base.res_partner_19'))])
188     self.signal_workflow(cr, uid, voucher, 'proforma_voucher')
189 -
190   I check that the move of my voucher is valid
191 -
192   !python {model: account.voucher}: |
193     voucher = self.search(cr, uid, [('name', '=', 'First payment: Case 2 USD/EUR DR EUR'), ('partner_id', '=', ref('base.res_partner_19'))])
194     voucher_id = self.browse(cr, uid, voucher[0])
195     move_line_obj = self.pool.get('account.move.line')
196     move_lines = move_line_obj.search(cr, uid, [('move_id', '=', voucher_id.move_id.id)])
197     for move_line in move_line_obj.browse(cr, uid, move_lines):
198         assert move_line.state == 'valid', "Voucher move is not valid"
199 -
200   I check the residual amount of Invoice1, should be 55.56 in residual currency and 20 in amount_residual
201 -
202   !python {model: account.invoice}: |
203     from openerp.tools import float_compare
204     invoice_id = self.browse(cr, uid, ref("account_first_invoice_jan"))
205     move_line_obj = self.pool.get('account.move.line')
206     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)])
207     move_line = move_line_obj.browse(cr, uid, move_lines[0])
208     assert (float_compare(move_line.amount_residual_currency, 55.56, precision_digits=2) == 0 and float_compare(move_line.amount_residual, 20, precision_digits=2) == 0) , "Residual amount is not correct for first Invoice. Got %s USD (%s EUR)" %(move_line.amount_residual_currency, move_line.amount_residual)
209 -
210   I check the residual amuont of Invoice2, should be 22.22 in residual currency and 10 in amount_residual
211 -
212    !python {model: account.invoice}: |
213     from openerp.tools import float_compare
214     invoice_id = self.browse(cr, uid, ref("account_second_invoice_feb"))
215     move_line_obj = self.pool.get('account.move.line')
216     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)])
217     move_line = move_line_obj.browse(cr, uid, move_lines[0])
218     assert (float_compare(move_line.amount_residual_currency, 22.22, precision_digits=2) == 0 and float_compare(move_line.amount_residual, 10, precision_digits=2) == 0) , "Residual amount is not correct for second Invoice"
219 -
220   I create the second voucher of payment with values 80 USD, journal USD
221 -
222   !record {model: account.voucher, id: account_voucher_2_case2a, view: view_vendor_receipt_form}:
223     account_id: account.cash
224     amount: 80
225     company_id: base.main_company
226     journal_id: bank_journal_USD
227     partner_id: base.res_partner_19
228     period_id: account.period_3
229     date: !eval time.strftime("%Y-04-01")
230     payment_option: 'with_writeoff'
231     writeoff_acc_id: account.a_expense
232     comment: 'Write Off'
233     name: 'Second payment: Case 2 SUPPL USD/EUR DR EUR'
234
235 -
236   and I fully reconcile the 2 previous invoices
237 -
238   !python {model: account.voucher}: |
239     import time
240     from openerp import netsvc
241     from openerp.tools import float_compare
242     vals = {}
243     voucher_id = self.browse(cr, uid, ref('account_voucher_2_case2a'))
244     data = []
245     for item in voucher_id.line_cr_ids:
246         if float_compare(item.amount_unreconciled, 55.56, precision_digits=2) == 0:
247             data += [(item.id, 55.56)]
248         else:
249             data += [(item.id, 22.22)]
250     for line_id, amount in data:
251         self.pool.get('account.voucher.line').write(cr, uid, [line_id], {'amount': amount})
252     assert (voucher_id.state=='draft'), "Voucher is not in draft state"
253 -
254   I check that writeoff amount computed is 2.22
255 -
256   !python {model: account.voucher}: |
257     from openerp.tools import float_compare
258     voucher = self.search(cr, uid, [('name', '=', 'Second payment: Case 2 SUPPL USD/EUR DR EUR'), ('partner_id', '=', ref('base.res_partner_19'))])
259     voucher_id = self.browse(cr, uid, voucher[0])
260     assert (float_compare(round(voucher_id.writeoff_amount, 2), 2.22, precision_digits=2) == 0), "Writeoff amount is not 2.22$"
261 -
262   I confirm the voucher
263 -
264   !python {model: account.voucher}: |
265     from openerp import netsvc
266     voucher = self.search(cr, uid, [('name', '=', 'Second payment: Case 2 SUPPL USD/EUR DR EUR'), ('partner_id', '=', ref('base.res_partner_19'))])
267     self.signal_workflow(cr, uid, voucher, 'proforma_voucher')
268 -
269   I check that my voucher state is posted
270 -
271   !python {model: account.voucher}: |
272     voucher = self.search(cr, uid, [('name', '=', 'Second payment: Case 2 SUPPL USD/EUR DR EUR'), ('partner_id', '=', ref('base.res_partner_19'))])
273     voucher_id = self.browse(cr, uid, voucher[0])
274     assert voucher_id.state == 'posted', "Voucher state is not posted"
275 -
276   I check that my debtor account is correct
277 -
278   I check that the debtor account has 2 new lines with -55.56 and -22.22 in amount_currency columns and their credit columns are respectively 52.78 and 21.11 and currency is USD($).
279 -
280   I check that my currency rate difference is correct.
281 -
282   I check that my writeoff is correct. 2.11 in credit and 2.22 in amount_currency
283 -
284   !python {model: account.voucher}: |
285     from openerp.tools import float_compare
286     voucher = self.search(cr, uid, [('name', '=', 'Second payment: Case 2 SUPPL USD/EUR DR EUR'), ('partner_id', '=', ref('base.res_partner_19'))])
287     voucher_id = self.browse(cr, uid, voucher[0])
288     move_line_obj = self.pool.get('account.move.line')
289     move_lines = move_line_obj.search(cr, uid, [('move_id', '=', voucher_id.move_id.id)])
290     reconcile_a = reconcile_b = False
291     for move_line in move_line_obj.browse(cr, uid, move_lines):
292         if float_compare(move_line.amount_currency, -22.22, precision_digits=2) == 0:
293             assert move_line.reconcile_id.id, "The invoice of 200$ is not fully reconciled"
294             reconcile_b = move_line.reconcile_id.id
295         elif float_compare(move_line.amount_currency, -55.56, precision_digits=2) == 0:
296             assert move_line.reconcile_id.id, "The invoice of 100$ is not fully reconciled"
297             reconcile_a = move_line.reconcile_id.id
298     for move_line in move_line_obj.browse(cr, uid, move_lines):
299         if float_compare(move_line.amount_currency, -55.56, precision_digits=2) == 0:
300             assert float_compare(move_line.credit, 52.78, precision_digits=2) == 0, "Debtor account has wrong entry."
301         elif float_compare(move_line.amount_currency, -22.22, precision_digits=2) == 0:
302             assert float_compare(move_line.credit, 21.11, precision_digits=2) == 0, "Debtor account has wrong entry."
303         elif float_compare(move_line.credit, 11.11, precision_digits=2) == 0 and move_line.account_id.reconcile:
304             assert float_compare(move_line.amount_currency, 0.00, precision_digits=2) == 0 and move_line.reconcile_id.id == reconcile_b, "Incorrect Currency Difference."
305         elif float_compare(move_line.credit, 32.78, precision_digits=2) == 0 and move_line.account_id.reconcile:
306             assert float_compare(move_line.amount_currency, 0.00, precision_digits=2) == 0 and move_line.reconcile_id.id == reconcile_a, "Incorrect Currency Difference."
307         elif float_compare(move_line.amount_currency, 2.22, precision_digits=2) == 0:
308             assert float_compare(move_line.credit, 2.11, precision_digits=2) == 0, "Writeoff amount is wrong."
309 -
310   I check the residual amount of invoice 1, should be 0 in residual currency and 0 in amount_residual and paid
311 -
312   !python {model: account.invoice}: |
313     from openerp.tools import float_compare
314     invoice_id = self.browse(cr, uid, ref("account_first_invoice_jan"))
315     move_line_obj = self.pool.get('account.move.line')
316     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)])
317     move_line = move_line_obj.browse(cr, uid, move_lines[0])
318     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"
319 -    
320   I check the residual amuont of invoice 2, should be 0 in residual currency and 0 in amount_residual and paid
321 -
322    !python {model: account.invoice}: |
323     from openerp.tools import float_compare
324     invoice_id = self.browse(cr, uid, ref("account_second_invoice_feb"))
325     move_line_obj = self.pool.get('account.move.line')
326     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)])
327     move_line = move_line_obj.browse(cr, uid, move_lines[0])
328     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 second Invoice"