2 In order to check the Account_voucher module with multi-currency in OpenERP,
3 I create an invoice in CAD and make its Payment in CHF 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 currency CAD in OpenERP for January of 1.338800 Rate
16 !record {model: res.currency.rate, id: jan_cad}:
18 name: !eval "'%s-01-01' %(datetime.now().year)"
21 I create currency CAD in OpenERP for March of 2.000000 Rate
23 !record {model: res.currency.rate, id: mar_cad}:
25 name: !eval "'%s-03-01' %(datetime.now().year)"
28 I create currency CHF in OpenERP for January of 1.308600 Rate
30 !record {model: res.currency.rate, id: jan_chf}:
32 name: !eval "'%s-01-01' %(datetime.now().year)"
35 I create currency CHF in OpenERP for March of 1.250000 Rate
37 !record {model: res.currency.rate, id: mar_chf}:
39 name: !eval "'%s-03-01' %(datetime.now().year)"
42 I create a cash account with currency CHF
44 !record {model: account.account, id: account_cash_chf_id}:
46 name: "cash account in chf"
49 user_type: "account.data_account_type_cash"
52 I create a bank journal with CHF as currency
54 !record {model: account.journal, id: bank_journal_CHF}:
55 name: Bank Journal(CHF)
58 analytic_journal_id: analytic.sit
59 sequence_id: account.sequence_bank_journal
60 default_debit_account_id: account_cash_chf_id
61 default_credit_account_id: account_cash_chf_id
63 company_id: base.main_company
65 I create the first invoice on 1st January for 200 CAD
67 !record {model: account.invoice, id: account_first_invoice_jan_cad}:
68 account_id: account.a_recv
69 company_id: base.main_company
71 date_invoice: !eval "'%s-01-01' %(datetime.now().year)"
72 period_id: account.period_1
74 - account_id: account.a_sale
75 name: '[PCSC234] PC Assemble SC234'
78 product_id: product.product_product_3
79 uos_id: product.product_uom_unit
80 journal_id: account.sales_journal
81 partner_id: base.res_partner_19
84 I Validate invoice by clicking on Validate button
86 !workflow {model: account.invoice, action: invoice_open, ref: account_first_invoice_jan_cad}
88 I check that first invoice move is correct for debtor account (debit - credit == 149.39)
90 !python {model: account.invoice}: |
91 from openerp.tools import float_compare
92 invoice_id = self.browse(cr, uid, ref("account_first_invoice_jan_cad"))
93 assert invoice_id.move_id, "Move not created for open invoice"
94 move_line_obj = self.pool.get('account.move.line')
95 move_lines = move_line_obj.search(cr, uid, [('move_id', '=', invoice_id.move_id.id), ('account_id', '=', invoice_id.account_id.id)])
96 move_line = move_line_obj.browse(cr, uid, move_lines[0])
97 assert (float_compare(move_line.debit - move_line.credit, 149.39, precision_digits=2) == 0), "Invoice move is incorrect for debtors account"
99 I set the context that will be used for the encoding of all the vouchers of this file
104 I create the first voucher of payment with values 200 CHF, journal CHF
106 !record {model: account.voucher, id: account_voucher_1_case4, view: view_vendor_receipt_form}:
107 account_id: account.cash
109 company_id: base.main_company
110 journal_id: bank_journal_CHF
111 partner_id: base.res_partner_19
112 period_id: account.period_3
113 date: !eval time.strftime("%Y-03-01")
114 payment_option: 'with_writeoff'
115 writeoff_acc_id: account.a_expense
117 name: 'First payment: Case 4'
119 I completly pay the invoice of 200 CAD
121 !python {model: account.voucher}: |
123 from openerp import netsvc
124 from openerp.tools import float_compare
126 voucher_id = self.browse(cr, uid, ref('account_voucher_1_case4'))
128 for item in voucher_id.line_cr_ids:
129 if float_compare(item.amount_unreconciled, 186.74, precision_digits=2) == 0:
130 data += [(item.id, 186.74)]
132 data += [(item.id, 0.0)]
133 for line_id, amount in data:
134 self.pool.get('account.voucher.line').write(cr, uid, [line_id], {'amount': amount})
135 assert (voucher_id.state=='draft'), "Voucher is not in draft state"
137 I check that writeoff amount computed is 13.26
139 !python {model: account.voucher}: |
140 from openerp.tools import float_compare
141 voucher = self.search(cr, uid, [('name', '=', 'First payment: Case 4'), ('partner_id', '=', ref('base.res_partner_19'))])
142 voucher_id = self.browse(cr, uid, voucher[0])
143 assert (float_compare(round(voucher_id.writeoff_amount,2), 13.26, precision_digits=2) == 0), "Writeoff amount is not 13.26 CHF"
145 I confirm the voucher
147 !python {model: account.voucher}: |
148 voucher = self.search(cr, uid, [('name', '=', 'First payment: Case 4'), ('partner_id', '=', ref('base.res_partner_19'))])
149 self.signal_workflow(cr, uid, voucher, 'proforma_voucher')
152 I check that the move of my voucher is valid
154 !python {model: account.voucher}: |
155 voucher = self.search(cr, uid, [('name', '=', 'First payment: Case 4'), ('partner_id', '=', ref('base.res_partner_19'))])
156 voucher_id = self.browse(cr, uid, voucher[0])
157 move_line_obj = self.pool.get('account.move.line')
158 move_lines = move_line_obj.search(cr, uid, [('move_id', '=', voucher_id.move_id.id)])
159 for move_line in move_line_obj.browse(cr, uid, move_lines):
160 assert move_line.state == 'valid', "Voucher move is not valid"
161 assert voucher_id.state == 'posted', "Voucher state is not posted"
163 I check that my debtor account is correct
165 I check that the debtor account has 1 new line with -298.78 as amount_currency columns and 149.39 of credit and currency is CAD.
167 I check that my currency rate difference is correct. 0 in debit with 98.78 CAD as amount_currency
169 I check that my writeoff is correct. 11.05 credit and -13.26 amount_currency
171 !python {model: account.voucher}: |
172 from openerp.tools import float_compare
173 voucher = self.search(cr, uid, [('name', '=', 'First payment: Case 4'), ('partner_id', '=', ref('base.res_partner_19'))])
174 voucher_id = self.browse(cr, uid, voucher[0])
175 move_line_obj = self.pool.get('account.move.line')
176 move_lines = move_line_obj.search(cr, uid, [('move_id', '=', voucher_id.move_id.id)])
177 assert move_lines, "Voucher move has no lines"
178 for move_line in move_line_obj.browse(cr, uid, move_lines):
179 if float_compare(move_line.amount_currency, 200, precision_digits=2) == 0:
180 assert float_compare(move_line.debit, 160.00, precision_digits=2) == 0, "Bank account has wrong entry."
181 elif float_compare(move_line.amount_currency, -298.78, precision_digits=2) == 0 :
182 assert float_compare(move_line.credit, 149.39, precision_digits=2) == 0, "Debtor account has wrong entry."
183 elif float_compare(move_line.debit, 0.00, precision_digits=2) == 0 and float_compare(move_line.credit, 0.00, precision_digits=2) == 0:
184 assert float_compare(move_line.amount_currency, 98.78, precision_digits=2) == 0, "Incorrect Currency Difference, got %s as amount_currency (expected 98.78)." % (move_line.amount_currency)
185 assert move_line.currency_id.id == ref('base.CAD'), "Incorrect Currency Difference, got %s (expected 'CAD')" % (move_line.currency_id.name)
186 elif float_compare(move_line.credit, 10.61, precision_digits=2) == 0:
187 assert float_compare(move_line.amount_currency, -13.26, precision_digits=2) == 0, "Writeoff amount is wrong."
189 assert False, "Wrong entry"
191 I check the residual amount of Invoice1, should be 0 in residual currency and 0 in amount_residual and paid
193 !python {model: account.invoice}: |
194 from openerp.tools import float_compare
195 invoice_id = self.browse(cr, uid, ref("account_first_invoice_jan_cad"))
196 move_line_obj = self.pool.get('account.move.line')
197 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)])
198 move_line = move_line_obj.browse(cr, uid, move_lines[0])
199 assert (float_compare(move_line.amount_residual_currency, 0.0, precision_digits=2) == 0 and float_compare(move_line.amount_residual, 0.0, precision_digits=2) == 0 and invoice_id.state == 'paid') , "Residual amount is not correct for first Invoice"