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: account.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 invoice_id = self.browse(cr, uid, ref("account_first_invoice_jan_cad"))
92 assert invoice_id.move_id, "Move not created for open invoice"
93 move_line_obj = self.pool.get('account.move.line')
94 move_lines = move_line_obj.search(cr, uid, [('move_id', '=', invoice_id.move_id.id), ('account_id', '=', invoice_id.account_id.id)])
95 move_line = move_line_obj.browse(cr, uid, move_lines[0])
96 assert (move_line.debit - move_line.credit == 149.39), "Invoice move is incorrect for debtors account"
98 I set the context that will be used for the encoding of all the vouchers of this file
103 I create the first voucher of payment with values 200 CHF, journal CHF
105 !record {model: account.voucher, id: account_voucher_1_case4, view: view_vendor_receipt_form}:
106 account_id: account.cash
108 company_id: base.main_company
109 journal_id: bank_journal_CHF
110 partner_id: base.res_partner_19
111 period_id: account.period_3
112 date: !eval time.strftime("%Y-03-01")
113 payment_option: 'with_writeoff'
114 writeoff_acc_id: account.a_expense
116 name: 'First payment: Case 4'
118 I completly pay the invoice of 200 CAD
120 !python {model: account.voucher}: |
123 voucher_id = self.browse(cr, uid, ref('account_voucher_1_case4'))
125 for item in voucher_id.line_cr_ids:
126 if item.amount_unreconciled == 186.74:
127 data += [(item.id, 186.74)]
129 data += [(item.id, 0.0)]
130 for line_id, amount in data:
131 self.pool.get('account.voucher.line').write(cr, uid, [line_id], {'amount': amount})
132 assert (voucher_id.state=='draft'), "Voucher is not in draft state"
134 I check that writeoff amount computed is 13.26
136 !python {model: account.voucher}: |
137 voucher = self.search(cr, uid, [('name', '=', 'First payment: Case 4'), ('partner_id', '=', ref('base.res_partner_19'))])
138 voucher_id = self.browse(cr, uid, voucher[0])
139 assert (round(voucher_id.writeoff_amount,2) == 13.26), "Writeoff amount is not 13.26 CHF"
141 I confirm the voucher
143 !python {model: account.voucher}: |
145 voucher = self.search(cr, uid, [('name', '=', 'First payment: Case 4'), ('partner_id', '=', ref('base.res_partner_19'))])
146 wf_service = netsvc.LocalService("workflow")
147 wf_service.trg_validate(uid, 'account.voucher', voucher[0], 'proforma_voucher', cr)
149 I check that the move of my voucher is valid
151 !python {model: account.voucher}: |
152 voucher = self.search(cr, uid, [('name', '=', 'First payment: Case 4'), ('partner_id', '=', ref('base.res_partner_19'))])
153 voucher_id = self.browse(cr, uid, voucher[0])
154 move_line_obj = self.pool.get('account.move.line')
155 move_lines = move_line_obj.search(cr, uid, [('move_id', '=', voucher_id.move_id.id)])
156 for move_line in move_line_obj.browse(cr, uid, move_lines):
157 assert move_line.state == 'valid', "Voucher move is not valid"
158 assert voucher_id.state == 'posted', "Voucher state is not posted"
160 I check that my debtor account is correct
162 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.
164 I check that my currency rate difference is correct. 0 in debit with no amount_currency
166 I check that my writeoff is correct. 11.05 credit and -13.26 amount_currency
168 !python {model: account.voucher}: |
169 voucher = self.search(cr, uid, [('name', '=', 'First payment: Case 4'), ('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 if move_line.amount_currency == 200:
175 assert move_line.debit == 160.00, "Bank account has wrong entry."
176 elif move_line.amount_currency == -298.78:
177 assert move_line.credit == 149.39, "Debtor account has wrong entry."
178 elif move_line.debit == 0.00 and move_line.credit == 0.00:
179 assert move_line.amount_currency == 0.00, "Incorrect Currency Difference."
180 elif move_line.credit == 10.61:
181 assert move_line.amount_currency == -13.26, "Writeoff amount is wrong."
183 assert False, "Wrong entry"
185 I check the residual amount of Invoice1, should be 0 in residual currency and 0 in amount_residual and paid
187 !python {model: account.invoice}: |
188 invoice_id = self.browse(cr, uid, ref("account_first_invoice_jan_cad"))
189 move_line_obj = self.pool.get('account.move.line')
190 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)])
191 move_line = move_line_obj.browse(cr, uid, move_lines[0])
192 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"