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 create a bank journal with EUR as currency
16 !record {model: account.journal, id: bank_journal_EUR}:
17 name: Bank Journal(EUR)
20 analytic_journal_id: account.sit
21 sequence_id: account.sequence_bank_journal
22 default_debit_account_id: account.cash
23 default_credit_account_id: account.cash
25 company_id: base.main_company
27 I create a bank journal with USD as currency
29 !record {model: account.journal, id: bank_journal_USD}:
30 name: Bank Journal(USD)
33 analytic_journal_id: account.sit
34 sequence_id: account.sequence_bank_journal
35 default_debit_account_id: account.cash
36 default_credit_account_id: account.cash
38 company_id: base.main_company
40 I create the first invoice on 1st January for 200 USD
42 !record {model: account.invoice, id: account_first_invoice_jan_suppl}:
43 account_id: account.a_pay
45 company_id: base.main_company
47 date_invoice: !eval "'%s-01-01' %(datetime.now().year)"
48 period_id: account.period_1
50 - account_id: account.a_expense
51 name: '[PCSC234] PC Assemble SC234'
54 product_id: product.product_product_3
55 uos_id: product.product_uom_unit
56 journal_id: account.sales_journal
57 partner_id: base.res_partner_19
61 I Validate invoice by clicking on Validate button
63 !workflow {model: account.invoice, action: invoice_open, ref: account_first_invoice_jan_suppl}
65 I check that first invoice move is correct for debtor account(debit - credit == -150)
67 !python {model: account.invoice}: |
68 invoice_id = self.browse(cr, uid, ref("account_first_invoice_jan_suppl"))
69 assert invoice_id.move_id, "Move not created for open invoice"
70 move_line_obj = self.pool.get('account.move.line')
71 move_lines = move_line_obj.search(cr, uid, [('move_id', '=', invoice_id.move_id.id), ('account_id', '=', invoice_id.account_id.id)])
72 move_line = move_line_obj.browse(cr, uid, move_lines[0])
73 assert (move_line.debit - move_line.credit == -150.00), "Invoice move is incorrect for debtors account"
75 I create the second invoice on 1st February for 100 USD
77 !record {model: account.invoice, id: account_second_invoice_feb_suppl}:
78 account_id: account.a_pay
79 company_id: base.main_company
81 date_invoice: !eval "'%s-02-01' %(datetime.now().year)"
82 period_id: account.period_2
85 - account_id: account.a_expense
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
96 I Validate invoice by clicking on Validate button
98 !workflow {model: account.invoice, action: invoice_open, ref: account_second_invoice_feb_suppl}
100 I check that second invoice move is correct for debtor account (debit - credit == -80)
102 !python {model: account.invoice}: |
103 invoice_id = self.browse(cr, uid, ref("account_second_invoice_feb_suppl"))
104 assert invoice_id.move_id, "Move not created for open invoice"
105 move_line_obj = self.pool.get('account.move.line')
106 move_lines = move_line_obj.search(cr, uid, [('move_id', '=', invoice_id.move_id.id), ('account_id', '=', invoice_id.account_id.id)])
107 move_line = move_line_obj.browse(cr, uid, move_lines[0])
108 assert (move_line.debit - move_line.credit == -80), "Invoice move is incorrect for debtors account"
110 I set the context that will be used for the encoding of all the vouchers of this file
115 I create the first voucher of payment with values 240 EUR, journal EUR
117 !record {model: account.voucher, id: account_voucher_1_case2_suppl, view: view_vendor_payment_form}:
118 account_id: account.cash
120 company_id: base.main_company
121 journal_id: bank_journal_EUR
122 name: 'First payment: Case 2 SUPPL USD/EUR',
123 partner_id: base.res_partner_19
124 period_id: account.period_3
125 date: !eval time.strftime("%Y-03-01")
126 payment_option: 'with_writeoff'
127 writeoff_acc_id: account.a_expense
131 I fill amounts 180 for the invoice of 200$ and 70 for the invoice of 100$
133 !python {model: account.voucher}: |
135 voucher_id = self.browse(cr, uid, ref('account_voucher_1_case2_suppl'))
137 for item in voucher_id.line_cr_ids:
138 if item.amount_unreconciled == 200.00:
139 data += [(item.id, 180.0)]
141 data += [(item.id, 70.0)]
142 for line_id, amount in data:
143 self.pool.get('account.voucher.line').write(cr, uid, [line_id], {'amount': amount})
144 assert (voucher_id.state=='draft'), "Voucher is not in draft state"
146 I check that writeoff amount computed is -15.0
148 !python {model: account.voucher}: |
149 voucher = self.search(cr, uid, [('name', '=', 'First payment: Case 2 SUPPL USD/EUR'), ('partner_id', '=', ref('base.res_partner_19'))])
150 voucher_id = self.browse(cr, uid, voucher[0])
151 assert (voucher_id.writeoff_amount == -15.0), "Writeoff amount is not -15.0"
153 I check that currency rate difference is 34.0
155 !python {model: account.voucher}: |
156 voucher = self.search(cr, uid, [('name', '=', 'First payment: Case 2 SUPPL USD/EUR'), ('partner_id', '=', ref('base.res_partner_19'))])
157 voucher_id = self.browse(cr, uid, voucher[0])
158 assert (voucher_id.currency_rate_difference == 34.0), "Currency rate difference is not 34.0"
160 I confirm the voucher
162 !python {model: account.voucher}: |
163 voucher = self.search(cr, uid, [('name', '=', 'First payment: Case 2 SUPPL USD/EUR'), ('partner_id', '=', ref('base.res_partner_19'))])
164 self.signal_proforma_voucher(cr, uid, voucher)
166 I check that the move of my voucher is valid
168 !python {model: account.voucher}: |
169 voucher = self.search(cr, uid, [('name', '=', 'First payment: Case 2 SUPPL USD/EUR'), ('partner_id', '=', ref('base.res_partner_19'))])
170 voucher_id = self.browse(cr, uid, voucher[0])
171 move_line_obj = self.pool.get('account.move.line')
172 move_lines = move_line_obj.search(cr, uid, [('move_id', '=', voucher_id.move_id.id)])
173 for move_line in move_line_obj.browse(cr, uid, move_lines):
174 assert move_line.state == 'valid', "Voucher move is not valid"
176 I check that my creditor account is correct
178 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($).
180 I check that my currency rate difference is correct. -34 in credit with no amount_currency
182 I check that my writeoff is correct. -15 in credit with no amount_currency
184 !python {model: account.voucher}: |
185 voucher = self.search(cr, uid, [('name', '=', 'First payment: Case 2 SUPPL USD/EUR'), ('partner_id', '=', ref('base.res_partner_19'))])
186 voucher_id = self.browse(cr, uid, voucher[0])
187 move_line_obj = self.pool.get('account.move.line')
188 move_lines = move_line_obj.search(cr, uid, [('move_id', '=', voucher_id.move_id.id)])
189 for move_line in move_line_obj.browse(cr, uid, move_lines):
190 if move_line.amount_currency == 180.00:
191 assert move_line.debit == 135.00, "Creditor account has wrong entry."
192 elif move_line.amount_currency == 70.00:
193 assert move_line.debit == 56.00, "Debtor account has wrong entry."
194 elif move_line.debit == 34.00:
195 assert move_line.amount_currency == 0.00, "Incorrect Currency Difference."
196 elif move_line.debit == 15.00:
197 assert move_line.amount_currency == 0.00, "Writeoff amount is wrong."
199 I check the residual amount of Invoice1, should be 20 in residual currency and 15 in amount_residual
201 !python {model: account.invoice}: |
202 invoice_id = self.browse(cr, uid, ref("account_first_invoice_jan_suppl"))
203 move_line_obj = self.pool.get('account.move.line')
204 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)])
205 move_line = move_line_obj.browse(cr, uid, move_lines[0])
206 assert (move_line.amount_residual_currency == 20.0 and move_line.amount_residual == 15) , "Residual amount is not correct for first Invoice"
208 I check the residual amuont of Invoice2, should be 30 in residual currency and 24 in amount_residual
210 !python {model: account.invoice}: |
211 invoice_id = self.browse(cr, uid, ref("account_second_invoice_feb_suppl"))
212 move_line_obj = self.pool.get('account.move.line')
213 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)])
214 move_line = move_line_obj.browse(cr, uid, move_lines[0])
215 assert (move_line.amount_residual_currency == 30 and move_line.amount_residual == 24) , "Residual amount is not correct for second Invoice"
217 I create the second voucher of payment with values 45 USD, journal USD,
219 !record {model: account.voucher, id: account_voucher_2_case2_suppl, view: view_vendor_payment_form}:
220 account_id: account.cash
222 company_id: base.main_company
223 journal_id: bank_journal_USD
224 partner_id: base.res_partner_19
225 period_id: account.period_3
226 date: !eval time.strftime("%Y-04-01")
227 payment_option: 'with_writeoff'
228 writeoff_acc_id: account.a_expense
230 name: 'Second payment: Case 2 SUPPL USD/EUR'
233 I fill amounts 20 for the invoice of 200$ and 30 for the invoice of 100$>
235 !python {model: account.voucher}: |
237 voucher_id = self.browse(cr, uid, ref('account_voucher_2_case2_suppl'))
239 for item in voucher_id.line_cr_ids:
240 if item.amount_unreconciled == 20.00:
241 data += [(item.id, 20.0)]
243 data += [(item.id, 30.0)]
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 -5.0
250 !python {model: account.voucher}: |
251 voucher = self.search(cr, uid, [('name', '=', 'Second payment: Case 2 SUPPL USD/EUR'), ('partner_id', '=', ref('base.res_partner_19'))])
252 voucher_id = self.browse(cr, uid, voucher[0])
253 assert (voucher_id.writeoff_amount == 5.0), "Writeoff amount is not 5.0"
255 I check that currency rate difference is 8.50
257 !python {model: account.voucher}: |
258 voucher = self.search(cr, uid, [('name', '=', 'Second payment: Case 2 SUPPL USD/EUR'), ('partner_id', '=', ref('base.res_partner_19'))])
259 voucher_id = self.browse(cr, uid, voucher[0])
260 assert (voucher_id.currency_rate_difference == 8.50), "Currency rate difference is not 8.50"
262 I confirm the voucher
264 !python {model: account.voucher}: |
265 voucher = self.search(cr, uid, [('name', '=', 'Second payment: Case 2 SUPPL USD/EUR'), ('partner_id', '=', ref('base.res_partner_19'))])
266 self.signal_proforma_voucher(cr, uid, voucher)
268 I check that my voucher state is posted
270 !python {model: account.voucher}: |
271 voucher = self.search(cr, uid, [('name', '=', 'Second payment: Case 2 SUPPL USD/EUR'), ('partner_id', '=', ref('base.res_partner_19'))])
272 voucher_id = self.browse(cr, uid, voucher[0])
273 assert voucher_id.state == 'posted', "Voucher state is not posted"
275 I check that my creditor account is correct
277 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($).
279 I check that my currency rate difference is correct. 8.50 in debit with no amount_currency
281 I check that my writeoff is correct. 4.75 in credit and 5 in amount_currency
283 !python {model: account.voucher}: |
284 voucher = self.search(cr, uid, [('name', '=', 'Second payment: Case 2 SUPPL USD/EUR'), ('partner_id', '=', ref('base.res_partner_19'))])
285 voucher_id = self.browse(cr, uid, voucher[0])
286 move_line_obj = self.pool.get('account.move.line')
287 move_lines = move_line_obj.search(cr, uid, [('move_id', '=', voucher_id.move_id.id)])
288 for move_line in move_line_obj.browse(cr, uid, move_lines):
289 if move_line.amount_currency == 20.00:
290 assert move_line.debit == 15.00, "Debtor account has wrong entry."
291 elif move_line.amount_currency == 30.00:
292 assert move_line.debit == 24.00, "Debtor account has wrong entry."
293 elif move_line.debit == 8.50:
294 assert move_line.amount_currency == 0.00, "Incorrect Currency Difference."
295 elif move_line.amount_currency == -5.00:
296 assert move_line.credit == 4.75, "Writeoff amount is wrong."
298 I check the residual amount of invoice 1, should be 0 in residual currency and 0 in amount_residual and paid
300 !python {model: account.invoice}: |
301 invoice_id = self.browse(cr, uid, ref("account_first_invoice_jan_suppl"))
302 move_line_obj = self.pool.get('account.move.line')
303 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)])
304 move_line = move_line_obj.browse(cr, uid, move_lines[0])
305 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"
307 I check the residual amount of invoice 2, should be 0 in residual currency and 0 in amount_residual and paid
309 !python {model: account.invoice}: |
310 invoice_id = self.browse(cr, uid, ref("account_second_invoice_feb_suppl"))
311 move_line_obj = self.pool.get('account.move.line')
312 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)])
313 move_line = move_line_obj.browse(cr, uid, move_lines[0])
314 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"