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 create currency USD in OpenERP for January of 1.333333 Rate
7 !python {model: res.currency.rate}: |
8 from datetime import datetime
9 curr_id = self.pool.get('res.currency').search(cr, uid, [('name', '=', 'USD')])
10 date = '%s-01-01' %(datetime.now().year)
11 ids = self.search(cr, uid, [('currency_id','=',curr_id), ('name', '=', date)])
12 self.write(cr, uid, ids, {'rate': 1.333333})
14 I create currency USD in OpenERP for February of 1.250000 Rate
16 !record {model: res.currency.rate, id: feb_usd}:
18 name: !eval "'%s-02-01' %(datetime.now().year)"
22 I create currency USD in OpenERP for March of 1.111111 Rate
24 !record {model: res.currency.rate, id: mar_usd}:
26 name: !eval "'%s-03-01' %(datetime.now().year)"
30 I create currency USD in OpenERP for April of 1.052632 Rate
32 !record {model: res.currency.rate, id: apr_usd}:
34 name: !eval "'%s-04-01' %(datetime.now().year)"
38 I create a bank journal with USD as currency
40 !record {model: account.journal, id: bank_journal_USD}:
41 name: Bank Journal(USD)
44 analytic_journal_id: account.sit
45 sequence_id: account.sequence_bank_journal
46 default_debit_account_id: account.cash
47 default_credit_account_id: account.cash
49 company_id: base.main_company
50 view_id: account.account_journal_bank_view
53 I set up some accounts for currency rate expense/income in my company
55 !record {model: res.company, id: base.main_company}:
56 property_expense_currency_exchange: account.o_expense
57 property_income_currency_exchange: account.o_income
59 I create new partner Mark Strauss.
61 !record {model: res.partner, id: res_partner_strauss0}:
66 street: 1 rue Rockfeller
69 name: Mr. Mark Strauss
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 address_contact_id: base.res_partner_address_3000
76 address_invoice_id: base.res_partner_address_3000
77 company_id: base.main_company
79 date_invoice: !eval "'%s-01-01' %(datetime.now().year)"
80 period_id: account.period_1
82 - account_id: account.a_sale
83 name: '[PC1] Basic PC'
86 product_id: product.product_product_pc1
87 uos_id: product.product_uom_unit
88 journal_id: account.sales_journal
89 partner_id: res_partner_strauss0
92 I Validate invoice by clicking on Validate button
94 !workflow {model: account.invoice, action: invoice_open, ref: account_invoice_jan}
96 I check that first invoice move is correct for debtor account (debit - credit == 150.0)
98 !python {model: account.invoice}: |
99 invoice_id = self.browse(cr, uid, ref("account_invoice_jan"))
100 assert invoice_id.move_id, "Move not created for open invoice"
101 move_line_obj = self.pool.get('account.move.line')
102 move_lines = move_line_obj.search(cr, uid, [('move_id', '=', invoice_id.move_id.id), ('account_id', '=', invoice_id.account_id.id)])
103 move_line = move_line_obj.browse(cr, uid, move_lines[0])
104 assert (move_line.debit - move_line.credit == 150.0), "Invoice move is not correct for debtors account"
106 I create the second invoice on 1st February for 100 USD
108 !record {model: account.invoice, id: account_invoice_feb}:
109 account_id: account.a_recv
110 address_contact_id: base.res_partner_address_3000
111 address_invoice_id: base.res_partner_address_3000
112 company_id: base.main_company
113 currency_id: base.USD
114 date_invoice: !eval "'%s-02-01' %(datetime.now().year)"
115 period_id: account.period_2
117 - account_id: account.a_sale
118 name: '[PC1] Basic PC'
121 product_id: product.product_product_pc1
122 uos_id: product.product_uom_unit
123 journal_id: account.sales_journal
124 partner_id: res_partner_strauss0
127 I Validate invoice by clicking on Validate button
129 !workflow {model: account.invoice, action: invoice_open, ref: account_invoice_feb}
131 I check that second invoice move is correct for debtor account (debit - credit == 80)
133 !python {model: account.invoice}: |
134 invoice_id = self.browse(cr, uid, ref("account_invoice_feb"))
135 assert invoice_id.move_id, "Move not created for open invoice"
136 move_line_obj = self.pool.get('account.move.line')
137 move_lines = move_line_obj.search(cr, uid, [('move_id', '=', invoice_id.move_id.id), ('account_id', '=', invoice_id.account_id.id)])
138 move_line = move_line_obj.browse(cr, uid, move_lines[0])
139 assert (move_line.debit - move_line.credit == 80), "Invoice move is not correct for debtors account"
142 I create the first voucher of payment
143 <create with values 240 USD, journal USD, and fill amounts 180 for the invoice of 200$ and 70 for the invoice of 100$>
145 !python {model: account.voucher}: |
148 res = self.onchange_partner_id(cr, uid, [], ref("res_partner_strauss0"), ref('bank_journal_USD'), 240.00, 2, ttype='receipt', date=False)
150 'account_id': ref('account.cash'),
152 'company_id': ref('base.main_company'),
153 'currency_id': ref('base.USD'),
154 'journal_id': ref('bank_journal_USD'),
155 'partner_id': ref('res_partner_strauss0'),
156 'period_id': ref('account.period_3'),
158 'date': time.strftime("%Y-03-01"),
159 'payment_option': 'with_writeoff',
160 'writeoff_acc_id': ref('account.a_expense'),
161 'comment': 'Write Off',
162 'name': 'First payment',
164 if not res['value']['line_cr_ids']:
165 res['value']['line_cr_ids'] = [{'type': 'cr', 'account_id': ref('account.a_recv'),}]
166 for item in res['value']['line_cr_ids']:
167 if item['amount_unreconciled'] == 200.00:
168 item['amount'] = 180.00
170 item['amount'] = 70.00
171 vals['line_cr_ids'] = [(0,0,i) for i in res['value']['line_cr_ids']]
172 id = self.create(cr, uid, vals)
173 voucher_id = self.browse(cr, uid, id)
174 assert (voucher_id.state=='draft'), "Voucher is not in draft state"
176 I check that writeoff amount computed is -10.0
178 !python {model: account.voucher}: |
179 voucher = self.search(cr, uid, [('name', '=', 'First payment'), ('partner_id', '=', ref('res_partner_strauss0'))])
180 voucher_id = self.browse(cr, uid, voucher[0])
181 assert (voucher_id.writeoff_amount == -10.0), "Writeoff amount is not -10.0"
183 I check that currency rate difference is -34.0
185 !python {model: account.voucher}: |
186 voucher = self.search(cr, uid, [('name', '=', 'First payment'), ('partner_id', '=', ref('res_partner_strauss0'))])
187 voucher_id = self.browse(cr, uid, voucher[0])
188 assert (voucher_id.currency_rate_difference == -34.0), "Currency rate difference is not -34.0"
190 I confirm the voucher
192 !python {model: account.voucher}: |
194 voucher = self.search(cr, uid, [('name', '=', 'First payment'), ('partner_id', '=', ref('res_partner_strauss0'))])
195 wf_service = netsvc.LocalService("workflow")
196 wf_service.trg_validate(uid, 'account.voucher', voucher[0], 'proforma_voucher', cr)
198 I check that the move of my first voucher is valid
200 !python {model: account.voucher}: |
201 voucher = self.search(cr, uid, [('name', '=', 'First payment'), ('partner_id', '=', ref('res_partner_strauss0'))])
202 voucher_id = self.browse(cr, uid, voucher[0])
203 move_line_obj = self.pool.get('account.move.line')
204 move_lines = move_line_obj.search(cr, uid, [('move_id', '=', voucher_id.move_id.id)])
205 for move_line in move_line_obj.browse(cr, uid, move_lines):
206 assert move_line.state == 'valid', "Voucher move is not valid"
208 I check that my debtor account is correct
210 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 135 and 56
212 I check that my currency rate difference is correct. 34 in credit with no amount_currency
214 I check that my write-off is correct. 9 debit and 10 amount_currency
216 !python {model: account.voucher}: |
217 voucher = self.search(cr, uid, [('name', '=', 'First payment'), ('partner_id', '=', ref('res_partner_strauss0'))])
218 voucher_id = self.browse(cr, uid, voucher[0])
219 move_line_obj = self.pool.get('account.move.line')
220 move_lines = move_line_obj.search(cr, uid, [('move_id', '=', voucher_id.move_id.id)])
221 for move_line in move_line_obj.browse(cr, uid, move_lines):
222 if move_line.amount_currency == -180.00:
223 assert move_line.credit == 135.00, "Debtor account has wrong entry."
224 elif move_line.amount_currency == -70.00:
225 assert move_line.credit == 56.00, "Debtor account has wrong entry."
226 elif move_line.credit == 34.00:
227 assert move_line.amount_currency == 0.00, "Incorrect currency rate difference."
228 elif move_line.amount_currency == 10.00:
229 assert move_line.debit == 9.00, "Writeoff amount is wrong."
231 I check the residual amount of Invoice1, should be 20 in amount_currency and 15 in company currency
233 !python {model: account.invoice}: |
234 invoice_id = self.browse(cr, uid, ref("account_invoice_jan"))
235 move_line_obj = self.pool.get('account.move.line')
236 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)])
237 move_line = move_line_obj.browse(cr, uid, move_lines[0])
238 assert (move_line.amount_residual_currency == 20.0 and move_line.amount_residual == 15.0) , "Residual amount is not correct for first Invoice"
240 I check the residual amuont of Invoice2, should be 30 in residual currency and 24 in amount_residual
242 !python {model: account.invoice}: |
243 invoice_id = self.browse(cr, uid, ref("account_invoice_feb"))
244 move_line_obj = self.pool.get('account.move.line')
245 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)])
246 move_line = move_line_obj.browse(cr, uid, move_lines[0])
247 assert (move_line.amount_residual_currency == 30.0 and move_line.amount_residual == 24.0) , "Residual amount is not correct for first Invoice"
249 I create the second voucher of payment
250 <create with values 45 USD, journal USD, and fill amounts 20 for the invoice of 200$ and 30 for the invoice of 100$>
253 !python {model: account.voucher}: |
256 res = self.onchange_partner_id(cr, uid, [], ref("res_partner_strauss0"), ref('bank_journal_USD'), 45.00, 2, ttype='receipt', date=False)
258 'account_id': ref('account.cash'),
260 'company_id': ref('base.main_company'),
261 'currency_id': ref('base.USD'),
262 'journal_id': ref('bank_journal_USD'),
263 'partner_id': ref('res_partner_strauss0'),
264 'period_id': ref('account.period_3'),
266 'date': time.strftime("%Y-04-01"),
267 'payment_option': 'with_writeoff',
268 'writeoff_acc_id': ref('account.a_expense'),
269 'comment': 'Write Off',
270 'name': 'Second payment',
272 if not res['value']['line_cr_ids']:
273 res['value']['line_cr_ids'] = [{'type': 'cr', 'account_id': ref('account.a_recv'),}]
274 for item in res['value']['line_cr_ids']:
275 if item['amount_unreconciled'] == 20.00:
276 item['amount'] = 20.00
278 item['amount'] = 30.00
279 vals['line_cr_ids'] = [(0,0,i) for i in res['value']['line_cr_ids']]
280 id = self.create(cr, uid, vals)
281 voucher_id = self.browse(cr, uid, id)
282 assert (voucher_id.state=='draft'), "Voucher is not in draft state"
284 I check that writeoff amount computed is -5.0
286 !python {model: account.voucher}: |
287 voucher = self.search(cr, uid, [('name', '=', 'Second payment'), ('partner_id', '=', ref('res_partner_strauss0'))])
288 voucher_id = self.browse(cr, uid, voucher[0])
289 assert (voucher_id.writeoff_amount == -5.0), "Writeoff amount is not -5.0"
291 I check that currency rate difference is -8.50
293 !python {model: account.voucher}: |
294 voucher = self.search(cr, uid, [('name', '=', 'Second payment'), ('partner_id', '=', ref('res_partner_strauss0'))])
295 voucher_id = self.browse(cr, uid, voucher[0])
296 assert (voucher_id.currency_rate_difference == -8.50), "Currency rate difference is not -8.50"
298 I confirm the voucher
300 !python {model: account.voucher}: |
302 voucher = self.search(cr, uid, [('name', '=', 'Second payment'), ('partner_id', '=', ref('res_partner_strauss0'))])
303 wf_service = netsvc.LocalService("workflow")
304 wf_service.trg_validate(uid, 'account.voucher', voucher[0], 'proforma_voucher', cr)
306 I check that the move of my second voucher is valid
308 !python {model: account.voucher}: |
309 voucher = self.search(cr, uid, [('name', '=', 'Second payment'), ('partner_id', '=', ref('res_partner_strauss0'))])
310 voucher_id = self.browse(cr, uid, voucher[0])
311 move_line_obj = self.pool.get('account.move.line')
312 move_lines = move_line_obj.search(cr, uid, [('move_id', '=', voucher_id.move_id.id)])
313 for move_line in move_line_obj.browse(cr, uid, move_lines):
314 assert move_line.state == 'valid', "Voucher move is not valid"
316 I check that my debtor account is correct
318 I check that the debtor account has 2 new lines with -20 and -30 as amount_currency columns and their credit columns are respectively 15 and 24.
320 I check that my currency rate difference is correct. 8.5 in credit with no amount_currency
322 I check that my writeoff is correct. 4.75 debit and 5 amount_currency
324 !python {model: account.voucher}: |
325 voucher = self.search(cr, uid, [('name', '=', 'Second payment'), ('partner_id', '=', ref('res_partner_strauss0'))])
326 voucher_id = self.browse(cr, uid, voucher[0])
327 move_line_obj = self.pool.get('account.move.line')
328 move_lines = move_line_obj.search(cr, uid, [('move_id', '=', voucher_id.move_id.id)])
329 for move_line in move_line_obj.browse(cr, uid, move_lines):
330 if move_line.amount_currency == -20.00:
331 assert move_line.credit == 15.00, "Debtor account has wrong entry."
332 elif move_line.amount_currency == -30.00:
333 assert move_line.credit == 24.00, "Debtor account has wrong entry."
334 elif move_line.credit == 8.50:
335 assert move_line.amount_currency == 0.00, "Incorrect Currency Difference."
336 elif move_line.amount_currency == 5.00:
337 assert move_line.debit == 4.75, "Writeoff amount is wrong."
339 I check the residual amount of Invoice1, should be 0 in residual currency and 0 in amount_residual and paid
341 !python {model: account.invoice}: |
342 invoice_id = self.browse(cr, uid, ref("account_invoice_jan"))
343 move_line_obj = self.pool.get('account.move.line')
344 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)])
345 move_line = move_line_obj.browse(cr, uid, move_lines[0])
346 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"
348 I check the residual amuont of Invoice2, should be 0 in residual currency and 0 in amount_residual and paid
350 !python {model: account.invoice}: |
351 invoice_id = self.browse(cr, uid, ref("account_invoice_feb"))
352 move_line_obj = self.pool.get('account.move.line')
353 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)])
354 move_line = move_line_obj.browse(cr, uid, move_lines[0])
355 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"