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 modify the debtor account in order to set the currency_id = USD
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': ref('base.USD')})
21 I create currency USD in OpenERP for January of 1.333333 Rate
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})
30 I create currency USD in OpenERP for February of 1.250000 Rate
32 !record {model: res.currency.rate, id: feb_usd}:
34 name: !eval "'%s-02-01' %(datetime.now().year)"
37 I create currency USD in OpenERP for March of 1.111111 Rate
39 !record {model: res.currency.rate, id: mar_usd}:
41 name: !eval "'%s-03-01' %(datetime.now().year)"
44 I create currency USD in OpenERP for April of 1.052632 Rate
46 !record {model: res.currency.rate, id: apr_usd}:
48 name: !eval "'%s-04-01' %(datetime.now().year)"
51 I create a bank journal with EUR as currency
53 !record {model: account.journal, id: bank_journal_EUR}:
54 name: Bank Journal(EUR)
57 analytic_journal_id: analytic.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
63 I create a bank journal with USD as currency
65 !record {model: account.journal, id: bank_journal_USD}:
66 name: Bank Journal(USD)
69 analytic_journal_id: analytic.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
74 company_id: base.main_company
76 I create the first invoice on 1st January for 200 USD
78 !record {model: account.invoice, id: account_first_invoice_jan_michal}:
79 account_id: account.a_recv
80 company_id: base.main_company
82 date_invoice: !eval "'%s-01-01' %(datetime.now().year)"
83 period_id: account.period_1
85 - account_id: account.a_sale
86 name: '[PCSC234] PC Assemble SC234'
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
95 I Validate invoice by clicking on Validate button
97 !workflow {model: account.invoice, action: invoice_open, ref: account_first_invoice_jan_michal}
99 I check that first invoice move is correct for debtor account(debit - credit == 150)
101 !python {model: account.invoice}: |
102 from openerp.tools import float_compare
103 invoice_id = self.browse(cr, uid, ref("account_first_invoice_jan_michal"))
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 (float_compare(move_line.debit - move_line.credit, 150.00, precision_digits=2) == 0), "Invoice move is incorrect for debtors account"
110 I create the second invoice on 1st February for 100 USD
112 !record {model: account.invoice, id: account_second_invoice_feb_michal}:
113 account_id: account.a_recv
114 company_id: base.main_company
115 currency_id: base.USD
116 date_invoice: !eval "'%s-02-01' %(datetime.now().year)"
117 period_id: account.period_2
119 - account_id: account.a_sale
120 name: '[PCSC234] PC Assemble SC234'
123 product_id: product.product_product_3
124 uos_id: product.product_uom_unit
125 journal_id: account.sales_journal
126 partner_id: base.res_partner_19
129 I Validate invoice by clicking on Validate button
131 !workflow {model: account.invoice, action: invoice_open, ref: account_second_invoice_feb_michal}
133 I check that second invoice move is correct for debtor account (debit - credit == 80)
135 !python {model: account.invoice}: |
136 from openerp.tools import float_compare
137 invoice_id = self.browse(cr, uid, ref("account_second_invoice_feb_michal"))
138 assert invoice_id.move_id, "Move not created for open invoice"
139 move_line_obj = self.pool.get('account.move.line')
140 move_lines = move_line_obj.search(cr, uid, [('move_id', '=', invoice_id.move_id.id), ('account_id', '=', invoice_id.account_id.id)])
141 move_line = move_line_obj.browse(cr, uid, move_lines[0])
142 assert (float_compare(move_line.debit - move_line.credit, 80, precision_digits=2) == 0), "Invoice move is incorrect for debtors account"
144 I set the context that will be used for the encoding of all the vouchers of this file
149 I create the first voucher of payment with values 200 EUR, journal EUR
151 !record {model: account.voucher, id: account_voucher_1_case2b, view: view_vendor_receipt_form}:
152 account_id: account.cash
154 company_id: base.main_company
155 journal_id: bank_journal_EUR
156 partner_id: base.res_partner_19
157 period_id: account.period_3
158 date: !eval time.strftime("%Y-03-01")
159 payment_option: 'with_writeoff'
160 writeoff_acc_id: account.a_expense
162 name: 'First payment: Case 2 USD/EUR DR USD'
165 I fill amounts 130 for the invoice of 200$ and 70 for the invoice of 100$>
167 !python {model: account.voucher}: |
168 from openerp.tools import float_compare
170 voucher_id = self.browse(cr, uid, ref('account_voucher_1_case2b'))
172 for item in voucher_id.line_cr_ids:
173 if float_compare(item.amount_unreconciled, 150.00, precision_digits=2) == 0:
174 data += [(item.id, 130.0)]
176 data += [(item.id, 70.0)]
177 for line_id, amount in data:
178 self.pool.get('account.voucher.line').write(cr, uid, [line_id], {'amount': amount})
179 assert (voucher_id.state=='draft'), "Voucher is not in draft state"
181 I confirm the voucher
183 !python {model: account.voucher}: |
184 voucher = self.search(cr, uid, [('name', '=', 'First payment: Case 2 USD/EUR DR USD'), ('partner_id', '=', ref('base.res_partner_19'))])
185 self.signal_workflow(cr, uid, voucher, 'proforma_voucher')
187 I check that the move of my voucher is valid
189 !python {model: account.voucher}: |
190 voucher = self.search(cr, uid, [('name', '=', 'First payment: Case 2 USD/EUR DR 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"
197 I check that my debtor account is correct
199 I check that the debtor account has 2 new lines with 144.44 and 77.78 in amount_currency columns and their credit columns are 130 and 70
201 !python {model: account.voucher}: |
202 from openerp.tools import float_compare
203 voucher = self.search(cr, uid, [('name', '=', 'First payment: Case 2 USD/EUR DR USD'), ('partner_id', '=', ref('base.res_partner_19'))])
204 voucher_id = self.browse(cr, uid, voucher[0])
205 move_line_obj = self.pool.get('account.move.line')
206 move_lines = move_line_obj.search(cr, uid, [('move_id', '=', voucher_id.move_id.id)])
207 for move_line in move_line_obj.browse(cr, uid, move_lines):
208 if float_compare(move_line.credit, 70.0, precision_digits=2) == 0:
209 assert float_compare(move_line.amount_currency, -77.78, precision_digits=2) == 0, "Wrong debtor entry"
210 if float_compare(move_line.credit, 130.0, precision_digits=2) == 0:
211 assert float_compare(move_line.amount_currency, -144.44, precision_digits=2) == 0, "Wrong debtor entry"
213 I check the residual amount of Invoice1, should be 55.56 in residual currency and 20 in amount_residual
215 !python {model: account.invoice}: |
216 from openerp.tools import float_compare
217 invoice_id = self.browse(cr, uid, ref("account_first_invoice_jan_michal"))
218 move_line_obj = self.pool.get('account.move.line')
219 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)])
220 move_line = move_line_obj.browse(cr, uid, move_lines[0])
221 assert (float_compare(move_line.amount_residual_currency, 55.56, precision_digits=2) == 0 and float_compare(move_line.amount_residual, 20, precision_digits=2) == 0) , "Residual amount is not correct for first Invoice"
223 I check the residual amount of Invoice2, should be 22.22 in residual currency and 10 in amount_residual
225 !python {model: account.invoice}: |
226 from openerp.tools import float_compare
227 invoice_id = self.browse(cr, uid, ref("account_second_invoice_feb_michal"))
228 move_line_obj = self.pool.get('account.move.line')
229 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)])
230 move_line = move_line_obj.browse(cr, uid, move_lines[0])
231 assert (float_compare(move_line.amount_residual_currency, 22.22, precision_digits=2) == 0 and float_compare(move_line.amount_residual, 10, precision_digits=2) == 0) , "Residual amount is not correct for second Invoice"
233 I create the second voucher of payment with values 80 USD, journal USD
235 !record {model: account.voucher, id: account_voucher_2_case2b, view: view_vendor_receipt_form}:
236 account_id: account.cash
238 company_id: base.main_company
239 journal_id: bank_journal_USD
240 partner_id: base.res_partner_19
241 period_id: account.period_3
242 date: !eval time.strftime("%Y-04-01")
243 payment_option: 'with_writeoff'
244 writeoff_acc_id: account.a_expense
246 name: 'Second payment: Case 2 SUPPL USD/EUR DR USD'
249 and I fully reconcil the 2 previous invoices
251 !python {model: account.voucher}: |
252 from openerp.tools import float_compare
254 voucher_id = self.browse(cr, uid, ref('account_voucher_2_case2b'))
256 for item in voucher_id.line_cr_ids:
257 if float_compare(item.amount_unreconciled, 55.56, precision_digits=2) == 0:
258 data += [(item.id, 55.56)]
260 data += [(item.id, 22.22)]
261 for line_id, amount in data:
262 self.pool.get('account.voucher.line').write(cr, uid, [line_id], {'amount': amount})
263 assert (voucher_id.state=='draft'), "Voucher is not in draft state"
265 I check that writeoff amount computed is 2.22
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 DR USD'), ('partner_id', '=', ref('base.res_partner_19'))])
270 voucher_id = self.browse(cr, uid, voucher[0])
271 assert (float_compare(round(voucher_id.writeoff_amount, 2), 2.22, precision_digits=2) == 0), "Writeoff amount is not 2.22$"
273 I confirm the voucher
275 !python {model: account.voucher}: |
276 voucher = self.search(cr, uid, [('name', '=', 'Second payment: Case 2 SUPPL USD/EUR DR USD'), ('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 DR USD'), ('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 debtor account is correct
288 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($).
290 I check that my currency rate difference is correct.
292 I check that my writeoff is correct. 2.11 in credit and 2.22 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 DR USD'), ('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 reconcile_a = reconcile_b = False
301 for move_line in move_line_obj.browse(cr, uid, move_lines):
302 if float_compare(move_line.amount_currency, -22.22, precision_digits=2) == 0:
303 assert move_line.reconcile_id.id, "The invoice of 200$ is not fully reconciled"
304 reconcile_b = move_line.reconcile_id.id
305 elif float_compare(move_line.amount_currency, -55.56, precision_digits=2) == 0:
306 assert move_line.reconcile_id.id, "The invoice of 100$ is not fully reconciled"
307 reconcile_a = move_line.reconcile_id.id
308 for move_line in move_line_obj.browse(cr, uid, move_lines):
309 if float_compare(move_line.amount_currency, -55.56, precision_digits=2) == 0:
310 assert float_compare(move_line.credit, 52.78, precision_digits=2) == 0, "Debtor account has wrong entry."
311 elif float_compare(move_line.amount_currency, -22.22, precision_digits=2) == 0:
312 assert float_compare(move_line.credit, 21.11, precision_digits=2) == 0, "Debtor account has wrong entry."
313 elif float_compare(move_line.credit, 11.11, precision_digits=2) == 0 and move_line.account_id.reconcile:
314 assert float_compare(move_line.amount_currency, 0.00, precision_digits=2) == 0 and move_line.reconcile_id.id == reconcile_b, "Incorrect Currency Difference."
315 elif float_compare(move_line.credit, 32.78, precision_digits=2) == 0 and move_line.account_id.reconcile:
316 assert float_compare(move_line.amount_currency, 0.00, precision_digits=2) == 0 and move_line.reconcile_id.id == reconcile_a, "Incorrect Currency Difference."
317 elif float_compare(move_line.amount_currency, 2.22, precision_digits=2) == 0:
318 assert float_compare(move_line.credit, 2.11, precision_digits=2) == 0, "Writeoff amount is wrong."
320 I check the residual amount of invoice 1, 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_first_invoice_jan_michal"))
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 first Invoice"
330 I check the residual amount of invoice 2, should be 0 in residual currency and 0 in amount_residual and paid
332 !python {model: account.invoice}: |
333 from openerp.tools import float_compare
334 invoice_id = self.browse(cr, uid, ref("account_second_invoice_feb_michal"))
335 move_line_obj = self.pool.get('account.move.line')
336 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)])
337 move_line = move_line_obj.browse(cr, uid, move_lines[0])
338 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"