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: account.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: account.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 invoice_id = self.browse(cr, uid, ref("account_first_invoice_jan"))
103 assert invoice_id.move_id, "Move not created for open invoice"
104 move_line_obj = self.pool.get('account.move.line')
105 move_lines = move_line_obj.search(cr, uid, [('move_id', '=', invoice_id.move_id.id), ('account_id', '=', invoice_id.account_id.id)])
106 move_line = move_line_obj.browse(cr, uid, move_lines[0])
107 assert (move_line.debit - move_line.credit == 150.00), "Invoice move is incorrect for debtors account"
109 I create the second invoice on 1st February for 100 USD
111 !record {model: account.invoice, id: account_second_invoice_feb}:
112 account_id: account.a_recv
113 company_id: base.main_company
114 currency_id: base.USD
115 date_invoice: !eval "'%s-02-01' %(datetime.now().year)"
116 period_id: account.period_2
118 - account_id: account.a_sale
119 name: '[PCSC234] PC Assemble SC234'
122 product_id: product.product_product_3
123 uos_id: product.product_uom_unit
124 journal_id: account.sales_journal
125 partner_id: base.res_partner_19
128 I Validate invoice by clicking on Validate button
130 !workflow {model: account.invoice, action: invoice_open, ref: account_second_invoice_feb}
132 I check that second invoice move is correct for debtor account (debit - credit == 80)
134 !python {model: account.invoice}: |
135 invoice_id = self.browse(cr, uid, ref("account_second_invoice_feb"))
136 assert invoice_id.move_id, "Move not created for open invoice"
137 move_line_obj = self.pool.get('account.move.line')
138 move_lines = move_line_obj.search(cr, uid, [('move_id', '=', invoice_id.move_id.id), ('account_id', '=', invoice_id.account_id.id)])
139 move_line = move_line_obj.browse(cr, uid, move_lines[0])
140 assert (move_line.debit - move_line.credit == 80), "Invoice move is incorrect for debtors account"
142 I set the context that will be used for the encoding of all the vouchers of this file
147 I create the first voucher of payment with values 200 EUR, journal EUR
149 !record {model: account.voucher, id: account_voucher_1_case2a, view: view_vendor_receipt_form}:
150 account_id: account.cash
152 company_id: base.main_company
153 journal_id: bank_journal_EUR
154 partner_id: base.res_partner_19
155 period_id: account.period_3
156 date: !eval time.strftime("%Y-03-01")
157 payment_option: 'with_writeoff'
158 writeoff_acc_id: account.a_expense
160 name: 'First payment: Case 2 USD/EUR DR EUR'
163 I fill amounts 130 for the invoice of 200$ and 70 for the invoice of 100$
165 !python {model: account.voucher}: |
167 from openerp import netsvc
169 voucher_id = self.browse(cr, uid, ref('account_voucher_1_case2a'))
171 for item in voucher_id.line_cr_ids:
172 if item.amount_unreconciled == 150.00:
173 data += [(item.id, 130.0)]
175 data += [(item.id, 70.0)]
176 for line_id, amount in data:
177 self.pool.get('account.voucher.line').write(cr, uid, [line_id], {'amount': amount})
178 assert (voucher_id.state=='draft'), "Voucher is not in draft state"
180 I confirm the voucher
182 !python {model: account.voucher}: |
183 from openerp import netsvc
184 voucher = self.search(cr, uid, [('name', '=', 'First payment: Case 2 USD/EUR DR EUR'), ('partner_id', '=', ref('base.res_partner_19'))])
185 self.signal_proforma_voucher(cr, uid, 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 EUR'), ('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 the residual amount of Invoice1, should be 55.56 in residual currency and 20 in amount_residual
199 !python {model: account.invoice}: |
200 invoice_id = self.browse(cr, uid, ref("account_first_invoice_jan"))
201 move_line_obj = self.pool.get('account.move.line')
202 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)])
203 move_line = move_line_obj.browse(cr, uid, move_lines[0])
204 assert (move_line.amount_residual_currency == 55.56 and move_line.amount_residual == 20) , "Residual amount is not correct for first Invoice. Got %s USD (%s EUR)" %(move_line.amount_residual_currency, move_line.amount_residual)
206 I check the residual amuont of Invoice2, should be 22.22 in residual currency and 10 in amount_residual
208 !python {model: account.invoice}: |
209 invoice_id = self.browse(cr, uid, ref("account_second_invoice_feb"))
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 (move_line.amount_residual_currency == 22.22 and move_line.amount_residual == 10) , "Residual amount is not correct for second Invoice"
215 I create the second voucher of payment with values 80 USD, journal USD
217 !record {model: account.voucher, id: account_voucher_2_case2a, view: view_vendor_receipt_form}:
218 account_id: account.cash
220 company_id: base.main_company
221 journal_id: bank_journal_USD
222 partner_id: base.res_partner_19
223 period_id: account.period_3
224 date: !eval time.strftime("%Y-04-01")
225 payment_option: 'with_writeoff'
226 writeoff_acc_id: account.a_expense
228 name: 'Second payment: Case 2 SUPPL USD/EUR DR EUR'
231 and I fully reconcile the 2 previous invoices
233 !python {model: account.voucher}: |
235 from openerp import netsvc
237 voucher_id = self.browse(cr, uid, ref('account_voucher_2_case2a'))
239 for item in voucher_id.line_cr_ids:
240 if item.amount_unreconciled == 55.56:
241 data += [(item.id, 55.56)]
243 data += [(item.id, 22.22)]
244 for line_id, amount in data:
245 self.pool.get('account.voucher.line').write(cr, uid, [line_id], {'amount': amount})
246 assert (voucher_id.state=='draft'), "Voucher is not in draft state"
248 I check that writeoff amount computed is 2.22
250 !python {model: account.voucher}: |
251 voucher = self.search(cr, uid, [('name', '=', 'Second payment: Case 2 SUPPL USD/EUR DR EUR'), ('partner_id', '=', ref('base.res_partner_19'))])
252 voucher_id = self.browse(cr, uid, voucher[0])
253 assert (round(voucher_id.writeoff_amount, 2) == 2.22), "Writeoff amount is not 2.22$"
255 I confirm the voucher
257 !python {model: account.voucher}: |
258 from openerp import netsvc
259 voucher = self.search(cr, uid, [('name', '=', 'Second payment: Case 2 SUPPL USD/EUR DR EUR'), ('partner_id', '=', ref('base.res_partner_19'))])
260 self.signal_proforma_voucher(cr, uid, voucher)
262 I check that my voucher state is posted
264 !python {model: account.voucher}: |
265 voucher = self.search(cr, uid, [('name', '=', 'Second payment: Case 2 SUPPL USD/EUR DR EUR'), ('partner_id', '=', ref('base.res_partner_19'))])
266 voucher_id = self.browse(cr, uid, voucher[0])
267 assert voucher_id.state == 'posted', "Voucher state is not posted"
269 I check that my debtor account is correct
271 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($).
273 I check that my currency rate difference is correct.
275 I check that my writeoff is correct. 2.11 in credit and 2.22 in amount_currency
277 !python {model: account.voucher}: |
278 voucher = self.search(cr, uid, [('name', '=', 'Second payment: Case 2 SUPPL USD/EUR DR EUR'), ('partner_id', '=', ref('base.res_partner_19'))])
279 voucher_id = self.browse(cr, uid, voucher[0])
280 move_line_obj = self.pool.get('account.move.line')
281 move_lines = move_line_obj.search(cr, uid, [('move_id', '=', voucher_id.move_id.id)])
282 reconcile_a = reconcile_b = False
283 for move_line in move_line_obj.browse(cr, uid, move_lines):
284 if move_line.amount_currency == -22.22:
285 assert move_line.reconcile_id.id, "The invoice of 200$ is not fully reconciled"
286 reconcile_b = move_line.reconcile_id.id
287 elif move_line.amount_currency == -55.56:
288 assert move_line.reconcile_id.id, "The invoice of 100$ is not fully reconciled"
289 reconcile_a = move_line.reconcile_id.id
290 for move_line in move_line_obj.browse(cr, uid, move_lines):
291 if move_line.amount_currency == -55.56:
292 assert move_line.credit == 52.78, "Debtor account has wrong entry."
293 elif move_line.amount_currency == -22.22:
294 assert move_line.credit == 21.11, "Debtor account has wrong entry."
295 elif move_line.credit == 11.11 and move_line.account_id.reconcile:
296 assert move_line.amount_currency == 0.00 and move_line.reconcile_id.id == reconcile_b, "Incorrect Currency Difference."
297 elif move_line.credit == 32.78 and move_line.account_id.reconcile:
298 assert move_line.amount_currency == 0.00 and move_line.reconcile_id.id == reconcile_a, "Incorrect Currency Difference."
299 elif move_line.amount_currency == 2.22:
300 assert move_line.credit == 2.11, "Writeoff amount is wrong."
302 I check the residual amount of invoice 1, should be 0 in residual currency and 0 in amount_residual and paid
304 !python {model: account.invoice}: |
305 invoice_id = self.browse(cr, uid, ref("account_first_invoice_jan"))
306 move_line_obj = self.pool.get('account.move.line')
307 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)])
308 move_line = move_line_obj.browse(cr, uid, move_lines[0])
309 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"
311 I check the residual amuont of invoice 2, should be 0 in residual currency and 0 in amount_residual and paid
313 !python {model: account.invoice}: |
314 invoice_id = self.browse(cr, uid, ref("account_second_invoice_feb"))
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 (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"