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 make sure there is no currency_id linked
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': False})
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}:
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}
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"))
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}:
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}
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"))
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_case2a, 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 EUR'
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 from openerp import netsvc
172 voucher_id = self.browse(cr, uid, ref('account_voucher_1_case2a'))
174 for item in voucher_id.line_cr_ids:
175 if float_compare(item.amount_unreconciled, 150.00, precision_digits=2) == 0:
176 data += [(item.id, 130.0)]
178 data += [(item.id, 70.0)]
179 for line_id, amount in data:
180 self.pool.get('account.voucher.line').write(cr, uid, [line_id], {'amount': amount})
181 assert (voucher_id.state=='draft'), "Voucher is not in draft state"
183 I confirm the voucher
185 !python {model: account.voucher}: |
186 from openerp import netsvc
187 voucher = self.search(cr, uid, [('name', '=', 'First payment: Case 2 USD/EUR DR EUR'), ('partner_id', '=', ref('base.res_partner_19'))])
188 self.signal_workflow(cr, uid, voucher, 'proforma_voucher')
190 I check that the move of my voucher is valid
192 !python {model: account.voucher}: |
193 voucher = self.search(cr, uid, [('name', '=', 'First payment: Case 2 USD/EUR DR EUR'), ('partner_id', '=', ref('base.res_partner_19'))])
194 voucher_id = self.browse(cr, uid, voucher[0])
195 move_line_obj = self.pool.get('account.move.line')
196 move_lines = move_line_obj.search(cr, uid, [('move_id', '=', voucher_id.move_id.id)])
197 for move_line in move_line_obj.browse(cr, uid, move_lines):
198 assert move_line.state == 'valid', "Voucher move is not valid"
200 I check the residual amount of Invoice1, should be 55.56 in residual currency and 20 in amount_residual
202 !python {model: account.invoice}: |
203 from openerp.tools import float_compare
204 invoice_id = self.browse(cr, uid, ref("account_first_invoice_jan"))
205 move_line_obj = self.pool.get('account.move.line')
206 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)])
207 move_line = move_line_obj.browse(cr, uid, move_lines[0])
208 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. Got %s USD (%s EUR)" %(move_line.amount_residual_currency, move_line.amount_residual)
210 I check the residual amuont of Invoice2, should be 22.22 in residual currency and 10 in amount_residual
212 !python {model: account.invoice}: |
213 from openerp.tools import float_compare
214 invoice_id = self.browse(cr, uid, ref("account_second_invoice_feb"))
215 move_line_obj = self.pool.get('account.move.line')
216 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)])
217 move_line = move_line_obj.browse(cr, uid, move_lines[0])
218 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"
220 I create the second voucher of payment with values 80 USD, journal USD
222 !record {model: account.voucher, id: account_voucher_2_case2a, view: view_vendor_receipt_form}:
223 account_id: account.cash
225 company_id: base.main_company
226 journal_id: bank_journal_USD
227 partner_id: base.res_partner_19
228 period_id: account.period_3
229 date: !eval time.strftime("%Y-04-01")
230 payment_option: 'with_writeoff'
231 writeoff_acc_id: account.a_expense
233 name: 'Second payment: Case 2 SUPPL USD/EUR DR EUR'
236 and I fully reconcile the 2 previous invoices
238 !python {model: account.voucher}: |
240 from openerp import netsvc
241 from openerp.tools import float_compare
243 voucher_id = self.browse(cr, uid, ref('account_voucher_2_case2a'))
245 for item in voucher_id.line_cr_ids:
246 if float_compare(item.amount_unreconciled, 55.56, precision_digits=2) == 0:
247 data += [(item.id, 55.56)]
249 data += [(item.id, 22.22)]
250 for line_id, amount in data:
251 self.pool.get('account.voucher.line').write(cr, uid, [line_id], {'amount': amount})
252 assert (voucher_id.state=='draft'), "Voucher is not in draft state"
254 I check that writeoff amount computed is 2.22
256 !python {model: account.voucher}: |
257 from openerp.tools import float_compare
258 voucher = self.search(cr, uid, [('name', '=', 'Second payment: Case 2 SUPPL USD/EUR DR EUR'), ('partner_id', '=', ref('base.res_partner_19'))])
259 voucher_id = self.browse(cr, uid, voucher[0])
260 assert (float_compare(round(voucher_id.writeoff_amount, 2), 2.22, precision_digits=2) == 0), "Writeoff amount is not 2.22$"
262 I confirm the voucher
264 !python {model: account.voucher}: |
265 from openerp import netsvc
266 voucher = self.search(cr, uid, [('name', '=', 'Second payment: Case 2 SUPPL USD/EUR DR EUR'), ('partner_id', '=', ref('base.res_partner_19'))])
267 self.signal_workflow(cr, uid, voucher, 'proforma_voucher')
269 I check that my voucher state is posted
271 !python {model: account.voucher}: |
272 voucher = self.search(cr, uid, [('name', '=', 'Second payment: Case 2 SUPPL USD/EUR DR EUR'), ('partner_id', '=', ref('base.res_partner_19'))])
273 voucher_id = self.browse(cr, uid, voucher[0])
274 assert voucher_id.state == 'posted', "Voucher state is not posted"
276 I check that my debtor account is correct
278 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($).
280 I check that my currency rate difference is correct.
282 I check that my writeoff is correct. 2.11 in credit and 2.22 in amount_currency
284 !python {model: account.voucher}: |
285 from openerp.tools import float_compare
286 voucher = self.search(cr, uid, [('name', '=', 'Second payment: Case 2 SUPPL USD/EUR DR EUR'), ('partner_id', '=', ref('base.res_partner_19'))])
287 voucher_id = self.browse(cr, uid, voucher[0])
288 move_line_obj = self.pool.get('account.move.line')
289 move_lines = move_line_obj.search(cr, uid, [('move_id', '=', voucher_id.move_id.id)])
290 reconcile_a = reconcile_b = False
291 for move_line in move_line_obj.browse(cr, uid, move_lines):
292 if float_compare(move_line.amount_currency, -22.22, precision_digits=2) == 0:
293 assert move_line.reconcile_id.id, "The invoice of 200$ is not fully reconciled"
294 reconcile_b = move_line.reconcile_id.id
295 elif float_compare(move_line.amount_currency, -55.56, precision_digits=2) == 0:
296 assert move_line.reconcile_id.id, "The invoice of 100$ is not fully reconciled"
297 reconcile_a = move_line.reconcile_id.id
298 for move_line in move_line_obj.browse(cr, uid, move_lines):
299 if float_compare(move_line.amount_currency, -55.56, precision_digits=2) == 0:
300 assert float_compare(move_line.credit, 52.78, precision_digits=2) == 0, "Debtor account has wrong entry."
301 elif float_compare(move_line.amount_currency, -22.22, precision_digits=2) == 0:
302 assert float_compare(move_line.credit, 21.11, precision_digits=2) == 0, "Debtor account has wrong entry."
303 elif float_compare(move_line.credit, 11.11, precision_digits=2) == 0 and move_line.account_id.reconcile:
304 assert float_compare(move_line.amount_currency, 0.00, precision_digits=2) == 0 and move_line.reconcile_id.id == reconcile_b, "Incorrect Currency Difference."
305 elif float_compare(move_line.credit, 32.78, precision_digits=2) == 0 and move_line.account_id.reconcile:
306 assert float_compare(move_line.amount_currency, 0.00, precision_digits=2) == 0 and move_line.reconcile_id.id == reconcile_a, "Incorrect Currency Difference."
307 elif float_compare(move_line.amount_currency, 2.22, precision_digits=2) == 0:
308 assert float_compare(move_line.credit, 2.11, 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"))
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 amuont 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"))
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"