[FIX] /web/login restore request.uid in case of authentication failure
[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: account.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: account.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     invoice_id = self.browse(cr, uid, ref("account_first_invoice_jan"))
103     assert invoice_id.move_id, "Move not created for open invoice"
104     move_line_obj = self.pool.get('account.move.line')
105     move_lines = move_line_obj.search(cr, uid, [('move_id', '=', invoice_id.move_id.id), ('account_id', '=', invoice_id.account_id.id)])
106     move_line = move_line_obj.browse(cr, uid, move_lines[0])
107     assert (move_line.debit - move_line.credit == 150.00), "Invoice move is incorrect for debtors account"
108 -
109   I create the second invoice on 1st February for 100 USD
110 -
111   !record {model: account.invoice, id: account_second_invoice_feb}:
112     account_id: account.a_recv
113     company_id: base.main_company
114     currency_id: base.USD
115     date_invoice: !eval "'%s-02-01' %(datetime.now().year)"
116     period_id: account.period_2
117     invoice_line:
118       - account_id: account.a_sale
119         name: '[PCSC234] PC Assemble SC234'
120         price_unit: 100.0
121         quantity: 1.0
122         product_id: product.product_product_3
123         uos_id: product.product_uom_unit
124     journal_id: account.sales_journal
125     partner_id: base.res_partner_19
126     reference_type: none
127 -
128   I Validate invoice by clicking on Validate button
129 -
130   !workflow {model: account.invoice, action: invoice_open, ref: account_second_invoice_feb}
131 -
132   I check that second invoice move is correct for debtor account (debit - credit == 80)
133 -
134   !python {model: account.invoice}: |
135     invoice_id = self.browse(cr, uid, ref("account_second_invoice_feb"))
136     assert invoice_id.move_id, "Move not created for open invoice"
137     move_line_obj = self.pool.get('account.move.line')
138     move_lines = move_line_obj.search(cr, uid, [('move_id', '=', invoice_id.move_id.id), ('account_id', '=', invoice_id.account_id.id)])
139     move_line = move_line_obj.browse(cr, uid, move_lines[0])
140     assert (move_line.debit - move_line.credit == 80), "Invoice move is incorrect for debtors account"
141 -
142   I set the context that will be used for the encoding of all the vouchers of this file
143 -
144   !context
145     'type': 'receipt'
146 -
147   I create the first voucher of payment with values 200 EUR, journal EUR 
148 -
149   !record {model: account.voucher, id: account_voucher_1_case2a, view: view_vendor_receipt_form}:
150     account_id: account.cash
151     amount: 200.0
152     company_id: base.main_company
153     journal_id: bank_journal_EUR
154     partner_id: base.res_partner_19
155     period_id: account.period_3
156     date: !eval time.strftime("%Y-03-01")
157     payment_option: 'with_writeoff'
158     writeoff_acc_id: account.a_expense
159     comment: 'Write Off'
160     name: 'First payment: Case 2 USD/EUR DR EUR'
161
162 -
163   I fill amounts 130 for the invoice of 200$ and 70 for the invoice of 100$
164 -
165   !python {model: account.voucher}: |
166     import time
167     from openerp import netsvc
168     vals = {}
169     voucher_id = self.browse(cr, uid, ref('account_voucher_1_case2a'))
170     data = []
171     for item in voucher_id.line_cr_ids:
172         if item.amount_unreconciled == 150.00:
173             data += [(item.id, 130.0)]
174         else:
175             data += [(item.id, 70.0)]
176     for line_id, amount in data:
177         self.pool.get('account.voucher.line').write(cr, uid, [line_id], {'amount': amount})
178     assert (voucher_id.state=='draft'), "Voucher is not in draft state"
179 -
180   I confirm the voucher
181 -
182   !python {model: account.voucher}: |
183     from openerp import netsvc
184     voucher = self.search(cr, uid, [('name', '=', 'First payment: Case 2 USD/EUR DR EUR'), ('partner_id', '=', ref('base.res_partner_19'))])
185     self.signal_proforma_voucher(cr, uid, voucher)
186 -
187   I check that the move of my voucher is valid
188 -
189   !python {model: account.voucher}: |
190     voucher = self.search(cr, uid, [('name', '=', 'First payment: Case 2 USD/EUR DR EUR'), ('partner_id', '=', ref('base.res_partner_19'))])
191     voucher_id = self.browse(cr, uid, voucher[0])
192     move_line_obj = self.pool.get('account.move.line')
193     move_lines = move_line_obj.search(cr, uid, [('move_id', '=', voucher_id.move_id.id)])
194     for move_line in move_line_obj.browse(cr, uid, move_lines):
195         assert move_line.state == 'valid', "Voucher move is not valid"
196 -
197   I check the residual amount of Invoice1, should be 55.56 in residual currency and 20 in amount_residual
198 -
199   !python {model: account.invoice}: |
200     invoice_id = self.browse(cr, uid, ref("account_first_invoice_jan"))
201     move_line_obj = self.pool.get('account.move.line')
202     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)])
203     move_line = move_line_obj.browse(cr, uid, move_lines[0])
204     assert (move_line.amount_residual_currency == 55.56 and move_line.amount_residual == 20) , "Residual amount is not correct for first Invoice. Got %s USD (%s EUR)" %(move_line.amount_residual_currency, move_line.amount_residual)
205 -
206   I check the residual amuont of Invoice2, should be 22.22 in residual currency and 10 in amount_residual
207 -
208    !python {model: account.invoice}: |
209     invoice_id = self.browse(cr, uid, ref("account_second_invoice_feb"))
210     move_line_obj = self.pool.get('account.move.line')
211     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)])
212     move_line = move_line_obj.browse(cr, uid, move_lines[0])
213     assert (move_line.amount_residual_currency == 22.22 and move_line.amount_residual == 10) , "Residual amount is not correct for second Invoice"
214 -
215   I create the second voucher of payment with values 80 USD, journal USD
216 -
217   !record {model: account.voucher, id: account_voucher_2_case2a, view: view_vendor_receipt_form}:
218     account_id: account.cash
219     amount: 80
220     company_id: base.main_company
221     journal_id: bank_journal_USD
222     partner_id: base.res_partner_19
223     period_id: account.period_3
224     date: !eval time.strftime("%Y-04-01")
225     payment_option: 'with_writeoff'
226     writeoff_acc_id: account.a_expense
227     comment: 'Write Off'
228     name: 'Second payment: Case 2 SUPPL USD/EUR DR EUR'
229
230 -
231   and I fully reconcile the 2 previous invoices
232 -
233   !python {model: account.voucher}: |
234     import time
235     from openerp import netsvc
236     vals = {}
237     voucher_id = self.browse(cr, uid, ref('account_voucher_2_case2a'))
238     data = []
239     for item in voucher_id.line_cr_ids:
240         if item.amount_unreconciled == 55.56:
241             data += [(item.id, 55.56)]
242         else:
243             data += [(item.id, 22.22)]
244     for line_id, amount in data:
245         self.pool.get('account.voucher.line').write(cr, uid, [line_id], {'amount': amount})
246     assert (voucher_id.state=='draft'), "Voucher is not in draft state"
247 -
248   I check that writeoff amount computed is 2.22
249 -
250   !python {model: account.voucher}: |
251     voucher = self.search(cr, uid, [('name', '=', 'Second payment: Case 2 SUPPL USD/EUR DR EUR'), ('partner_id', '=', ref('base.res_partner_19'))])
252     voucher_id = self.browse(cr, uid, voucher[0])
253     assert (round(voucher_id.writeoff_amount, 2) == 2.22), "Writeoff amount is not 2.22$"
254 -
255   I confirm the voucher
256 -
257   !python {model: account.voucher}: |
258     from openerp import netsvc
259     voucher = self.search(cr, uid, [('name', '=', 'Second payment: Case 2 SUPPL USD/EUR DR EUR'), ('partner_id', '=', ref('base.res_partner_19'))])
260     self.signal_proforma_voucher(cr, uid, voucher)
261 -
262   I check that my voucher state is posted
263 -
264   !python {model: account.voucher}: |
265     voucher = self.search(cr, uid, [('name', '=', 'Second payment: Case 2 SUPPL USD/EUR DR EUR'), ('partner_id', '=', ref('base.res_partner_19'))])
266     voucher_id = self.browse(cr, uid, voucher[0])
267     assert voucher_id.state == 'posted', "Voucher state is not posted"
268 -
269   I check that my debtor account is correct
270 -
271   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($).
272 -
273   I check that my currency rate difference is correct.
274 -
275   I check that my writeoff is correct. 2.11 in credit and 2.22 in amount_currency
276 -
277   !python {model: account.voucher}: |
278     voucher = self.search(cr, uid, [('name', '=', 'Second payment: Case 2 SUPPL USD/EUR DR EUR'), ('partner_id', '=', ref('base.res_partner_19'))])
279     voucher_id = self.browse(cr, uid, voucher[0])
280     move_line_obj = self.pool.get('account.move.line')
281     move_lines = move_line_obj.search(cr, uid, [('move_id', '=', voucher_id.move_id.id)])
282     reconcile_a = reconcile_b = False
283     for move_line in move_line_obj.browse(cr, uid, move_lines):
284         if move_line.amount_currency == -22.22:
285             assert move_line.reconcile_id.id, "The invoice of 200$ is not fully reconciled"
286             reconcile_b = move_line.reconcile_id.id
287         elif move_line.amount_currency == -55.56:
288             assert move_line.reconcile_id.id, "The invoice of 100$ is not fully reconciled"
289             reconcile_a = move_line.reconcile_id.id
290     for move_line in move_line_obj.browse(cr, uid, move_lines):
291         if move_line.amount_currency == -55.56:
292             assert move_line.credit == 52.78, "Debtor account has wrong entry."
293         elif move_line.amount_currency == -22.22:
294             assert move_line.credit == 21.11, "Debtor account has wrong entry."
295         elif move_line.credit == 11.11 and move_line.account_id.reconcile:
296             assert move_line.amount_currency == 0.00 and move_line.reconcile_id.id == reconcile_b, "Incorrect Currency Difference."
297         elif move_line.credit == 32.78 and move_line.account_id.reconcile:
298             assert move_line.amount_currency == 0.00 and move_line.reconcile_id.id == reconcile_a, "Incorrect Currency Difference."
299         elif move_line.amount_currency == 2.22:
300             assert move_line.credit == 2.11, "Writeoff amount is wrong."
301 -
302   I check the residual amount of invoice 1, should be 0 in residual currency and 0 in amount_residual and paid
303 -
304   !python {model: account.invoice}: |
305     invoice_id = self.browse(cr, uid, ref("account_first_invoice_jan"))
306     move_line_obj = self.pool.get('account.move.line')
307     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)])
308     move_line = move_line_obj.browse(cr, uid, move_lines[0])
309     assert (move_line.amount_residual_currency == 0.0 and move_line.amount_residual == 0.0 and invoice_id.state == 'paid') , "Residual amount is not correct for first Invoice"
310 -    
311   I check the residual amuont of invoice 2, should be 0 in residual currency and 0 in amount_residual and paid
312 -
313    !python {model: account.invoice}: |
314     invoice_id = self.browse(cr, uid, ref("account_second_invoice_feb"))
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 (move_line.amount_residual_currency == 0.0 and move_line.amount_residual == 0.0 and invoice_id.state == 'paid') , "Residual amount is not correct for second Invoice"