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