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
5 I set the income and expense currency accounts on the main company
7 !python {model: res.company}: |
8 from datetime import datetime
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)
14 I create a bank journal with EUR as currency
16 !record {model: account.journal, id: bank_journal_EUR}:
17 name: Bank Journal(EUR)
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
25 company_id: base.main_company
27 I create a bank journal with USD as currency
29 !record {model: account.journal, id: bank_journal_USD}:
30 name: Bank Journal(USD)
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
38 company_id: base.main_company
40 I create the first invoice on 1st January for 200 USD
42 !record {model: account.invoice, id: account_first_invoice_jan_suppl}:
43 account_id: account.a_pay
45 company_id: base.main_company
47 date_invoice: !eval "'%s-01-01' %(datetime.now().year)"
48 period_id: account.period_1
50 - account_id: account.a_expense
51 name: '[PCSC234] PC Assemble SC234'
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
61 I Validate invoice by clicking on Validate button
63 !workflow {model: account.invoice, action: invoice_open, ref: account_first_invoice_jan_suppl}
65 I check that first invoice move is correct for debtor account(debit - credit == -150)
67 !python {model: account.invoice}: |
68 from openerp.tools import float_compare
69 invoice_id = self.browse(cr, uid, ref("account_first_invoice_jan_suppl"))
70 assert invoice_id.move_id, "Move not created for open invoice"
71 move_line_obj = self.pool.get('account.move.line')
72 move_lines = move_line_obj.search(cr, uid, [('move_id', '=', invoice_id.move_id.id), ('account_id', '=', invoice_id.account_id.id)])
73 move_line = move_line_obj.browse(cr, uid, move_lines[0])
74 assert (float_compare(move_line.debit - move_line.credit, -150.00, precision_digits=2) == 0), "Invoice move is incorrect for debtors account"
76 I create the second invoice on 1st February for 100 USD
78 !record {model: account.invoice, id: account_second_invoice_feb_suppl}:
79 account_id: account.a_pay
80 company_id: base.main_company
82 date_invoice: !eval "'%s-02-01' %(datetime.now().year)"
83 period_id: account.period_2
86 - account_id: account.a_expense
87 name: '[PCSC234] PC Assemble SC234'
90 product_id: product.product_product_3
91 uos_id: product.product_uom_unit
92 journal_id: account.sales_journal
93 partner_id: base.res_partner_19
97 I Validate invoice by clicking on Validate button
99 !workflow {model: account.invoice, action: invoice_open, ref: account_second_invoice_feb_suppl}
101 I check that second invoice move is correct for debtor account (debit - credit == -80)
103 !python {model: account.invoice}: |
104 from openerp.tools import float_compare
105 invoice_id = self.browse(cr, uid, ref("account_second_invoice_feb_suppl"))
106 assert invoice_id.move_id, "Move not created for open invoice"
107 move_line_obj = self.pool.get('account.move.line')
108 move_lines = move_line_obj.search(cr, uid, [('move_id', '=', invoice_id.move_id.id), ('account_id', '=', invoice_id.account_id.id)])
109 move_line = move_line_obj.browse(cr, uid, move_lines[0])
110 assert (float_compare(move_line.debit - move_line.credit, -80, precision_digits=2) == 0), "Invoice move is incorrect for debtors account"
112 I set the context that will be used for the encoding of all the vouchers of this file
117 I create the first voucher of payment with values 240 EUR, journal EUR
119 !record {model: account.voucher, id: account_voucher_1_case2_suppl, view: view_vendor_payment_form}:
120 account_id: account.cash
122 company_id: base.main_company
123 journal_id: bank_journal_EUR
124 name: 'First payment: Case 2 SUPPL USD/EUR',
125 partner_id: base.res_partner_19
126 period_id: account.period_3
127 date: !eval time.strftime("%Y-03-01")
128 payment_option: 'with_writeoff'
129 writeoff_acc_id: account.a_expense
133 I fill amounts 180 for the invoice of 200$ and 70 for the invoice of 100$
135 !python {model: account.voucher}: |
136 from openerp.tools import float_compare
138 voucher_id = self.browse(cr, uid, ref('account_voucher_1_case2_suppl'))
140 for item in voucher_id.line_cr_ids:
141 if float_compare(item.amount_unreconciled, 200.00, precision_digits=2) == 0:
142 data += [(item.id, 180.0)]
144 data += [(item.id, 70.0)]
145 for line_id, amount in data:
146 self.pool.get('account.voucher.line').write(cr, uid, [line_id], {'amount': amount})
147 assert (voucher_id.state=='draft'), "Voucher is not in draft state"
149 I check that writeoff amount computed is -15.0
151 !python {model: account.voucher}: |
152 from openerp.tools import float_compare
153 voucher = self.search(cr, uid, [('name', '=', 'First payment: Case 2 SUPPL USD/EUR'), ('partner_id', '=', ref('base.res_partner_19'))])
154 voucher_id = self.browse(cr, uid, voucher[0])
155 assert (float_compare(voucher_id.writeoff_amount, -15.0, precision_digits=2) == 0), "Writeoff amount is not -15.0"
157 I check that currency rate difference is 34.0
159 !python {model: account.voucher}: |
160 from openerp.tools import float_compare
161 voucher = self.search(cr, uid, [('name', '=', 'First payment: Case 2 SUPPL USD/EUR'), ('partner_id', '=', ref('base.res_partner_19'))])
162 voucher_id = self.browse(cr, uid, voucher[0])
163 assert (float_compare(voucher_id.currency_rate_difference, 34.0, precision_digits=2) == 0), "Currency rate difference is not 34.0"
165 I confirm the voucher
167 !python {model: account.voucher}: |
168 voucher = self.search(cr, uid, [('name', '=', 'First payment: Case 2 SUPPL USD/EUR'), ('partner_id', '=', ref('base.res_partner_19'))])
169 self.signal_workflow(cr, uid, voucher, 'proforma_voucher')
171 I check that the move of my voucher is valid
173 !python {model: account.voucher}: |
174 voucher = self.search(cr, uid, [('name', '=', 'First payment: Case 2 SUPPL USD/EUR'), ('partner_id', '=', ref('base.res_partner_19'))])
175 voucher_id = self.browse(cr, uid, voucher[0])
176 move_line_obj = self.pool.get('account.move.line')
177 move_lines = move_line_obj.search(cr, uid, [('move_id', '=', voucher_id.move_id.id)])
178 for move_line in move_line_obj.browse(cr, uid, move_lines):
179 assert move_line.state == 'valid', "Voucher move is not valid"
181 I check that my creditor account is correct
183 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($).
185 I check that my currency rate difference is correct. -34 in credit with no amount_currency
187 I check that my writeoff is correct. -15 in credit with no amount_currency
189 !python {model: account.voucher}: |
190 from openerp.tools import float_compare
191 voucher = self.search(cr, uid, [('name', '=', 'First payment: Case 2 SUPPL USD/EUR'), ('partner_id', '=', ref('base.res_partner_19'))])
192 voucher_id = self.browse(cr, uid, voucher[0])
193 move_line_obj = self.pool.get('account.move.line')
194 move_lines = move_line_obj.search(cr, uid, [('move_id', '=', voucher_id.move_id.id)])
195 for move_line in move_line_obj.browse(cr, uid, move_lines):
196 if float_compare(move_line.amount_currency, 180.00, precision_digits=2) == 0:
197 assert float_compare(move_line.debit, 135.00, precision_digits=2) == 0, "Creditor account has wrong entry."
198 elif float_compare(move_line.amount_currency, 70.00, precision_digits=2) == 0:
199 assert float_compare(move_line.debit, 56.00, precision_digits=2) == 0, "Debtor account has wrong entry."
200 elif float_compare(move_line.debit, 34.00, precision_digits=2) == 0:
201 assert float_compare(move_line.amount_currency, 0.00, precision_digits=2) == 0, "Incorrect Currency Difference."
202 elif float_compare(move_line.debit, 15.00, precision_digits=2) == 0:
203 assert float_compare(move_line.amount_currency, 0.00, precision_digits=2) == 0, "Writeoff amount is wrong."
205 I check the residual amount of Invoice1, should be 20 in residual currency and 15 in amount_residual
207 !python {model: account.invoice}: |
208 from openerp.tools import float_compare
209 invoice_id = self.browse(cr, uid, ref("account_first_invoice_jan_suppl"))
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 (float_compare(move_line.amount_residual_currency, 20.0, precision_digits=2) == 0 and float_compare(move_line.amount_residual, 15, precision_digits=2) == 0) , "Residual amount is not correct for first Invoice"
215 I check the residual amuont of Invoice2, should be 30 in residual currency and 24 in amount_residual
217 !python {model: account.invoice}: |
218 from openerp.tools import float_compare
219 invoice_id = self.browse(cr, uid, ref("account_second_invoice_feb_suppl"))
220 move_line_obj = self.pool.get('account.move.line')
221 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)])
222 move_line = move_line_obj.browse(cr, uid, move_lines[0])
223 assert (float_compare(move_line.amount_residual_currency, 30, precision_digits=2) == 0 and float_compare(move_line.amount_residual, 24, precision_digits=2) == 0) , "Residual amount is not correct for second Invoice"
225 I create the second voucher of payment with values 45 USD, journal USD,
227 !record {model: account.voucher, id: account_voucher_2_case2_suppl, view: view_vendor_payment_form}:
228 account_id: account.cash
230 company_id: base.main_company
231 journal_id: bank_journal_USD
232 partner_id: base.res_partner_19
233 period_id: account.period_3
234 date: !eval time.strftime("%Y-04-01")
235 payment_option: 'with_writeoff'
236 writeoff_acc_id: account.a_expense
238 name: 'Second payment: Case 2 SUPPL USD/EUR'
241 I fill amounts 20 for the invoice of 200$ and 30 for the invoice of 100$>
243 !python {model: account.voucher}: |
244 from openerp.tools import float_compare
246 voucher_id = self.browse(cr, uid, ref('account_voucher_2_case2_suppl'))
248 for item in voucher_id.line_cr_ids:
249 if float_compare(item.amount_unreconciled, 20.00, precision_digits=2) == 0:
250 data += [(item.id, 20.0)]
252 data += [(item.id, 30.0)]
253 for line_id, amount in data:
254 self.pool.get('account.voucher.line').write(cr, uid, [line_id], {'amount': amount})
255 assert (voucher_id.state=='draft'), "Voucher is not in draft state"
257 I check that writeoff amount computed is -5.0
259 !python {model: account.voucher}: |
260 from openerp.tools import float_compare
261 voucher = self.search(cr, uid, [('name', '=', 'Second payment: Case 2 SUPPL USD/EUR'), ('partner_id', '=', ref('base.res_partner_19'))])
262 voucher_id = self.browse(cr, uid, voucher[0])
263 assert (float_compare(voucher_id.writeoff_amount, 5.0, precision_digits=2) == 0), "Writeoff amount is not 5.0"
265 I check that currency rate difference is 8.50
267 !python {model: account.voucher}: |
268 from openerp.tools import float_compare
269 voucher = self.search(cr, uid, [('name', '=', 'Second payment: Case 2 SUPPL USD/EUR'), ('partner_id', '=', ref('base.res_partner_19'))])
270 voucher_id = self.browse(cr, uid, voucher[0])
271 assert (float_compare(voucher_id.currency_rate_difference, 8.50, precision_digits=2) == 0), "Currency rate difference is not 8.50"
273 I confirm the voucher
275 !python {model: account.voucher}: |
276 voucher = self.search(cr, uid, [('name', '=', 'Second payment: Case 2 SUPPL USD/EUR'), ('partner_id', '=', ref('base.res_partner_19'))])
277 self.signal_workflow(cr, uid, voucher, 'proforma_voucher')
279 I check that my voucher state is posted
281 !python {model: account.voucher}: |
282 voucher = self.search(cr, uid, [('name', '=', 'Second payment: Case 2 SUPPL USD/EUR'), ('partner_id', '=', ref('base.res_partner_19'))])
283 voucher_id = self.browse(cr, uid, voucher[0])
284 assert voucher_id.state == 'posted', "Voucher state is not posted"
286 I check that my creditor account is correct
288 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($).
290 I check that my currency rate difference is correct. 8.50 in debit with no amount_currency
292 I check that my writeoff is correct. 4.75 in credit and 5 in amount_currency
294 !python {model: account.voucher}: |
295 from openerp.tools import float_compare
296 voucher = self.search(cr, uid, [('name', '=', 'Second payment: Case 2 SUPPL USD/EUR'), ('partner_id', '=', ref('base.res_partner_19'))])
297 voucher_id = self.browse(cr, uid, voucher[0])
298 move_line_obj = self.pool.get('account.move.line')
299 move_lines = move_line_obj.search(cr, uid, [('move_id', '=', voucher_id.move_id.id)])
300 for move_line in move_line_obj.browse(cr, uid, move_lines):
301 if float_compare(move_line.amount_currency, 20.00, precision_digits=2) == 0:
302 assert float_compare(move_line.debit, 15.00, precision_digits=2) == 0, "Debtor account has wrong entry."
303 elif float_compare(move_line.amount_currency, 30.00, precision_digits=2) == 0:
304 assert float_compare(move_line.debit, 24.00, precision_digits=2) == 0, "Debtor account has wrong entry."
305 elif float_compare(move_line.debit, 8.50, precision_digits=2) == 0:
306 assert float_compare(move_line.amount_currency, 0.00, precision_digits=2) == 0, "Incorrect Currency Difference."
307 elif float_compare(move_line.amount_currency, -5.00, precision_digits=2) == 0:
308 assert float_compare(move_line.credit, 4.75, precision_digits=2) == 0, "Writeoff amount is wrong."
310 I check the residual amount of invoice 1, should be 0 in residual currency and 0 in amount_residual and paid
312 !python {model: account.invoice}: |
313 from openerp.tools import float_compare
314 invoice_id = self.browse(cr, uid, ref("account_first_invoice_jan_suppl"))
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"
320 I check the residual amount of invoice 2, should be 0 in residual currency and 0 in amount_residual and paid
322 !python {model: account.invoice}: |
323 from openerp.tools import float_compare
324 invoice_id = self.browse(cr, uid, ref("account_second_invoice_feb_suppl"))
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"