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 in USD 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 currency USD in OpenERP for January of 1.333333 Rate
16 !python {model: res.currency.rate}: |
17 from datetime import datetime
18 curr_id = self.pool.get('res.currency').search(cr, uid, [('name', '=', 'USD')])[0]
19 date = '%s-01-01' %(datetime.now().year)
20 ids = self.search(cr, uid, [('currency_id','=',curr_id), ('name', '=', date)])
21 self.write(cr, uid, ids, {'rate': 1.333333})
23 I create currency USD in OpenERP for February of 1.250000 Rate
25 !record {model: res.currency.rate, id: feb_usd}:
27 name: !eval "'%s-02-01' %(datetime.now().year)"
31 I create currency USD in OpenERP for March of 1.111111 Rate
33 !record {model: res.currency.rate, id: mar_usd}:
35 name: !eval "'%s-03-01' %(datetime.now().year)"
39 I create currency USD in OpenERP for April of 1.052632 Rate
41 !record {model: res.currency.rate, id: apr_usd}:
43 name: !eval "'%s-04-01' %(datetime.now().year)"
47 I create a cash account with currency USD
49 !record {model: account.account, id: account_cash_usd_id}:
51 name: "cash account in usd"
54 user_type: "account.data_account_type_cash"
57 I create a bank journal with USD as currency
59 !record {model: account.journal, id: bank_journal_USD}:
60 name: Bank Journal(USD)
63 analytic_journal_id: analytic.sit
64 sequence_id: account.sequence_bank_journal
65 default_debit_account_id: account_cash_usd_id
66 default_credit_account_id: account_cash_usd_id
68 company_id: base.main_company
71 I create the first invoice on 1st January for 200 USD
73 !record {model: account.invoice, id: account_invoice_jan}:
74 account_id: account.a_recv
75 company_id: base.main_company
77 date_invoice: !eval "'%s-01-01' %(datetime.now().year)"
78 period_id: account.period_1
80 - account_id: account.a_sale
81 name: '[PCSC234] PC Assemble SC234'
84 product_id: product.product_product_3
85 uos_id: product.product_uom_unit
86 journal_id: account.sales_journal
87 partner_id: base.res_partner_19
90 I Validate invoice by clicking on Validate button
92 !workflow {model: account.invoice, action: invoice_open, ref: account_invoice_jan}
94 I check that first invoice move is correct for debtor account (debit - credit == 150.0)
96 !python {model: account.invoice}: |
97 from openerp.tools import float_compare
98 invoice_id = self.browse(cr, uid, ref("account_invoice_jan"))
99 assert invoice_id.move_id, "Move not created for open invoice"
100 move_line_obj = self.pool.get('account.move.line')
101 move_lines = move_line_obj.search(cr, uid, [('move_id', '=', invoice_id.move_id.id), ('account_id', '=', invoice_id.account_id.id)])
102 move_line = move_line_obj.browse(cr, uid, move_lines[0])
103 assert (float_compare(move_line.debit - move_line.credit, 150.0, precision_digits=2) == 0), "Invoice move is not correct for debtors account"
105 I create the second invoice on 1st February for 100 USD
107 !record {model: account.invoice, id: account_invoice_feb}:
108 account_id: account.a_recv
109 company_id: base.main_company
110 currency_id: base.USD
111 date_invoice: !eval "'%s-02-01' %(datetime.now().year)"
112 period_id: account.period_2
114 - account_id: account.a_sale
115 name: '[PCSC234] PC Assemble SC234'
118 product_id: product.product_product_3
119 uos_id: product.product_uom_unit
120 journal_id: account.sales_journal
121 partner_id: base.res_partner_19
124 I Validate invoice by clicking on Validate button
126 !workflow {model: account.invoice, action: invoice_open, ref: account_invoice_feb}
128 I check that second invoice move is correct for debtor account (debit - credit == 80)
130 !python {model: account.invoice}: |
131 from openerp.tools import float_compare
132 invoice_id = self.browse(cr, uid, ref("account_invoice_feb"))
133 assert invoice_id.move_id, "Move not created for open invoice"
134 move_line_obj = self.pool.get('account.move.line')
135 move_lines = move_line_obj.search(cr, uid, [('move_id', '=', invoice_id.move_id.id), ('account_id', '=', invoice_id.account_id.id)])
136 move_line = move_line_obj.browse(cr, uid, move_lines[0])
137 assert (float_compare(move_line.debit - move_line.credit, 80, precision_digits=2) == 0), "Invoice move is not correct for debtors account"
140 I set the context that will be used for the encoding of all the vouchers of this file
145 On the first March, I create the first voucher of payment with values 240 USD, journal USD,
147 !record {model: account.voucher, id: account_voucher_1_case1, view: view_vendor_receipt_form}:
148 account_id: account.cash
150 company_id: base.main_company
151 journal_id: bank_journal_USD
152 name: 'First payment: Case 1 USD/USD'
153 partner_id: base.res_partner_19
154 period_id: account.period_3
155 date: !eval time.strftime("%Y-03-01")
156 payment_option: 'with_writeoff'
157 writeoff_acc_id: account.a_expense
161 I fill amounts 180 for the invoice of 200$ and 70 for the invoice of 100$>
163 !python {model: account.voucher}: |
164 from openerp.tools import float_compare
166 voucher_id = self.browse(cr, uid, ref('account_voucher_1_case1'))
168 for item in voucher_id.line_cr_ids:
169 if float_compare(item.amount_unreconciled, 200.00, precision_digits=2) == 0:
170 data += [(item.id, 180.0)]
172 data += [(item.id, 70.0)]
173 for line_id, amount in data:
174 self.pool.get('account.voucher.line').write(cr, uid, [line_id], {'amount': amount})
175 assert (voucher_id.state=='draft'), "Voucher is not in draft state"
177 I check that writeoff amount computed is -10.0
179 !python {model: account.voucher}: |
180 from openerp.tools import float_compare
181 voucher = self.search(cr, uid, [('name', '=', 'First payment: Case 1 USD/USD'), ('partner_id', '=', ref('base.res_partner_19'))])
182 voucher_id = self.browse(cr, uid, voucher[0])
183 assert (float_compare(voucher_id.writeoff_amount, -10.0, precision_digits=2) == 0), "Writeoff amount is not -10.0"
185 I confirm the voucher
187 !python {model: account.voucher}: |
188 voucher = self.search(cr, uid, [('name', '=', 'First payment: Case 1 USD/USD'), ('partner_id', '=', ref('base.res_partner_19'))])
189 self.signal_workflow(cr, uid, voucher, 'proforma_voucher')
191 I check that the move of my first voucher is valid
193 !python {model: account.voucher}: |
194 voucher = self.search(cr, uid, [('name', '=', 'First payment: Case 1 USD/USD'), ('partner_id', '=', ref('base.res_partner_19'))])
195 voucher_id = self.browse(cr, uid, voucher[0])
196 move_line_obj = self.pool.get('account.move.line')
197 move_lines = move_line_obj.search(cr, uid, [('move_id', '=', voucher_id.move_id.id)])
198 for move_line in move_line_obj.browse(cr, uid, move_lines):
199 assert move_line.state == 'valid', "Voucher move is not valid"
201 I check that my debtor account is correct
203 I check that the debtor account has 2 new lines with -180 and -70 as amount_currency columns and that their credit columns are respectively 162 and 63
205 I check that my write-off is correct. 9 debit and 10 amount_currency
207 !python {model: account.voucher}: |
208 from openerp.tools import float_compare
209 voucher = self.search(cr, uid, [('name', '=', 'First payment: Case 1 USD/USD'), ('partner_id', '=', ref('base.res_partner_19'))])
210 voucher_id = self.browse(cr, uid, voucher[0])
211 move_line_obj = self.pool.get('account.move.line')
212 move_lines = move_line_obj.search(cr, uid, [('move_id', '=', voucher_id.move_id.id)])
213 for move_line in move_line_obj.browse(cr, uid, move_lines):
214 if float_compare(move_line.amount_currency, -180.00, precision_digits=2) == 0:
215 assert float_compare(move_line.credit, 162.00, precision_digits=2) == 0, "Debtor account has wrong entry."
216 elif float_compare(move_line.amount_currency, -70.00, precision_digits=2) == 0:
217 assert float_compare(move_line.credit, 63.00, precision_digits=2) == 0, "Debtor account has wrong entry."
218 elif float_compare(move_line.amount_currency, 10.00, precision_digits=2) == 0:
219 assert float_compare(move_line.debit, 9.00, precision_digits=2) == 0, "Writeoff amount is wrong."
220 elif float_compare(move_line.amount_currency, 240.00, precision_digits=2) == 0:
221 assert float_compare(move_line.debit, 216.00, precision_digits=2) == 0, "Bank entry is wrong."
223 assert False, "Unrecognized journal entry"
225 I check the residual amount of Invoice1, should be 20 in amount_currency
227 !python {model: account.invoice}: |
228 from openerp.tools import float_compare
229 invoice_id = self.browse(cr, uid, ref("account_invoice_jan"))
230 move_line_obj = self.pool.get('account.move.line')
231 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)])
232 move_line = move_line_obj.browse(cr, uid, move_lines[0])
233 assert (float_compare(move_line.amount_residual_currency, 20.0, precision_digits=2) == 0) , "Residual amount is not correct for first Invoice"
235 I check the residual amuont of Invoice2, should be 30 in residual currency and 24 in amount_residual
237 !python {model: account.invoice}: |
238 from openerp.tools import float_compare
239 invoice_id = self.browse(cr, uid, ref("account_invoice_feb"))
240 move_line_obj = self.pool.get('account.move.line')
241 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)])
242 move_line = move_line_obj.browse(cr, uid, move_lines[0])
243 assert (float_compare(move_line.amount_residual_currency, 30.0, precision_digits=2) == 0) , "Residual amount is not correct for first Invoice"
245 On the first April, I create the second voucher of payment with values 45 USD, journal USD,
247 !record {model: account.voucher, id: account_voucher_2_case1, view: view_vendor_receipt_form}:
248 account_id: account.cash
250 company_id: base.main_company
251 journal_id: bank_journal_USD
252 name: 'Second payment: Case 1'
253 partner_id: base.res_partner_19
254 period_id: account.period_3
255 date: !eval time.strftime("%Y-04-01")
256 payment_option: 'with_writeoff'
257 writeoff_acc_id: account.a_expense
260 I fill amounts 20 for the invoice of 200$ and 30 for the invoice of 100$
262 !python {model: account.voucher}: |
263 from openerp.tools import float_compare
265 voucher_id = self.browse(cr, uid, ref('account_voucher_2_case1'))
267 for item in voucher_id.line_cr_ids:
268 if float_compare(item.amount_unreconciled, 20.00, precision_digits=2) == 0:
269 data += [(item.id, 20.0)]
271 data += [(item.id, 30.0)]
272 for line_id, amount in data:
273 self.pool.get('account.voucher.line').write(cr, uid, [line_id], {'amount': amount})
274 assert (voucher_id.state=='draft'), "Voucher is not in draft state"
276 I check that writeoff amount computed is -5.0
278 !python {model: account.voucher}: |
279 from openerp.tools import float_compare
280 voucher = self.search(cr, uid, [('name', '=', 'Second payment: Case 1'), ('partner_id', '=', ref('base.res_partner_19'))])
281 voucher_id = self.browse(cr, uid, voucher[0])
282 assert (float_compare(voucher_id.writeoff_amount, -5.0, precision_digits=2) == 0), "Writeoff amount is not -5.0"
284 I confirm the voucher
286 !python {model: account.voucher}: |
287 voucher = self.search(cr, uid, [('name', '=', 'Second payment: Case 1'), ('partner_id', '=', ref('base.res_partner_19'))])
288 self.signal_workflow(cr, uid, voucher, 'proforma_voucher')
290 I check that the move of my second voucher is valid
292 !python {model: account.voucher}: |
293 voucher = self.search(cr, uid, [('name', '=', 'Second payment: Case 1'), ('partner_id', '=', ref('base.res_partner_19'))])
294 voucher_id = self.browse(cr, uid, voucher[0])
295 move_line_obj = self.pool.get('account.move.line')
296 move_lines = move_line_obj.search(cr, uid, [('move_id', '=', voucher_id.move_id.id)])
297 for move_line in move_line_obj.browse(cr, uid, move_lines):
298 assert move_line.state == 'valid', "Voucher move is not valid"
300 I check that my debtor account is correct
302 I check that the debtor account has 2 new lines with -20 and -30 as amount_currency columns and their credit columns are respectively 19 and 28.5
304 I check that my currency rate difference is correct. 8.5 in credit with no amount_currency
306 I check that the total reconcilation created entries as expected
308 I check that my writeoff is correct. 4.75 debit and 5 amount_currency
310 !python {model: account.voucher}: |
311 from openerp.tools import float_compare
312 voucher = self.search(cr, uid, [('name', '=', 'Second payment: Case 1'), ('partner_id', '=', ref('base.res_partner_19'))])
313 voucher_id = self.browse(cr, uid, voucher[0])
314 move_line_obj = self.pool.get('account.move.line')
315 move_lines = move_line_obj.search(cr, uid, [('move_id', '=', voucher_id.move_id.id)])
316 reconcile_a = reconcile_b = False
317 for move_line in move_line_obj.browse(cr, uid, move_lines):
318 if float_compare(move_line.amount_currency, -20.00, precision_digits=2) == 0:
319 assert move_line.reconcile_id.id, "The invoice of 200$ is not fully reconciled"
320 reconcile_b = move_line.reconcile_id.id
321 elif float_compare(move_line.amount_currency, -30.00, precision_digits=2) == 0:
322 assert move_line.reconcile_id.id, "The invoice of 100$ is not fully reconciled"
323 reconcile_a = move_line.reconcile_id.id
324 for move_line in move_line_obj.browse(cr, uid, move_lines):
325 if float_compare(move_line.amount_currency, -20.00, precision_digits=2) == 0:
326 assert float_compare(move_line.credit, 19.00, precision_digits=2) == 0, "Debtor account has wrong entry."
327 elif float_compare(move_line.amount_currency, -30.00, precision_digits=2) == 0:
328 assert float_compare(move_line.credit, 28.50, precision_digits=2) == 0, "Debtor account has wrong entry."
329 elif float_compare(move_line.amount_currency, 5.00, precision_digits=2) == 0:
330 assert float_compare(move_line.debit, 4.75, precision_digits=2) == 0, "Writeoff amount is wrong."
331 elif float_compare(move_line.debit, 11.5, precision_digits=2) == 0 and move_line.account_id.reconcile:
332 assert float_compare(move_line.amount_currency, 0.0, precision_digits=2) == 0 and move_line.reconcile_id.id == reconcile_a, "Exchange difference entry for the invoice of 100$ is wrong"
333 elif float_compare(move_line.credit, 11.5, precision_digits=2) == 0:
334 assert float_compare(move_line.amount_currency, 0.0, precision_digits=2) == 0
335 elif float_compare(move_line.debit, 31.0, precision_digits=2) == 0 and move_line.account_id.reconcile:
336 assert float_compare(move_line.amount_currency, 0.0, precision_digits=2) == 0 and move_line.reconcile_id.id == reconcile_b, "Exchange difference entry for the invoice of 200$ is wrong"
337 elif float_compare(move_line.credit, 31.0, precision_digits=2) == 0:
338 assert float_compare(move_line.amount_currency, 0.0, precision_digits=2) == 0
339 elif float_compare(move_line.amount_currency, 45.00, precision_digits=2) == 0:
340 assert float_compare(move_line.debit, 42.75, precision_digits=2) == 0, "Bank entry is wrong."
342 assert False, "Unrecognized journal entry"
344 I check the residual amount of Invoice1, should be 0 in residual currency and 0 in amount_residual and paid
346 !python {model: account.invoice}: |
347 from openerp.tools import float_compare
348 invoice_id = self.browse(cr, uid, ref("account_invoice_jan"))
349 move_line_obj = self.pool.get('account.move.line')
350 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)])
351 move_line = move_line_obj.browse(cr, uid, move_lines[0])
352 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"
354 I check the residual amuont of Invoice2, should be 0 in residual currency and 0 in amount_residual and paid
356 !python {model: account.invoice}: |
357 from openerp.tools import float_compare
358 invoice_id = self.browse(cr, uid, ref("account_invoice_feb"))
359 move_line_obj = self.pool.get('account.move.line')
360 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)])
361 move_line = move_line_obj.browse(cr, uid, move_lines[0])
362 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"