2 In order to check the Account_voucher module with multi-currency in OpenERP,
3 I create 2 Invoices in USD and make 1 Payment in USD based on the currency rating given by the bank which is slightly different that the one encoded in OpenERP
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 currency USD in OpenERP for January of 1.333333 Rate
16 !python {model: res.currency.rate}: |
17 from datetime import datetime
18 curr_id = self.pool.get('res.currency').search(cr, uid, [('name', '=', 'USD')])[0]
19 date = '%s-01-01' %(datetime.now().year)
20 ids = self.search(cr, uid, [('currency_id','=',curr_id), ('name', '=', date)])
21 self.write(cr, uid, ids, {'rate': 1.333333})
23 I create currency USD in OpenERP for February of 1.250000 Rate
25 !record {model: res.currency.rate, id: feb_usd}:
27 name: !eval "'%s-02-01' %(datetime.now().year)"
31 I create currency USD in OpenERP for March of 1.111111 Rate
33 !record {model: res.currency.rate, id: mar_usd}:
35 name: !eval "'%s-03-01' %(datetime.now().year)"
39 I create currency USD in OpenERP for April of 1.052632 Rate
41 !record {model: res.currency.rate, id: apr_usd}:
43 name: !eval "'%s-04-01' %(datetime.now().year)"
47 I create a cash account with currency USD
49 !record {model: account.account, id: account_cash_usd_id}:
51 name: "cash account in usd"
54 user_type: "account.data_account_type_cash"
57 I create a bank journal with USD as currency
59 !record {model: account.journal, id: bank_journal_USD}:
60 name: Bank Journal(USD)
63 analytic_journal_id: analytic.sit
64 sequence_id: account.sequence_bank_journal
65 default_debit_account_id: account_cash_usd_id
66 default_credit_account_id: account_cash_usd_id
68 company_id: base.main_company
71 I create a new partner Kate Mc Kay
73 !record {model: res.partner, id: res_partner_mc_kay}:
75 property_account_receivable: account.a_recv
76 property_account_payable: account.a_pay
78 I create the first invoice on 1st January for 200 USD
80 !record {model: account.invoice, id: account_invoice_jan_payment_rate}:
81 account_id: account.a_recv
82 company_id: base.main_company
84 date_invoice: !eval "'%s-01-01' %(datetime.now().year)"
85 period_id: account.period_1
87 - account_id: account.a_sale
88 name: '[PCSC234] PC Assemble SC234'
91 product_id: product.product_product_3
92 uos_id: product.product_uom_unit
93 journal_id: account.sales_journal
94 partner_id: res_partner_mc_kay
97 I Validate invoice by clicking on Validate button
99 !workflow {model: account.invoice, action: invoice_open, ref: account_invoice_jan_payment_rate}
101 I check that first invoice move is correct for debtor account (debit - credit == 150.0)
103 !python {model: account.invoice}: |
104 from openerp.tools import float_compare
105 invoice_id = self.browse(cr, uid, ref("account_invoice_jan_payment_rate"))
106 assert invoice_id.move_id, "Move not created for open invoice"
107 move_line_obj = self.pool.get('account.move.line')
108 move_lines = move_line_obj.search(cr, uid, [('move_id', '=', invoice_id.move_id.id), ('account_id', '=', invoice_id.account_id.id)])
109 move_line = move_line_obj.browse(cr, uid, move_lines[0])
110 assert (float_compare(move_line.debit - move_line.credit, 150.0, precision_digits=2) == 0), "Invoice move is not correct for debtors account"
112 I create the second invoice on 1st February for 100 USD
114 !record {model: account.invoice, id: account_invoice_feb_payment_rate}:
115 account_id: account.a_recv
116 company_id: base.main_company
117 currency_id: base.USD
118 date_invoice: !eval "'%s-02-01' %(datetime.now().year)"
119 period_id: account.period_2
121 - account_id: account.a_sale
122 name: '[PCSC234] PC Assemble SC234'
125 product_id: product.product_product_3
126 uos_id: product.product_uom_unit
127 journal_id: account.sales_journal
128 partner_id: res_partner_mc_kay
131 I Validate invoice by clicking on Validate button
133 !workflow {model: account.invoice, action: invoice_open, ref: account_invoice_feb_payment_rate}
135 I check that second invoice move is correct for debtor account (debit - credit == 80)
137 !python {model: account.invoice}: |
138 from openerp.tools import float_compare
139 invoice_id = self.browse(cr, uid, ref("account_invoice_feb_payment_rate"))
140 assert invoice_id.move_id, "Move not created for open invoice"
141 move_line_obj = self.pool.get('account.move.line')
142 move_lines = move_line_obj.search(cr, uid, [('move_id', '=', invoice_id.move_id.id), ('account_id', '=', invoice_id.account_id.id)])
143 move_line = move_line_obj.browse(cr, uid, move_lines[0])
144 assert (float_compare(move_line.debit - move_line.credit, 80, precision_digits=2) == 0), "Invoice move is not correct for debtors account"
147 I set the context that will be used for the encoding of all the vouchers of this file
152 On the first March, I create the first voucher of payment with values 240 USD, journal USD, and specifying that $1 = 0.8€
154 !record {model: account.voucher, id: account_voucher_1_case1_payment_rate, view: view_vendor_receipt_form}:
155 account_id: account.cash
157 company_id: base.main_company
158 journal_id: bank_journal_USD
159 name: 'Payment: Case 1 USD/USD payment rate'
160 partner_id: res_partner_mc_kay
161 period_id: account.period_3
162 date: !eval time.strftime("%Y-03-01")
163 payment_option: 'with_writeoff'
164 writeoff_acc_id: account.a_expense
167 payment_rate_currency_id: base.EUR
170 I fill amounts 180 for the invoice of 200$ and 70 for the invoice of 100$>
172 !python {model: account.voucher}: |
173 from openerp.tools import float_compare
175 voucher_id = self.browse(cr, uid, ref('account_voucher_1_case1_payment_rate'))
177 for item in voucher_id.line_cr_ids:
178 if float_compare(item.amount_unreconciled, 200.00, precision_digits=2) == 0:
179 data += [(item.id, 180.0)]
181 data += [(item.id, 70.0)]
182 for line_id, amount in data:
183 self.pool.get('account.voucher.line').write(cr, uid, [line_id], {'amount': amount})
184 assert (voucher_id.state=='draft'), "Voucher is not in draft state"
186 I check that writeoff amount computed is -10.0
188 !python {model: account.voucher}: |
189 from openerp.tools import float_compare
190 voucher = ref('account_voucher_1_case1_payment_rate')
191 voucher_id = self.browse(cr, uid, voucher)
192 assert (float_compare(voucher_id.writeoff_amount, -10.0, precision_digits=2) == 0), "Writeoff amount is not -10.0"
194 I confirm the voucher
196 !python {model: account.voucher}: |
197 voucher = ref('account_voucher_1_case1_payment_rate')
198 self.signal_workflow(cr, uid, [voucher], 'proforma_voucher')
200 I check that the move of my first voucher is valid
202 !python {model: account.voucher}: |
203 voucher = ref('account_voucher_1_case1_payment_rate')
204 voucher_id = self.browse(cr, uid, voucher)
205 move_line_obj = self.pool.get('account.move.line')
206 move_lines = move_line_obj.search(cr, uid, [('move_id', '=', voucher_id.move_id.id)])
207 for move_line in move_line_obj.browse(cr, uid, move_lines):
208 assert move_line.state == 'valid', "Voucher move is not valid"
210 I check that my debtor account is correct
212 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 144 and 56
214 I check that my write-off is correct. 8 debit and 10 amount_currency
216 !python {model: account.voucher}: |
217 from openerp.tools import float_compare
218 voucher = ref('account_voucher_1_case1_payment_rate')
219 voucher_id = self.browse(cr, uid, voucher)
220 move_line_obj = self.pool.get('account.move.line')
221 move_lines = move_line_obj.search(cr, uid, [('move_id', '=', voucher_id.move_id.id)])
222 for move_line in move_line_obj.browse(cr, uid, move_lines):
223 if float_compare(move_line.amount_currency, -180.00, precision_digits=2) == 0:
224 assert float_compare(move_line.credit, 144.00, precision_digits=2) == 0, "Debtor account has wrong entry."
225 elif float_compare(move_line.amount_currency, -70.00, precision_digits=2) == 0:
226 assert float_compare(move_line.credit, 56.00, precision_digits=2) == 0, "Debtor account has wrong entry."
227 elif float_compare(move_line.amount_currency, 10.00, precision_digits=2) == 0:
228 assert float_compare(move_line.debit, 8.00, precision_digits=2) == 0, "Writeoff amount is wrong: Got a debit of %s (expected 8,00€)" % (move_line.debit)
229 elif float_compare(move_line.amount_currency, 240.00, precision_digits=2) == 0:
230 assert float_compare(move_line.debit, 192.00, precision_digits=2) == 0, "Bank entry is wrong."
232 assert False, "Unrecognized journal entry"
234 I check the residual amount of Invoice1, should be 20 in amount_currency and 6 in amount_residual
236 !python {model: account.invoice}: |
237 from openerp.tools import float_compare
238 invoice_id = self.browse(cr, uid, ref("account_invoice_jan_payment_rate"))
239 move_line_obj = self.pool.get('account.move.line')
240 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)])
241 move_line = move_line_obj.browse(cr, uid, move_lines[0])
242 assert (float_compare(move_line.amount_residual, 6.0, precision_digits=2) == 0) , "Residual amount is not correct for first Invoice"
243 assert (float_compare(move_line.amount_residual_currency, 20.0, precision_digits=2) == 0) , "Residual amount in currency is not correct for first Invoice"
245 I check the residual amuont of Invoice2, should be 30 in residual currency and 24 in amount_residual
247 !python {model: account.invoice}: |
248 from openerp.tools import float_compare
249 invoice_id = self.browse(cr, uid, ref("account_invoice_feb_payment_rate"))
250 move_line_obj = self.pool.get('account.move.line')
251 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)])
252 move_line = move_line_obj.browse(cr, uid, move_lines[0])
253 assert (float_compare(move_line.amount_residual, 24.0, precision_digits=2) == 0) , "Residual amount is not correct for second Invoice"
254 assert (float_compare(move_line.amount_residual_currency, 30.0, precision_digits=2) == 0) , "Residual amount in currency is not correct for second Invoice"