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 create a bank journal with EUR as currency
7 !record {model: account.journal, id: bank_journal_EUR}:
8 name: Bank Journal(EUR)
11 analytic_journal_id: account.sit
12 sequence_id: account.sequence_bank_journal
13 default_debit_account_id: account.cash
14 default_credit_account_id: account.cash
16 company_id: base.main_company
17 view_id: account.account_journal_bank_view
19 I create a bank journal with USD as currency
21 !record {model: account.journal, id: bank_journal_USD}:
22 name: Bank Journal(USD)
25 analytic_journal_id: account.sit
26 sequence_id: account.sequence_bank_journal
27 default_debit_account_id: account.cash
28 default_credit_account_id: account.cash
30 company_id: base.main_company
31 view_id: account.account_journal_bank_view
33 I create the first invoice on 1st January for 200 USD
35 !record {model: account.invoice, id: account_first_invoice_jan_suppl}:
36 account_id: account.a_pay
38 address_contact_id: base.res_partner_address_3000
39 address_invoice_id: base.res_partner_address_3000
40 company_id: base.main_company
42 date_invoice: !eval "'%s-01-01' %(datetime.now().year)"
43 period_id: account.period_1
45 - account_id: account.a_expense
46 name: '[PC1] Basic PC'
49 product_id: product.product_product_pc1
50 uos_id: product.product_uom_unit
51 journal_id: account.sales_journal
52 partner_id: base.res_partner_seagate
56 I Validate invoice by clicking on Validate button
58 !workflow {model: account.invoice, action: invoice_open, ref: account_first_invoice_jan_suppl}
60 I check that first invoice move is correct for debtor account(debit - credit == -150)
62 !python {model: account.invoice}: |
63 invoice_id = self.browse(cr, uid, ref("account_first_invoice_jan_suppl"))
64 assert invoice_id.move_id, "Move not created for open invoice"
65 move_line_obj = self.pool.get('account.move.line')
66 move_lines = move_line_obj.search(cr, uid, [('move_id', '=', invoice_id.move_id.id), ('account_id', '=', invoice_id.account_id.id)])
67 move_line = move_line_obj.browse(cr, uid, move_lines[0])
68 assert (move_line.debit - move_line.credit == -150.00), "Invoice move is incorrect for debtors account"
70 I create the second invoice on 1st February for 100 USD
72 !record {model: account.invoice, id: account_second_invoice_feb_suppl}:
73 account_id: account.a_pay
74 address_contact_id: base.res_partner_address_3000
75 address_invoice_id: base.res_partner_address_3000
76 company_id: base.main_company
78 date_invoice: !eval "'%s-02-01' %(datetime.now().year)"
79 period_id: account.period_2
82 - account_id: account.a_expense
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: base.res_partner_seagate
93 I Validate invoice by clicking on Validate button
95 !workflow {model: account.invoice, action: invoice_open, ref: account_second_invoice_feb_suppl}
97 I check that second invoice move is correct for debtor account (debit - credit == -80)
99 !python {model: account.invoice}: |
100 invoice_id = self.browse(cr, uid, ref("account_second_invoice_feb_suppl"))
101 assert invoice_id.move_id, "Move not created for open invoice"
102 move_line_obj = self.pool.get('account.move.line')
103 move_lines = move_line_obj.search(cr, uid, [('move_id', '=', invoice_id.move_id.id), ('account_id', '=', invoice_id.account_id.id)])
104 move_line = move_line_obj.browse(cr, uid, move_lines[0])
105 assert (move_line.debit - move_line.credit == -80), "Invoice move is incorrect for debtors account"
107 I create the first voucher of payment
108 <create with values 240 EUR, journal EUR, and fills amount 180 for the invoice of 200$ and 70 for the invoice of 100$>
110 !python {model: account.voucher}: |
113 res = self.onchange_partner_id(cr, uid, [], ref("base.res_partner_seagate"), ref('bank_journal_EUR'), 240.0, 2, ttype='payment', date=False)
115 'account_id': ref('account.cash'),
117 'company_id': ref('base.main_company'),
118 'currency_id': ref('base.EUR'),
119 'journal_id': ref('bank_journal_EUR'),
120 'partner_id': ref('base.res_partner_seagate'),
121 'period_id': ref('account.period_3'),
123 'date': time.strftime("%Y-03-01"),
124 'payment_option': 'with_writeoff',
125 'writeoff_acc_id': ref('account.a_expense'),
126 'comment': 'Write Off',
127 'name': 'First payment: Case 2 SUPPL USD/EUR',
129 if not res['value']['line_dr_ids']:
130 res['value']['line_dr_ids'] = [{'type': 'dr', 'account_id': ref('account.a_pay'),}]
131 for item in res['value']['line_dr_ids']:
132 if item['amount_unreconciled'] == 200.00:
133 item['amount'] = 180.00
135 item['amount'] = 70.00
136 vals['line_dr_ids'] = [(0,0,i) for i in res['value']['line_dr_ids']]
137 id = self.create(cr, uid, vals)
138 voucher_id = self.browse(cr, uid, id)
139 assert (voucher_id.state=='draft'), "Voucher is not in draft state"
141 I check that writeoff amount computed is -15.0
143 !python {model: account.voucher}: |
144 voucher = self.search(cr, uid, [('name', '=', 'First payment: Case 2 SUPPL USD/EUR'), ('partner_id', '=', ref('base.res_partner_seagate'))])
145 voucher_id = self.browse(cr, uid, voucher[0])
146 assert (voucher_id.writeoff_amount == -15.0), "Writeoff amount is not -15.0"
148 I check that currency rate difference is 34.0
150 !python {model: account.voucher}: |
151 voucher = self.search(cr, uid, [('name', '=', 'First payment: Case 2 SUPPL USD/EUR'), ('partner_id', '=', ref('base.res_partner_seagate'))])
152 voucher_id = self.browse(cr, uid, voucher[0])
153 assert (voucher_id.currency_rate_difference == 34.0), "Currency rate difference is not 34.0"
155 I confirm the voucher
157 !python {model: account.voucher}: |
159 voucher = self.search(cr, uid, [('name', '=', 'First payment: Case 2 SUPPL USD/EUR'), ('partner_id', '=', ref('base.res_partner_seagate'))])
160 wf_service = netsvc.LocalService("workflow")
161 wf_service.trg_validate(uid, 'account.voucher', voucher[0], 'proforma_voucher', cr)
163 I check that the move of my voucher is valid
165 !python {model: account.voucher}: |
166 voucher = self.search(cr, uid, [('name', '=', 'First payment: Case 2 SUPPL USD/EUR'), ('partner_id', '=', ref('base.res_partner_seagate'))])
167 voucher_id = self.browse(cr, uid, voucher[0])
168 move_line_obj = self.pool.get('account.move.line')
169 move_lines = move_line_obj.search(cr, uid, [('move_id', '=', voucher_id.move_id.id)])
170 for move_line in move_line_obj.browse(cr, uid, move_lines):
171 assert move_line.state == 'valid', "Voucher move is not valid"
173 I check that my creditor account is correct
175 I check that the creditor account has 2 new lines with 180 and 70 in amount_currency columns and their debit columns are respectively 135 and 56 and currency is USD($).
177 I check that my currency rate difference is correct. -34 in credit with no amount_currency
179 I check that my writeoff is correct. -15 in credit with no amount_currency
181 !python {model: account.voucher}: |
182 voucher = self.search(cr, uid, [('name', '=', 'First payment: Case 2 SUPPL USD/EUR'), ('partner_id', '=', ref('base.res_partner_seagate'))])
183 voucher_id = self.browse(cr, uid, voucher[0])
184 move_line_obj = self.pool.get('account.move.line')
185 move_lines = move_line_obj.search(cr, uid, [('move_id', '=', voucher_id.move_id.id)])
186 for move_line in move_line_obj.browse(cr, uid, move_lines):
187 if move_line.amount_currency == 180.00:
188 assert move_line.debit == 135.00, "Creditor account has wrong entry."
189 elif move_line.amount_currency == 70.00:
190 assert move_line.debit == 56.00, "Debtor account has wrong entry."
191 elif move_line.debit == 34.00:
192 assert move_line.amount_currency == 0.00, "Incorrect Currency Difference."
193 elif move_line.debit == 15.00:
194 assert move_line.amount_currency == 0.00, "Writeoff amount is wrong."
196 I check the residual amount of Invoice1, should be 20 in residual currency and 15 in amount_residual
198 !python {model: account.invoice}: |
199 invoice_id = self.browse(cr, uid, ref("account_first_invoice_jan_suppl"))
200 move_line_obj = self.pool.get('account.move.line')
201 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)])
202 move_line = move_line_obj.browse(cr, uid, move_lines[0])
203 assert (move_line.amount_residual_currency == 20.0 and move_line.amount_residual == 15) , "Residual amount is not correct for first Invoice"
205 I check the residual amuont of Invoice2, should be 30 in residual currency and 24 in amount_residual
207 !python {model: account.invoice}: |
208 invoice_id = self.browse(cr, uid, ref("account_second_invoice_feb_suppl"))
209 move_line_obj = self.pool.get('account.move.line')
210 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)])
211 move_line = move_line_obj.browse(cr, uid, move_lines[0])
212 assert (move_line.amount_residual_currency == 30 and move_line.amount_residual == 24) , "Residual amount is not correct for second Invoice"
214 I create the second voucher of payment
215 <create with values 45 USD, journal USD, and fill amounts 20 for the invoice of 200$ and 30 for the invoice of 100$>
217 !python {model: account.voucher}: |
220 res = self.onchange_partner_id(cr, uid, [], ref("base.res_partner_seagate"), ref('bank_journal_EUR'), 45.0, 2, ttype='payment', date=False)
222 'account_id': ref('account.cash'),
224 'company_id': ref('base.main_company'),
225 'currency_id': ref('base.USD'),
226 'journal_id': ref('bank_journal_USD'),
227 'partner_id': ref('base.res_partner_seagate'),
228 'period_id': ref('account.period_3'),
230 'date': time.strftime("%Y-%m-%d"),
231 'payment_option': 'with_writeoff',
232 'writeoff_acc_id': ref('account.a_expense'),
233 'comment': 'Write Off',
234 'name': 'Second payment: Case 2 SUPPL USD/EUR',
236 vals.update(self.onchange_date(cr, uid, [], time.strftime('%Y-04-01'), ref('base.USD'), 45.0)['value'])
237 if not res['value']['line_dr_ids']:
238 res['value']['line_dr_ids'] = [{'type': 'dr', 'account_id': ref('account.a_pay'),}]
239 for item in res['value']['line_dr_ids']:
240 if item['amount_unreconciled'] == 20.00:
241 item['amount'] = 20.00
243 item['amount'] = 30.00
244 vals['line_dr_ids'] = [(0,0,i) for i in res['value']['line_dr_ids']]
245 id = self.create(cr, uid, vals)
246 voucher_id = self.browse(cr, uid, id)
247 assert (voucher_id.state=='draft'), "Voucher is not in draft state"
249 I check that writeoff amount computed is -5.0
251 !python {model: account.voucher}: |
252 voucher = self.search(cr, uid, [('name', '=', 'Second payment: Case 2 SUPPL USD/EUR'), ('partner_id', '=', ref('base.res_partner_seagate'))])
253 voucher_id = self.browse(cr, uid, voucher[0])
254 assert (voucher_id.writeoff_amount == 5.0), "Writeoff amount is not 5.0"
256 I check that currency rate difference is 8.50
258 !python {model: account.voucher}: |
259 voucher = self.search(cr, uid, [('name', '=', 'Second payment: Case 2 SUPPL USD/EUR'), ('partner_id', '=', ref('base.res_partner_seagate'))])
260 voucher_id = self.browse(cr, uid, voucher[0])
261 assert (voucher_id.currency_rate_difference == 8.50), "Currency rate difference is not 8.50"
263 I confirm the voucher
265 !python {model: account.voucher}: |
267 voucher = self.search(cr, uid, [('name', '=', 'Second payment: Case 2 SUPPL USD/EUR'), ('partner_id', '=', ref('base.res_partner_seagate'))])
268 wf_service = netsvc.LocalService("workflow")
269 wf_service.trg_validate(uid, 'account.voucher', voucher[0], 'proforma_voucher', cr)
271 I check that my voucher state is posted
273 !python {model: account.voucher}: |
274 voucher = self.search(cr, uid, [('name', '=', 'Second payment: Case 2 SUPPL USD/EUR'), ('partner_id', '=', ref('base.res_partner_seagate'))])
275 voucher_id = self.browse(cr, uid, voucher[0])
276 assert voucher_id.state == 'posted', "Voucher state is not posted"
278 I check that my creditor account is correct
280 I check that the creditor account has 2 new lines with 20 and 30 in amount_currency columns and their debit columns are respectively 15 and 24 and currency is USD($).
282 I check that my currency rate difference is correct. 8.50 in debit with no amount_currency
284 I check that my writeoff is correct. 4.75 in credit and 5 in amount_currency
286 !python {model: account.voucher}: |
287 voucher = self.search(cr, uid, [('name', '=', 'Second payment: Case 2 SUPPL USD/EUR'), ('partner_id', '=', ref('base.res_partner_seagate'))])
288 voucher_id = self.browse(cr, uid, voucher[0])
289 move_line_obj = self.pool.get('account.move.line')
290 move_lines = move_line_obj.search(cr, uid, [('move_id', '=', voucher_id.move_id.id)])
291 for move_line in move_line_obj.browse(cr, uid, move_lines):
292 if move_line.amount_currency == 20.00:
293 assert move_line.debit == 15.00, "Debtor account has wrong entry."
294 elif move_line.amount_currency == 30.00:
295 assert move_line.debit == 24.00, "Debtor account has wrong entry."
296 elif move_line.debit == 8.50:
297 assert move_line.amount_currency == 0.00, "Incorrect Currency Difference."
298 elif move_line.amount_currency == -5.00:
299 assert move_line.credit == 4.75, "Writeoff amount is wrong."
301 I check the residual amount of invoice 1, should be 0 in residual currency and 0 in amount_residual and paid
303 !python {model: account.invoice}: |
304 invoice_id = self.browse(cr, uid, ref("account_first_invoice_jan_suppl"))
305 move_line_obj = self.pool.get('account.move.line')
306 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)])
307 move_line = move_line_obj.browse(cr, uid, move_lines[0])
308 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"
310 I check the residual amount of invoice 2, should be 0 in residual currency and 0 in amount_residual and paid
312 !python {model: account.invoice}: |
313 invoice_id = self.browse(cr, uid, ref("account_second_invoice_feb_suppl"))
314 move_line_obj = self.pool.get('account.move.line')
315 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)])
316 move_line = move_line_obj.browse(cr, uid, move_lines[0])
317 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"