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: account.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
invoice_id = self.browse(cr, uid, ref("account_invoice_jan"))
98
assert invoice_id.move_id, "Move not created for open invoice"
99
move_line_obj = self.pool.get('account.move.line')
100
move_lines = move_line_obj.search(cr, uid, [('move_id', '=', invoice_id.move_id.id), ('account_id', '=', invoice_id.account_id.id)])
101
move_line = move_line_obj.browse(cr, uid, move_lines[0])
102
assert (move_line.debit - move_line.credit == 150.0), "Invoice move is not correct for debtors account"
104
I create the second invoice on 1st February for 100 USD
106
!record {model: account.invoice, id: account_invoice_feb}:
107
account_id: account.a_recv
108
company_id: base.main_company
109
currency_id: base.USD
110
date_invoice: !eval "'%s-02-01' %(datetime.now().year)"
111
period_id: account.period_2
113
- account_id: account.a_sale
114
name: '[PCSC234] PC Assemble SC234'
117
product_id: product.product_product_3
118
uos_id: product.product_uom_unit
119
journal_id: account.sales_journal
120
partner_id: base.res_partner_19
123
I Validate invoice by clicking on Validate button
125
!workflow {model: account.invoice, action: invoice_open, ref: account_invoice_feb}
127
I check that second invoice move is correct for debtor account (debit - credit == 80)
129
!python {model: account.invoice}: |
130
invoice_id = self.browse(cr, uid, ref("account_invoice_feb"))
131
assert invoice_id.move_id, "Move not created for open invoice"
132
move_line_obj = self.pool.get('account.move.line')
133
move_lines = move_line_obj.search(cr, uid, [('move_id', '=', invoice_id.move_id.id), ('account_id', '=', invoice_id.account_id.id)])
134
move_line = move_line_obj.browse(cr, uid, move_lines[0])
135
assert (move_line.debit - move_line.credit == 80), "Invoice move is not correct for debtors account"
138
I set the context that will be used for the encoding of all the vouchers of this file
143
On the first March, I create the first voucher of payment with values 240 USD, journal USD,
145
!record {model: account.voucher, id: account_voucher_1_case1, view: view_vendor_receipt_form}:
146
account_id: account.cash
148
company_id: base.main_company
149
journal_id: bank_journal_USD
150
name: 'First payment: Case 1 USD/USD'
151
partner_id: base.res_partner_19
152
period_id: account.period_3
153
date: !eval time.strftime("%Y-03-01")
154
payment_option: 'with_writeoff'
155
writeoff_acc_id: account.a_expense
159
I fill amounts 180 for the invoice of 200$ and 70 for the invoice of 100$>
161
!python {model: account.voucher}: |
164
voucher_id = self.browse(cr, uid, ref('account_voucher_1_case1'))
166
for item in voucher_id.line_cr_ids:
167
if item.amount_unreconciled == 200.00:
168
data += [(item.id, 180.0)]
170
data += [(item.id, 70.0)]
171
for line_id, amount in data:
172
self.pool.get('account.voucher.line').write(cr, uid, [line_id], {'amount': amount})
173
assert (voucher_id.state=='draft'), "Voucher is not in draft state"
175
I check that writeoff amount computed is -10.0
177
!python {model: account.voucher}: |
178
voucher = self.search(cr, uid, [('name', '=', 'First payment: Case 1 USD/USD'), ('partner_id', '=', ref('base.res_partner_19'))])
179
voucher_id = self.browse(cr, uid, voucher[0])
180
assert (voucher_id.writeoff_amount == -10.0), "Writeoff amount is not -10.0"
182
I confirm the voucher
184
!python {model: account.voucher}: |
186
voucher = self.search(cr, uid, [('name', '=', 'First payment: Case 1 USD/USD'), ('partner_id', '=', ref('base.res_partner_19'))])
187
wf_service = netsvc.LocalService("workflow")
188
wf_service.trg_validate(uid, 'account.voucher', voucher[0], 'proforma_voucher', cr)
190
I check that the move of my first voucher is valid
192
!python {model: account.voucher}: |
193
voucher = self.search(cr, uid, [('name', '=', 'First payment: Case 1 USD/USD'), ('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 that my debtor account is correct
202
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
204
I check that my write-off is correct. 9 debit and 10 amount_currency
206
!python {model: account.voucher}: |
207
voucher = self.search(cr, uid, [('name', '=', 'First payment: Case 1 USD/USD'), ('partner_id', '=', ref('base.res_partner_19'))])
208
voucher_id = self.browse(cr, uid, voucher[0])
209
move_line_obj = self.pool.get('account.move.line')
210
move_lines = move_line_obj.search(cr, uid, [('move_id', '=', voucher_id.move_id.id)])
211
for move_line in move_line_obj.browse(cr, uid, move_lines):
212
if move_line.amount_currency == -180.00:
213
assert move_line.credit == 162.00, "Debtor account has wrong entry."
214
elif move_line.amount_currency == -70.00:
215
assert move_line.credit == 63.00, "Debtor account has wrong entry."
216
elif move_line.amount_currency == 10.00:
217
assert move_line.debit == 9.00, "Writeoff amount is wrong."
218
elif move_line.amount_currency == 240.00:
219
assert move_line.debit == 216.00, "Bank entry is wrong."
221
assert False, "Unrecognized journal entry"
223
I check the residual amount of Invoice1, should be 20 in amount_currency
225
!python {model: account.invoice}: |
226
invoice_id = self.browse(cr, uid, ref("account_invoice_jan"))
227
move_line_obj = self.pool.get('account.move.line')
228
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)])
229
move_line = move_line_obj.browse(cr, uid, move_lines[0])
230
assert (move_line.amount_residual_currency == 20.0) , "Residual amount is not correct for first Invoice"
232
I check the residual amuont of Invoice2, should be 30 in residual currency and 24 in amount_residual
234
!python {model: account.invoice}: |
235
invoice_id = self.browse(cr, uid, ref("account_invoice_feb"))
236
move_line_obj = self.pool.get('account.move.line')
237
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)])
238
move_line = move_line_obj.browse(cr, uid, move_lines[0])
239
assert (move_line.amount_residual_currency == 30.0) , "Residual amount is not correct for first Invoice"
241
On the first April, I create the second voucher of payment with values 45 USD, journal USD,
243
!record {model: account.voucher, id: account_voucher_2_case1, view: view_vendor_receipt_form}:
244
account_id: account.cash
246
company_id: base.main_company
247
journal_id: bank_journal_USD
248
name: 'Second payment: Case 1'
249
partner_id: base.res_partner_19
250
period_id: account.period_3
251
date: !eval time.strftime("%Y-04-01")
252
payment_option: 'with_writeoff'
253
writeoff_acc_id: account.a_expense
256
I fill amounts 20 for the invoice of 200$ and 30 for the invoice of 100$
258
!python {model: account.voucher}: |
261
voucher_id = self.browse(cr, uid, ref('account_voucher_2_case1'))
263
for item in voucher_id.line_cr_ids:
264
if item.amount_unreconciled == 20.00:
265
data += [(item.id, 20.0)]
267
data += [(item.id, 30.0)]
268
for line_id, amount in data:
269
self.pool.get('account.voucher.line').write(cr, uid, [line_id], {'amount': amount})
270
assert (voucher_id.state=='draft'), "Voucher is not in draft state"
272
I check that writeoff amount computed is -5.0
274
!python {model: account.voucher}: |
275
voucher = self.search(cr, uid, [('name', '=', 'Second payment: Case 1'), ('partner_id', '=', ref('base.res_partner_19'))])
276
voucher_id = self.browse(cr, uid, voucher[0])
277
assert (voucher_id.writeoff_amount == -5.0), "Writeoff amount is not -5.0"
279
I confirm the voucher
281
!python {model: account.voucher}: |
283
voucher = self.search(cr, uid, [('name', '=', 'Second payment: Case 1'), ('partner_id', '=', ref('base.res_partner_19'))])
284
wf_service = netsvc.LocalService("workflow")
285
wf_service.trg_validate(uid, 'account.voucher', voucher[0], 'proforma_voucher', cr)
287
I check that the move of my second voucher is valid
289
!python {model: account.voucher}: |
290
voucher = self.search(cr, uid, [('name', '=', 'Second payment: Case 1'), ('partner_id', '=', ref('base.res_partner_19'))])
291
voucher_id = self.browse(cr, uid, voucher[0])
292
move_line_obj = self.pool.get('account.move.line')
293
move_lines = move_line_obj.search(cr, uid, [('move_id', '=', voucher_id.move_id.id)])
294
for move_line in move_line_obj.browse(cr, uid, move_lines):
295
assert move_line.state == 'valid', "Voucher move is not valid"
297
I check that my debtor account is correct
299
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
301
I check that my currency rate difference is correct. 8.5 in credit with no amount_currency
303
I check that the total reconcilation created entries as expected
305
I check that my writeoff is correct. 4.75 debit and 5 amount_currency
307
!python {model: account.voucher}: |
308
voucher = self.search(cr, uid, [('name', '=', 'Second payment: Case 1'), ('partner_id', '=', ref('base.res_partner_19'))])
309
voucher_id = self.browse(cr, uid, voucher[0])
310
move_line_obj = self.pool.get('account.move.line')
311
move_lines = move_line_obj.search(cr, uid, [('move_id', '=', voucher_id.move_id.id)])
312
reconcile_a = reconcile_b = False
313
for move_line in move_line_obj.browse(cr, uid, move_lines):
314
if move_line.amount_currency == -20.00:
315
assert move_line.reconcile_id.id, "The invoice of 200$ is not fully reconciled"
316
reconcile_b = move_line.reconcile_id.id
317
elif move_line.amount_currency == -30.00:
318
assert move_line.reconcile_id.id, "The invoice of 100$ is not fully reconciled"
319
reconcile_a = move_line.reconcile_id.id
320
for move_line in move_line_obj.browse(cr, uid, move_lines):
321
if move_line.amount_currency == -20.00:
322
assert move_line.credit == 19.00, "Debtor account has wrong entry."
323
elif move_line.amount_currency == -30.00:
324
assert move_line.credit == 28.50, "Debtor account has wrong entry."
325
elif move_line.amount_currency == 5.00:
326
assert move_line.debit == 4.75, "Writeoff amount is wrong."
327
elif move_line.debit == 11.5 and move_line.account_id.reconcile:
328
assert move_line.amount_currency == 0.0 and move_line.reconcile_id.id == reconcile_a, "Exchange difference entry for the invoice of 100$ is wrong"
329
elif move_line.credit == 11.5:
330
assert move_line.amount_currency == 0.0
331
elif move_line.debit == 31.0 and move_line.account_id.reconcile:
332
assert move_line.amount_currency == 0.0 and move_line.reconcile_id.id == reconcile_b, "Exchange difference entry for the invoice of 200$ is wrong"
333
elif move_line.credit == 31.0:
334
assert move_line.amount_currency == 0.0
335
elif move_line.amount_currency == 45.00:
336
assert move_line.debit == 42.75, "Bank entry is wrong."
338
assert False, "Unrecognized journal entry"
340
I check the residual amount of Invoice1, should be 0 in residual currency and 0 in amount_residual and paid
342
!python {model: account.invoice}: |
343
invoice_id = self.browse(cr, uid, ref("account_invoice_jan"))
344
move_line_obj = self.pool.get('account.move.line')
345
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)])
346
move_line = move_line_obj.browse(cr, uid, move_lines[0])
347
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"
349
I check the residual amuont of Invoice2, should be 0 in residual currency and 0 in amount_residual and paid
351
!python {model: account.invoice}: |
352
invoice_id = self.browse(cr, uid, ref("account_invoice_feb"))
353
move_line_obj = self.pool.get('account.move.line')
354
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)])
355
move_line = move_line_obj.browse(cr, uid, move_lines[0])
356
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"