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')])[0]
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 create the first invoice on 1st January for 200 USD
55 !record {model: account.invoice, id: account_invoice_jan}:
56 account_id: account.a_recv
57 address_contact_id: base.res_partner_address_3000
58 address_invoice_id: base.res_partner_address_3000
59 company_id: base.main_company
61 date_invoice: !eval "'%s-01-01' %(datetime.now().year)"
62 period_id: account.period_1
64 - account_id: account.a_sale
65 name: '[PC1] Basic PC'
68 product_id: product.product_product_pc1
69 uos_id: product.product_uom_unit
70 journal_id: account.sales_journal
71 partner_id: base.res_partner_seagate
74 I Validate invoice by clicking on Validate button
76 !workflow {model: account.invoice, action: invoice_open, ref: account_invoice_jan}
78 I check that first invoice move is correct for debtor account (debit - credit == 150.0)
80 !python {model: account.invoice}: |
81 invoice_id = self.browse(cr, uid, ref("account_invoice_jan"))
82 assert invoice_id.move_id, "Move not created for open invoice"
83 move_line_obj = self.pool.get('account.move.line')
84 move_lines = move_line_obj.search(cr, uid, [('move_id', '=', invoice_id.move_id.id), ('account_id', '=', invoice_id.account_id.id)])
85 move_line = move_line_obj.browse(cr, uid, move_lines[0])
86 assert (move_line.debit - move_line.credit == 150.0), "Invoice move is not correct for debtors account"
88 I create the second invoice on 1st February for 100 USD
90 !record {model: account.invoice, id: account_invoice_feb}:
91 account_id: account.a_recv
92 address_contact_id: base.res_partner_address_3000
93 address_invoice_id: base.res_partner_address_3000
94 company_id: base.main_company
96 date_invoice: !eval "'%s-02-01' %(datetime.now().year)"
97 period_id: account.period_2
99 - account_id: account.a_sale
100 name: '[PC1] Basic PC'
103 product_id: product.product_product_pc1
104 uos_id: product.product_uom_unit
105 journal_id: account.sales_journal
106 partner_id: base.res_partner_seagate
109 I Validate invoice by clicking on Validate button
111 !workflow {model: account.invoice, action: invoice_open, ref: account_invoice_feb}
113 I check that second invoice move is correct for debtor account (debit - credit == 80)
115 !python {model: account.invoice}: |
116 invoice_id = self.browse(cr, uid, ref("account_invoice_feb"))
117 assert invoice_id.move_id, "Move not created for open invoice"
118 move_line_obj = self.pool.get('account.move.line')
119 move_lines = move_line_obj.search(cr, uid, [('move_id', '=', invoice_id.move_id.id), ('account_id', '=', invoice_id.account_id.id)])
120 move_line = move_line_obj.browse(cr, uid, move_lines[0])
121 assert (move_line.debit - move_line.credit == 80), "Invoice move is not correct for debtors account"
124 I create the first voucher of payment
125 <create with values 240 USD, journal USD, and fill amounts 180 for the invoice of 200$ and 70 for the invoice of 100$>
127 !python {model: account.voucher}: |
130 res = self.onchange_partner_id(cr, uid, [], ref("base.res_partner_seagate"), ref('bank_journal_USD'), 240.00, 2, ttype='receipt', date=False)
132 'account_id': ref('account.cash'),
134 'company_id': ref('base.main_company'),
135 'currency_id': ref('base.USD'),
136 'journal_id': ref('bank_journal_USD'),
137 'partner_id': ref('base.res_partner_seagate'),
138 'period_id': ref('account.period_3'),
140 'date': time.strftime("%Y-%m-%d"),
141 'payment_option': 'with_writeoff',
142 'writeoff_acc_id': ref('account.a_expense'),
143 'comment': 'Write Off',
144 'name': 'First payment: Case 1 USD/USD',
146 vals.update(self.onchange_date(cr, uid, [], time.strftime('%Y-03-01'), ref('base.USD'), 240)['value'])
147 if not res['value']['line_cr_ids']:
148 res['value']['line_cr_ids'] = [{'type': 'cr', 'account_id': ref('account.a_recv'),}]
149 for item in res['value']['line_cr_ids']:
150 if item['amount_unreconciled'] == 200.00:
151 item['amount'] = 180.00
153 item['amount'] = 70.00
154 vals['line_cr_ids'] = [(0,0,i) for i in res['value']['line_cr_ids']]
155 id = self.create(cr, uid, vals)
156 voucher_id = self.browse(cr, uid, id)
157 assert (voucher_id.state=='draft'), "Voucher is not in draft state"
159 I check that writeoff amount computed is 10.0
161 !python {model: account.voucher}: |
162 voucher = self.search(cr, uid, [('name', '=', 'First payment: Case 1 USD/USD'), ('partner_id', '=', ref('base.res_partner_seagate'))])
163 voucher_id = self.browse(cr, uid, voucher[0])
164 assert (voucher_id.writeoff_amount == 10.0), "Writeoff amount is not 10.0"
166 I confirm the voucher
168 !python {model: account.voucher}: |
170 voucher = self.search(cr, uid, [('name', '=', 'First payment: Case 1 USD/USD'), ('partner_id', '=', ref('base.res_partner_seagate'))])
171 wf_service = netsvc.LocalService("workflow")
172 wf_service.trg_validate(uid, 'account.voucher', voucher[0], 'proforma_voucher', cr)
174 I check that the move of my first voucher is valid
176 !python {model: account.voucher}: |
177 voucher = self.search(cr, uid, [('name', '=', 'First payment: Case 1 USD/USD'), ('partner_id', '=', ref('base.res_partner_seagate'))])
178 voucher_id = self.browse(cr, uid, voucher[0])
179 move_line_obj = self.pool.get('account.move.line')
180 move_lines = move_line_obj.search(cr, uid, [('move_id', '=', voucher_id.move_id.id)])
181 for move_line in move_line_obj.browse(cr, uid, move_lines):
182 assert move_line.state == 'valid', "Voucher move is not valid"
184 I check that my debtor account is correct
186 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
188 I check that my write-off is correct. 9 debit and 10 amount_currency
190 !python {model: account.voucher}: |
191 voucher = self.search(cr, uid, [('name', '=', 'First payment: Case 1 USD/USD'), ('partner_id', '=', ref('base.res_partner_seagate'))])
192 voucher_id = self.browse(cr, uid, voucher[0])
193 move_line_obj = self.pool.get('account.move.line')
194 move_lines = move_line_obj.search(cr, uid, [('move_id', '=', voucher_id.move_id.id)])
195 for move_line in move_line_obj.browse(cr, uid, move_lines):
196 if move_line.amount_currency == -180.00:
197 assert move_line.credit == 162.00, "Debtor account has wrong entry."
198 elif move_line.amount_currency == -70.00:
199 assert move_line.credit == 63.00, "Debtor account has wrong entry."
200 elif move_line.amount_currency == 10.00:
201 assert move_line.debit == 9.00, "Writeoff amount is wrong."
203 I check the residual amount of Invoice1, should be 20 in amount_currency
205 !python {model: account.invoice}: |
206 invoice_id = self.browse(cr, uid, ref("account_invoice_jan"))
207 move_line_obj = self.pool.get('account.move.line')
208 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)])
209 move_line = move_line_obj.browse(cr, uid, move_lines[0])
210 assert (move_line.amount_residual_currency == 20.0) , "Residual amount is not correct for first Invoice"
212 I check the residual amuont of Invoice2, should be 30 in residual currency and 24 in amount_residual
214 !python {model: account.invoice}: |
215 invoice_id = self.browse(cr, uid, ref("account_invoice_feb"))
216 move_line_obj = self.pool.get('account.move.line')
217 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)])
218 move_line = move_line_obj.browse(cr, uid, move_lines[0])
219 assert (move_line.amount_residual_currency == 30.0) , "Residual amount is not correct for first Invoice"
221 I create the second voucher of payment
222 <create with values 45 USD, journal USD, and fill amounts 20 for the invoice of 200$ and 30 for the invoice of 100$>
225 !python {model: account.voucher}: |
228 res = self.onchange_partner_id(cr, uid, [], ref("base.res_partner_seagate"), ref('bank_journal_USD'), 45.00, 2, ttype='receipt', date=False)
230 'account_id': ref('account.cash'),
232 'exchange_acc_id': ref('account.o_expense'),
233 'company_id': ref('base.main_company'),
234 'currency_id': ref('base.USD'),
235 'journal_id': ref('bank_journal_USD'),
236 'partner_id': ref('base.res_partner_seagate'),
237 'period_id': ref('account.period_3'),
239 'date': time.strftime("%Y-%m-%d"),
240 'payment_option': 'with_writeoff',
241 'writeoff_acc_id': ref('account.a_expense'),
242 'comment': 'Write Off',
243 'name': 'Second payment: Case 1',
245 vals.update(self.onchange_date(cr, uid, [], time.strftime('%Y-04-01'), ref('base.USD'), 45.0)['value'])
246 if not res['value']['line_cr_ids']:
247 res['value']['line_cr_ids'] = [{'type': 'cr', 'account_id': ref('account.a_recv'),}]
248 for item in res['value']['line_cr_ids']:
249 if item['amount_unreconciled'] == 20.00:
250 item['amount'] = 20.00
252 item['amount'] = 30.00
253 vals['line_cr_ids'] = [(0,0,i) for i in res['value']['line_cr_ids']]
254 id = self.create(cr, uid, vals)
255 voucher_id = self.browse(cr, uid, id)
256 assert (voucher_id.state=='draft'), "Voucher is not in draft state"
258 I check that writeoff amount computed is 5.0
260 !python {model: account.voucher}: |
261 voucher = self.search(cr, uid, [('name', '=', 'Second payment: Case 1'), ('partner_id', '=', ref('base.res_partner_seagate'))])
262 voucher_id = self.browse(cr, uid, voucher[0])
263 assert (voucher_id.writeoff_amount == 5.0), "Writeoff amount is not 5.0"
265 I confirm the voucher
267 !python {model: account.voucher}: |
269 voucher = self.search(cr, uid, [('name', '=', 'Second payment: Case 1'), ('partner_id', '=', ref('base.res_partner_seagate'))])
270 wf_service = netsvc.LocalService("workflow")
271 wf_service.trg_validate(uid, 'account.voucher', voucher[0], 'proforma_voucher', cr)
273 I check that the move of my second voucher is valid
275 !python {model: account.voucher}: |
276 voucher = self.search(cr, uid, [('name', '=', 'Second payment: Case 1'), ('partner_id', '=', ref('base.res_partner_seagate'))])
277 voucher_id = self.browse(cr, uid, voucher[0])
278 move_line_obj = self.pool.get('account.move.line')
279 move_lines = move_line_obj.search(cr, uid, [('move_id', '=', voucher_id.move_id.id)])
280 for move_line in move_line_obj.browse(cr, uid, move_lines):
281 assert move_line.state == 'valid', "Voucher move is not valid"
283 I check that my debtor account is correct
285 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
287 I check that my currency rate difference is correct. 8.5 in credit with no amount_currency
289 I check that the total reconcilation created entries as expected
291 I check that my writeoff is correct. 4.75 debit and 5 amount_currency
293 !python {model: account.voucher}: |
294 voucher = self.search(cr, uid, [('name', '=', 'Second payment: Case 1'), ('partner_id', '=', ref('base.res_partner_seagate'))])
295 voucher_id = self.browse(cr, uid, voucher[0])
296 move_line_obj = self.pool.get('account.move.line')
297 move_lines = move_line_obj.search(cr, uid, [('move_id', '=', voucher_id.move_id.id)])
298 reconcile_a = reconcile_b = False
299 for move_line in move_line_obj.browse(cr, uid, move_lines):
300 if move_line.amount_currency == -20.00:
301 assert move_line.reconcile_id.id, "The invoice of 200$ is not fully reconciled"
302 reconcile_b = move_line.reconcile_id.id
303 elif move_line.amount_currency == -30.00:
304 assert move_line.reconcile_id.id, "The invoice of 100$ is not fully reconciled"
305 reconcile_a = move_line.reconcile_id.id
306 for move_line in move_line_obj.browse(cr, uid, move_lines):
307 if move_line.amount_currency == -20.00:
308 assert move_line.credit == 19.00, "Debtor account has wrong entry."
309 elif move_line.amount_currency == -30.00:
310 assert move_line.credit == 28.50, "Debtor account has wrong entry."
311 elif move_line.amount_currency == 5.00:
312 assert move_line.debit == 4.75, "Writeoff amount is wrong."
313 elif move_line.debit == 11.5 and move_line.account_id.reconcile:
314 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"
315 elif move_line.debit == 31.0 and move_line.account_id.reconcile:
316 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"
318 I check the residual amount of Invoice1, should be 0 in residual currency and 0 in amount_residual and paid
320 !python {model: account.invoice}: |
321 invoice_id = self.browse(cr, uid, ref("account_invoice_jan"))
322 move_line_obj = self.pool.get('account.move.line')
323 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)])
324 move_line = move_line_obj.browse(cr, uid, move_lines[0])
325 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"
327 I check the residual amuont of Invoice2, should be 0 in residual currency and 0 in amount_residual and paid
329 !python {model: account.invoice}: |
330 invoice_id = self.browse(cr, uid, ref("account_invoice_feb"))
331 move_line_obj = self.pool.get('account.move.line')
332 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)])
333 move_line = move_line_obj.browse(cr, uid, move_lines[0])
334 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"