[FIX] /web/login restore request.uid in case of authentication failure
[odoo/odoo.git] / addons / account_voucher / test / case2_suppl_usd_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 create a bank journal with EUR as currency
15 -
16   !record {model: account.journal, id: bank_journal_EUR}:
17     name: Bank Journal(EUR)
18     code: BEUR
19     type: bank
20     analytic_journal_id: account.sit
21     sequence_id: account.sequence_bank_journal
22     default_debit_account_id: account.cash
23     default_credit_account_id: account.cash
24     currency: base.EUR
25     company_id: base.main_company
26 -
27   I create a bank journal with USD as currency
28 -
29   !record {model: account.journal, id: bank_journal_USD}:
30     name: Bank Journal(USD)
31     code: BUSD
32     type: bank
33     analytic_journal_id: account.sit
34     sequence_id: account.sequence_bank_journal
35     default_debit_account_id: account.cash
36     default_credit_account_id: account.cash
37     currency: base.USD
38     company_id: base.main_company
39 -
40   I create the first invoice on 1st January for 200 USD
41 -
42   !record {model: account.invoice, id: account_first_invoice_jan_suppl}:
43     account_id: account.a_pay
44     type : in_invoice
45     company_id: base.main_company
46     currency_id: base.USD
47     date_invoice: !eval "'%s-01-01' %(datetime.now().year)"
48     period_id: account.period_1
49     invoice_line:
50       - account_id: account.a_expense
51         name: '[PCSC234] PC Assemble SC234'
52         price_unit: 200.0
53         quantity: 1.0
54         product_id: product.product_product_3
55         uos_id: product.product_uom_unit
56     journal_id: account.sales_journal
57     partner_id: base.res_partner_19
58     reference_type: none
59     check_total : 200
60 -
61   I Validate invoice by clicking on Validate button
62 -
63   !workflow {model: account.invoice, action: invoice_open, ref: account_first_invoice_jan_suppl}
64 -
65   I check that first invoice move is correct for debtor account(debit - credit == -150)
66 -
67   !python {model: account.invoice}: |
68     invoice_id = self.browse(cr, uid, ref("account_first_invoice_jan_suppl"))
69     assert invoice_id.move_id, "Move not created for open invoice"
70     move_line_obj = self.pool.get('account.move.line')
71     move_lines = move_line_obj.search(cr, uid, [('move_id', '=', invoice_id.move_id.id), ('account_id', '=', invoice_id.account_id.id)])
72     move_line = move_line_obj.browse(cr, uid, move_lines[0])
73     assert (move_line.debit - move_line.credit == -150.00), "Invoice move is incorrect for debtors account"
74 -
75   I create the second invoice on 1st February for 100 USD
76 -
77   !record {model: account.invoice, id: account_second_invoice_feb_suppl}:
78     account_id: account.a_pay
79     company_id: base.main_company
80     currency_id: base.USD
81     date_invoice: !eval "'%s-02-01' %(datetime.now().year)"
82     period_id: account.period_2
83     type : in_invoice
84     invoice_line:
85       - account_id: account.a_expense
86         name: '[PCSC234] PC Assemble SC234'
87         price_unit: 100.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     check_total : 100.0
95 -
96   I Validate invoice by clicking on Validate button
97 -
98   !workflow {model: account.invoice, action: invoice_open, ref: account_second_invoice_feb_suppl}
99 -
100   I check that second invoice move is correct for debtor account (debit - credit == -80)
101 -
102   !python {model: account.invoice}: |
103     invoice_id = self.browse(cr, uid, ref("account_second_invoice_feb_suppl"))
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 (move_line.debit - move_line.credit == -80), "Invoice move is incorrect for debtors account"
109 -
110   I set the context that will be used for the encoding of all the vouchers of this file
111 -
112   !context
113     'type': 'payment'
114 -
115   I create the first voucher of payment with values 240 EUR, journal EUR
116 -
117   !record {model: account.voucher, id: account_voucher_1_case2_suppl, view: view_vendor_payment_form}:
118     account_id: account.cash
119     amount: 240.0
120     company_id: base.main_company
121     journal_id: bank_journal_EUR
122     name: 'First payment: Case 2 SUPPL USD/EUR',
123     partner_id: base.res_partner_19
124     period_id: account.period_3
125     date: !eval time.strftime("%Y-03-01")
126     payment_option: 'with_writeoff'
127     writeoff_acc_id: account.a_expense
128     comment: 'Write Off'
129
130 -
131   I fill amounts 180 for the invoice of 200$ and 70 for the invoice of 100$
132 -
133   !python {model: account.voucher}: |
134     vals = {}
135     voucher_id = self.browse(cr, uid, ref('account_voucher_1_case2_suppl'))
136     data = []
137     for item in voucher_id.line_cr_ids:
138         if item.amount_unreconciled == 200.00:
139             data += [(item.id, 180.0)]
140         else:
141             data += [(item.id, 70.0)]
142     for line_id, amount in data:
143         self.pool.get('account.voucher.line').write(cr, uid, [line_id], {'amount': amount})
144     assert (voucher_id.state=='draft'), "Voucher is not in draft state"
145 -
146   I check that writeoff amount computed is -15.0
147 -
148   !python {model: account.voucher}: |
149     voucher = self.search(cr, uid, [('name', '=', 'First payment: Case 2 SUPPL USD/EUR'), ('partner_id', '=', ref('base.res_partner_19'))])
150     voucher_id = self.browse(cr, uid, voucher[0])
151     assert (voucher_id.writeoff_amount == -15.0), "Writeoff amount is not -15.0"
152 -
153   I check that currency rate difference is 34.0
154 -
155   !python {model: account.voucher}: |
156     voucher = self.search(cr, uid, [('name', '=', 'First payment: Case 2 SUPPL USD/EUR'), ('partner_id', '=', ref('base.res_partner_19'))])
157     voucher_id = self.browse(cr, uid, voucher[0])
158     assert (voucher_id.currency_rate_difference == 34.0), "Currency rate difference is not 34.0"
159 -
160   I confirm the voucher
161 -
162   !python {model: account.voucher}: |
163     voucher = self.search(cr, uid, [('name', '=', 'First payment: Case 2 SUPPL USD/EUR'), ('partner_id', '=', ref('base.res_partner_19'))])
164     self.signal_proforma_voucher(cr, uid, voucher)
165 -
166   I check that the move of my voucher is valid
167 -
168   !python {model: account.voucher}: |
169     voucher = self.search(cr, uid, [('name', '=', 'First payment: Case 2 SUPPL USD/EUR'), ('partner_id', '=', ref('base.res_partner_19'))])
170     voucher_id = self.browse(cr, uid, voucher[0])
171     move_line_obj = self.pool.get('account.move.line')
172     move_lines = move_line_obj.search(cr, uid, [('move_id', '=', voucher_id.move_id.id)])
173     for move_line in move_line_obj.browse(cr, uid, move_lines):
174         assert move_line.state == 'valid', "Voucher move is not valid"
175 -
176   I check that my creditor account is correct
177 -
178   I check that the creditor account has 2 new lines with 180 and 70 in amount_currency columns and their debit columns are respectively 135 and 56 and currency is USD($).
179 -
180   I check that my currency rate difference is correct. -34 in credit with no amount_currency
181 -
182   I check that my writeoff is correct. -15 in credit with no amount_currency
183 -
184   !python {model: account.voucher}: |
185     voucher = self.search(cr, uid, [('name', '=', 'First payment: Case 2 SUPPL USD/EUR'), ('partner_id', '=', ref('base.res_partner_19'))])
186     voucher_id = self.browse(cr, uid, voucher[0])
187     move_line_obj = self.pool.get('account.move.line')
188     move_lines = move_line_obj.search(cr, uid, [('move_id', '=', voucher_id.move_id.id)])
189     for move_line in move_line_obj.browse(cr, uid, move_lines):
190         if move_line.amount_currency == 180.00:
191             assert move_line.debit == 135.00, "Creditor account has wrong entry."
192         elif move_line.amount_currency == 70.00:
193             assert move_line.debit == 56.00, "Debtor account has wrong entry."
194         elif move_line.debit == 34.00:
195             assert move_line.amount_currency == 0.00, "Incorrect Currency Difference."
196         elif move_line.debit == 15.00:
197             assert move_line.amount_currency == 0.00, "Writeoff amount is wrong."
198 -
199   I check the residual amount of Invoice1, should be 20 in residual currency and 15 in amount_residual
200 -
201   !python {model: account.invoice}: |
202     invoice_id = self.browse(cr, uid, ref("account_first_invoice_jan_suppl"))
203     move_line_obj = self.pool.get('account.move.line')
204     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)])
205     move_line = move_line_obj.browse(cr, uid, move_lines[0])
206     assert (move_line.amount_residual_currency == 20.0 and move_line.amount_residual == 15) , "Residual amount is not correct for first Invoice"
207 -
208   I check the residual amuont of Invoice2, should be 30 in residual currency and 24 in amount_residual
209 -
210    !python {model: account.invoice}: |
211     invoice_id = self.browse(cr, uid, ref("account_second_invoice_feb_suppl"))
212     move_line_obj = self.pool.get('account.move.line')
213     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)])
214     move_line = move_line_obj.browse(cr, uid, move_lines[0])
215     assert (move_line.amount_residual_currency == 30 and move_line.amount_residual == 24) , "Residual amount is not correct for second Invoice"
216 -
217   I create the second voucher of payment with values 45 USD, journal USD, 
218 -
219   !record {model: account.voucher, id: account_voucher_2_case2_suppl, view: view_vendor_payment_form}:
220     account_id: account.cash
221     amount: 45.0
222     company_id: base.main_company
223     journal_id: bank_journal_USD
224     partner_id: base.res_partner_19
225     period_id: account.period_3
226     date: !eval time.strftime("%Y-04-01")
227     payment_option: 'with_writeoff'
228     writeoff_acc_id: account.a_expense
229     comment: 'Write Off'
230     name: 'Second payment: Case 2 SUPPL USD/EUR'
231
232 -
233   I fill amounts 20 for the invoice of 200$ and 30 for the invoice of 100$>
234 -
235   !python {model: account.voucher}: |
236     vals = {}
237     voucher_id = self.browse(cr, uid, ref('account_voucher_2_case2_suppl'))
238     data = []
239     for item in voucher_id.line_cr_ids:
240         if item.amount_unreconciled == 20.00:
241             data += [(item.id, 20.0)]
242         else:
243             data += [(item.id, 30.0)]
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 -5.0
249 -
250   !python {model: account.voucher}: |
251     voucher = self.search(cr, uid, [('name', '=', 'Second payment: Case 2 SUPPL USD/EUR'), ('partner_id', '=', ref('base.res_partner_19'))])
252     voucher_id = self.browse(cr, uid, voucher[0])
253     assert (voucher_id.writeoff_amount == 5.0), "Writeoff amount is not 5.0"
254 -
255   I check that currency rate difference is 8.50
256 -
257   !python {model: account.voucher}: |
258     voucher = self.search(cr, uid, [('name', '=', 'Second payment: Case 2 SUPPL USD/EUR'), ('partner_id', '=', ref('base.res_partner_19'))])
259     voucher_id = self.browse(cr, uid, voucher[0])
260     assert (voucher_id.currency_rate_difference == 8.50), "Currency rate difference is not 8.50"
261 -
262   I confirm the voucher
263 -
264   !python {model: account.voucher}: |
265     voucher = self.search(cr, uid, [('name', '=', 'Second payment: Case 2 SUPPL USD/EUR'), ('partner_id', '=', ref('base.res_partner_19'))])
266     self.signal_proforma_voucher(cr, uid, voucher)
267 -
268   I check that my voucher state is posted
269 -
270   !python {model: account.voucher}: |
271     voucher = self.search(cr, uid, [('name', '=', 'Second payment: Case 2 SUPPL USD/EUR'), ('partner_id', '=', ref('base.res_partner_19'))])
272     voucher_id = self.browse(cr, uid, voucher[0])
273     assert voucher_id.state == 'posted', "Voucher state is not posted"
274 -
275   I check that my creditor account is correct
276 -
277   I check that the creditor account has 2 new lines with 20 and 30 in amount_currency columns and their debit columns are respectively 15 and 24 and currency is USD($).
278 -
279   I check that my currency rate difference is correct. 8.50 in debit with no amount_currency
280 -
281   I check that my writeoff is correct. 4.75 in credit and 5 in amount_currency
282 -
283   !python {model: account.voucher}: |
284     voucher = self.search(cr, uid, [('name', '=', 'Second payment: Case 2 SUPPL USD/EUR'), ('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         if move_line.amount_currency == 20.00:
290             assert move_line.debit == 15.00, "Debtor account has wrong entry."
291         elif move_line.amount_currency == 30.00:
292             assert move_line.debit == 24.00, "Debtor account has wrong entry."
293         elif move_line.debit == 8.50:
294             assert move_line.amount_currency == 0.00, "Incorrect Currency Difference."
295         elif move_line.amount_currency == -5.00:
296             assert move_line.credit == 4.75, "Writeoff amount is wrong."
297 -
298   I check the residual amount of invoice 1, should be 0 in residual currency and 0 in amount_residual and paid
299 -
300   !python {model: account.invoice}: |
301     invoice_id = self.browse(cr, uid, ref("account_first_invoice_jan_suppl"))
302     move_line_obj = self.pool.get('account.move.line')
303     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)])
304     move_line = move_line_obj.browse(cr, uid, move_lines[0])
305     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"
306 -    
307   I check the residual amount of invoice 2, should be 0 in residual currency and 0 in amount_residual and paid
308 -
309    !python {model: account.invoice}: |
310     invoice_id = self.browse(cr, uid, ref("account_second_invoice_feb_suppl"))
311     move_line_obj = self.pool.get('account.move.line')
312     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)])
313     move_line = move_line_obj.browse(cr, uid, move_lines[0])
314     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"