[FIX] /web/login restore request.uid in case of authentication failure
[odoo/odoo.git] / addons / account_voucher / test / case1_usd_usd.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 in USD 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 USD in OpenERP for January of 1.333333 Rate
15 -
16   !python {model: res.currency.rate}: |
17     from datetime import datetime
18     curr_id = self.pool.get('res.currency').search(cr, uid, [('name', '=', 'USD')])[0]
19     date = '%s-01-01' %(datetime.now().year)
20     ids = self.search(cr, uid, [('currency_id','=',curr_id), ('name', '=', date)])
21     self.write(cr, uid, ids, {'rate': 1.333333})
22 -
23   I create currency USD in OpenERP for February of 1.250000 Rate
24 -
25   !record {model: res.currency.rate, id: feb_usd}:
26     currency_id: base.USD
27     name: !eval "'%s-02-01' %(datetime.now().year)"
28     rate: 1.250000
29
30 -
31   I create currency USD in OpenERP for March of 1.111111 Rate
32 -
33   !record {model: res.currency.rate, id: mar_usd}:
34     currency_id: base.USD
35     name: !eval "'%s-03-01' %(datetime.now().year)"
36     rate: 1.111111
37
38 -
39   I create currency USD in OpenERP for April of 1.052632 Rate
40 -
41   !record {model: res.currency.rate, id: apr_usd}:
42     currency_id: base.USD
43     name: !eval "'%s-04-01' %(datetime.now().year)"
44     rate: 1.052632
45
46 -
47   I create a cash account with currency USD
48 -
49   !record {model: account.account, id: account_cash_usd_id}:
50     currency_id: base.USD
51     name: "cash account in usd"
52     code: "Xcash usd"
53     type: 'liquidity'
54     user_type: "account.data_account_type_cash"
55
56 -
57   I create a bank journal with USD as currency
58 -
59   !record {model: account.journal, id: bank_journal_USD}:
60     name: Bank Journal(USD)
61     code: BUSD
62     type: bank
63     analytic_journal_id: account.sit
64     sequence_id: account.sequence_bank_journal
65     default_debit_account_id: account_cash_usd_id
66     default_credit_account_id: account_cash_usd_id
67     currency: base.USD
68     company_id: base.main_company
69
70 -
71   I create the first invoice on 1st January  for 200 USD
72 -
73   !record {model: account.invoice, id: account_invoice_jan}:
74     account_id: account.a_recv
75     company_id: base.main_company
76     currency_id: base.USD
77     date_invoice: !eval "'%s-01-01' %(datetime.now().year)"
78     period_id: account.period_1
79     invoice_line:
80       - account_id: account.a_sale
81         name: '[PCSC234] PC Assemble SC234'
82         price_unit: 200.0
83         quantity: 1.0
84         product_id: product.product_product_3
85         uos_id: product.product_uom_unit
86     journal_id: account.sales_journal
87     partner_id: base.res_partner_19
88     reference_type: none
89 -
90   I Validate invoice by clicking on Validate button
91 -
92   !workflow {model: account.invoice, action: invoice_open, ref: account_invoice_jan}
93 -
94   I check that first invoice move is correct for debtor account (debit - credit == 150.0)
95 -
96   !python {model: account.invoice}: |
97     invoice_id = self.browse(cr, uid, ref("account_invoice_jan"))
98     assert invoice_id.move_id, "Move not created for open invoice"
99     move_line_obj = self.pool.get('account.move.line')
100     move_lines = move_line_obj.search(cr, uid, [('move_id', '=', invoice_id.move_id.id), ('account_id', '=', invoice_id.account_id.id)])
101     move_line = move_line_obj.browse(cr, uid, move_lines[0])
102     assert (move_line.debit - move_line.credit == 150.0), "Invoice move is not correct for debtors account"
103 -
104   I create the second invoice on 1st February for 100 USD
105 -
106   !record {model: account.invoice, id: account_invoice_feb}:
107     account_id: account.a_recv
108     company_id: base.main_company
109     currency_id: base.USD
110     date_invoice: !eval "'%s-02-01' %(datetime.now().year)"
111     period_id: account.period_2
112     invoice_line:
113       - account_id: account.a_sale
114         name: '[PCSC234] PC Assemble SC234'
115         price_unit: 100.0
116         quantity: 1.0
117         product_id: product.product_product_3
118         uos_id: product.product_uom_unit
119     journal_id: account.sales_journal
120     partner_id: base.res_partner_19
121     reference_type: none
122 -
123   I Validate invoice by clicking on Validate button
124 -
125   !workflow {model: account.invoice, action: invoice_open, ref: account_invoice_feb}
126 -
127   I check that second invoice move is correct for debtor account (debit - credit == 80)
128 -
129   !python {model: account.invoice}: |
130     invoice_id = self.browse(cr, uid, ref("account_invoice_feb"))
131     assert invoice_id.move_id, "Move not created for open invoice"
132     move_line_obj = self.pool.get('account.move.line')
133     move_lines = move_line_obj.search(cr, uid, [('move_id', '=', invoice_id.move_id.id), ('account_id', '=', invoice_id.account_id.id)])
134     move_line = move_line_obj.browse(cr, uid, move_lines[0])
135     assert (move_line.debit - move_line.credit == 80), "Invoice move is not correct for debtors account"
136
137 -
138   I set the context that will be used for the encoding of all the vouchers of this file
139 -
140   !context
141     'type': 'receipt'
142 -
143   On the first March, I create the first voucher of payment with values 240 USD, journal USD, 
144 -
145   !record {model: account.voucher, id: account_voucher_1_case1, view: view_vendor_receipt_form}:
146     account_id: account.cash
147     amount: 240.0
148     company_id: base.main_company
149     journal_id: bank_journal_USD
150     name: 'First payment: Case 1 USD/USD'
151     partner_id: base.res_partner_19
152     period_id: account.period_3
153     date: !eval time.strftime("%Y-03-01")
154     payment_option: 'with_writeoff'
155     writeoff_acc_id: account.a_expense
156     comment: 'Write Off'
157
158 -
159   I fill amounts 180 for the invoice of 200$ and 70 for the invoice of 100$>
160 -
161   !python {model: account.voucher}: |
162     vals = {}
163     voucher_id = self.browse(cr, uid, ref('account_voucher_1_case1'))
164     data = []
165     for item in voucher_id.line_cr_ids:
166         if item.amount_unreconciled == 200.00:
167             data += [(item.id, 180.0)]
168         else:
169             data += [(item.id, 70.0)]
170     for line_id, amount in data:
171         self.pool.get('account.voucher.line').write(cr, uid, [line_id], {'amount': amount})
172     assert (voucher_id.state=='draft'), "Voucher is not in draft state"
173 -
174   I check that writeoff amount computed is -10.0
175 -
176   !python {model: account.voucher}: |
177     voucher = self.search(cr, uid, [('name', '=', 'First payment: Case 1 USD/USD'), ('partner_id', '=', ref('base.res_partner_19'))])
178     voucher_id = self.browse(cr, uid, voucher[0])
179     assert (voucher_id.writeoff_amount == -10.0), "Writeoff amount is not -10.0"
180 -
181   I confirm the voucher
182 -
183   !python {model: account.voucher}: |
184     voucher = self.search(cr, uid, [('name', '=', 'First payment: Case 1 USD/USD'), ('partner_id', '=', ref('base.res_partner_19'))])
185     self.signal_proforma_voucher(cr, uid, voucher)
186 -
187   I check that the move of my first voucher is valid
188 -
189   !python {model: account.voucher}: |
190     voucher = self.search(cr, uid, [('name', '=', 'First payment: Case 1 USD/USD'), ('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 that my debtor account is correct
198 -
199   I check that the debtor account has 2 new lines with -180 and -70 as amount_currency columns and that their credit columns are respectively 162 and 63
200 -
201   I check that my write-off is correct. 9 debit and 10 amount_currency
202 -
203   !python {model: account.voucher}: |
204     voucher = self.search(cr, uid, [('name', '=', 'First payment: Case 1 USD/USD'), ('partner_id', '=', ref('base.res_partner_19'))])
205     voucher_id = self.browse(cr, uid, voucher[0])
206     move_line_obj = self.pool.get('account.move.line')
207     move_lines = move_line_obj.search(cr, uid, [('move_id', '=', voucher_id.move_id.id)])
208     for move_line in move_line_obj.browse(cr, uid, move_lines):
209         if move_line.amount_currency == -180.00:
210             assert move_line.credit == 162.00, "Debtor account has wrong entry."
211         elif move_line.amount_currency == -70.00:
212             assert move_line.credit == 63.00, "Debtor account has wrong entry."
213         elif move_line.amount_currency == 10.00:
214             assert move_line.debit == 9.00, "Writeoff amount is wrong."
215         elif move_line.amount_currency == 240.00:
216             assert move_line.debit == 216.00, "Bank entry is wrong."
217         else:
218             assert False, "Unrecognized journal entry"
219 -
220   I check the residual amount of Invoice1, should be 20 in amount_currency
221 -
222   !python {model: account.invoice}: |
223     invoice_id = self.browse(cr, uid, ref("account_invoice_jan"))
224     move_line_obj = self.pool.get('account.move.line')
225     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)])
226     move_line = move_line_obj.browse(cr, uid, move_lines[0])
227     assert (move_line.amount_residual_currency == 20.0) , "Residual amount is not correct for first Invoice"
228 -
229   I check the residual amuont of Invoice2, should be 30 in residual currency and 24 in amount_residual
230 -
231   !python {model: account.invoice}: |
232     invoice_id = self.browse(cr, uid, ref("account_invoice_feb"))
233     move_line_obj = self.pool.get('account.move.line')
234     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)])
235     move_line = move_line_obj.browse(cr, uid, move_lines[0])
236     assert (move_line.amount_residual_currency == 30.0) , "Residual amount is not correct for first Invoice"
237 -
238   On the first April, I create the second voucher of payment with values 45 USD, journal USD, 
239 -
240   !record {model: account.voucher, id: account_voucher_2_case1, view: view_vendor_receipt_form}:
241     account_id: account.cash
242     amount: 45.0
243     company_id: base.main_company
244     journal_id: bank_journal_USD
245     name: 'Second payment: Case 1'
246     partner_id: base.res_partner_19
247     period_id: account.period_3
248     date: !eval time.strftime("%Y-04-01")
249     payment_option: 'with_writeoff'
250     writeoff_acc_id: account.a_expense
251     comment: 'Write Off'
252 -
253   I fill amounts 20 for the invoice of 200$ and 30 for the invoice of 100$
254 -
255   !python {model: account.voucher}: |
256     vals = {}
257     voucher_id = self.browse(cr, uid, ref('account_voucher_2_case1'))
258     data = []
259     for item in voucher_id.line_cr_ids:
260         if item.amount_unreconciled == 20.00:
261             data += [(item.id, 20.0)]
262         else:
263             data += [(item.id, 30.0)]
264     for line_id, amount in data:
265         self.pool.get('account.voucher.line').write(cr, uid, [line_id], {'amount': amount})
266     assert (voucher_id.state=='draft'), "Voucher is not in draft state"
267 -
268   I check that writeoff amount computed is -5.0
269 -
270   !python {model: account.voucher}: |
271     voucher = self.search(cr, uid, [('name', '=', 'Second payment: Case 1'), ('partner_id', '=', ref('base.res_partner_19'))])
272     voucher_id = self.browse(cr, uid, voucher[0])
273     assert (voucher_id.writeoff_amount == -5.0), "Writeoff amount is not -5.0"
274 -
275   I confirm the voucher
276 -
277   !python {model: account.voucher}: |
278     voucher = self.search(cr, uid, [('name', '=', 'Second payment: Case 1'), ('partner_id', '=', ref('base.res_partner_19'))])
279     self.signal_proforma_voucher(cr, uid, voucher)
280 -
281   I check that the move of my second voucher is valid
282 -
283   !python {model: account.voucher}: |
284     voucher = self.search(cr, uid, [('name', '=', 'Second payment: Case 1'), ('partner_id', '=', ref('base.res_partner_19'))])
285     voucher_id = self.browse(cr, uid, voucher[0])
286     move_line_obj = self.pool.get('account.move.line')
287     move_lines = move_line_obj.search(cr, uid, [('move_id', '=', voucher_id.move_id.id)])
288     for move_line in move_line_obj.browse(cr, uid, move_lines):
289         assert move_line.state == 'valid', "Voucher move is not valid"
290 -
291   I check that my debtor account is correct
292 -
293   I check that the debtor account has 2 new lines with -20 and -30 as amount_currency columns and their credit columns are respectively 19 and 28.5
294 -
295   I check that my currency rate difference is correct. 8.5 in credit with no amount_currency
296 -
297   I  check that the total reconcilation created entries as expected
298 -
299   I check that my writeoff is correct. 4.75 debit and 5 amount_currency
300 -
301   !python {model: account.voucher}: |
302     voucher = self.search(cr, uid, [('name', '=', 'Second payment: Case 1'), ('partner_id', '=', ref('base.res_partner_19'))])
303     voucher_id = self.browse(cr, uid, voucher[0])
304     move_line_obj = self.pool.get('account.move.line')
305     move_lines = move_line_obj.search(cr, uid, [('move_id', '=', voucher_id.move_id.id)])
306     reconcile_a = reconcile_b = False
307     for move_line in move_line_obj.browse(cr, uid, move_lines):
308         if move_line.amount_currency == -20.00:
309             assert move_line.reconcile_id.id, "The invoice of 200$ is not fully reconciled"
310             reconcile_b = move_line.reconcile_id.id
311         elif move_line.amount_currency == -30.00:
312             assert move_line.reconcile_id.id, "The invoice of 100$ is not fully reconciled"
313             reconcile_a = move_line.reconcile_id.id
314     for move_line in move_line_obj.browse(cr, uid, move_lines):
315         if move_line.amount_currency == -20.00:
316             assert move_line.credit == 19.00, "Debtor account has wrong entry."
317         elif move_line.amount_currency == -30.00:
318             assert move_line.credit == 28.50, "Debtor account has wrong entry."
319         elif move_line.amount_currency == 5.00:
320             assert move_line.debit == 4.75, "Writeoff amount is wrong."
321         elif move_line.debit == 11.5 and move_line.account_id.reconcile:
322             assert move_line.amount_currency == 0.0 and move_line.reconcile_id.id == reconcile_a, "Exchange difference entry for the invoice of 100$ is wrong"
323         elif move_line.credit == 11.5:
324             assert move_line.amount_currency == 0.0
325         elif move_line.debit == 31.0 and move_line.account_id.reconcile:
326             assert move_line.amount_currency == 0.0 and move_line.reconcile_id.id == reconcile_b, "Exchange difference entry for the invoice of 200$ is wrong"
327         elif move_line.credit == 31.0:
328             assert move_line.amount_currency == 0.0
329         elif move_line.amount_currency == 45.00:
330             assert move_line.debit == 42.75, "Bank entry is wrong."
331         else:
332             assert False, "Unrecognized journal entry"
333 -
334   I check the residual amount of Invoice1, should be 0 in residual currency and 0 in amount_residual and paid
335 -
336   !python {model: account.invoice}: |
337     invoice_id = self.browse(cr, uid, ref("account_invoice_jan"))
338     move_line_obj = self.pool.get('account.move.line')
339     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)])
340     move_line = move_line_obj.browse(cr, uid, move_lines[0])
341     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"
342 -
343   I check the residual amuont of Invoice2, should be 0 in residual currency and 0 in amount_residual and paid
344 -
345   !python {model: account.invoice}: |
346     invoice_id = self.browse(cr, uid, ref("account_invoice_feb"))
347     move_line_obj = self.pool.get('account.move.line')
348     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)])
349     move_line = move_line_obj.browse(cr, uid, move_lines[0])
350     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"