2011-09-27 16:37:09 +00:00
-
In order to check the Account_voucher module with multi-currency in OpenERP,
I create an invoice in CAD and make its Payment in CHF based on the currency rating on that particular date.
-
I create currency CAD in OpenERP for January of 1.338800 Rate
-
!record {model: res.currency.rate, id: jan_cad}:
currency_id : base.CAD
name : !eval "'%s-01-01' %(datetime.now().year)"
rate : 1.338800
-
I create currency CAD in OpenERP for March of 2.000000 Rate
-
!record {model: res.currency.rate, id: mar_cad}:
currency_id : base.CAD
name : !eval "'%s-03-01' %(datetime.now().year)"
rate : 2.000000
-
I create currency CHF in OpenERP for January of 1.308600 Rate
-
!record {model: res.currency.rate, id: jan_chf}:
currency_id : base.CHF
name : !eval "'%s-01-01' %(datetime.now().year)"
rate : 1.308600
-
I create currency CHF in OpenERP for March of 1.250000 Rate
-
!record {model: res.currency.rate, id: mar_chf}:
currency_id : base.CHF
name : !eval "'%s-03-01' %(datetime.now().year)"
2011-10-17 09:22:16 +00:00
rate : 1.25000
2011-09-27 16:37:09 +00:00
-
I create a bank journal with CHF as currency
-
!record {model: account.journal, id: bank_journal_CHF}:
name : Bank Journal(CHF)
code : BCHF
type : bank
analytic_journal_id : account.sit
sequence_id : account.sequence_bank_journal
default_debit_account_id : account.cash
default_credit_account_id : account.cash
currency : base.CHF
company_id : base.main_company
view_id : account.account_journal_bank_view
-
I create the first invoice on 1st January for 200 CAD
-
!record {model: account.invoice, id: account_first_invoice_jan_cad}:
account_id : account.a_recv
address_contact_id : base.res_partner_address_3000
address_invoice_id : base.res_partner_address_3000
company_id : base.main_company
currency_id : base.CAD
date_invoice : !eval "'%s-01-01' %(datetime.now().year)"
period_id : account.period_1
invoice_line :
- account_id : account.a_sale
name : '[PC1] Basic PC'
price_unit : 200.0
quantity : 1.0
product_id : product.product_product_pc1
uos_id : product.product_uom_unit
journal_id : account.sales_journal
2011-11-03 00:19:18 +00:00
partner_id : base.res_partner_seagate
2011-09-27 16:37:09 +00:00
reference_type : none
-
I Validate invoice by clicking on Validate button
-
!workflow {model: account.invoice, action: invoice_open, ref: account_first_invoice_jan_cad}
-
I check that first invoice move is correct for debtor account (debit - credit == 149.39)
-
!python {model: account.invoice}: |
invoice_id = self.browse(cr, uid, ref("account_first_invoice_jan_cad"))
assert invoice_id.move_id, "Move not created for open invoice"
move_line_obj = self.pool.get('account.move.line')
move_lines = move_line_obj.search(cr, uid, [('move_id', '=', invoice_id.move_id.id), ('account_id', '=', invoice_id.account_id.id)])
move_line = move_line_obj.browse(cr, uid, move_lines[0])
assert (move_line.debit - move_line.credit == 149.39), "Invoice move is incorrect for debtors account"
-
I create the first voucher of payment
2011-10-17 09:22:16 +00:00
<create with values 200 CHF, journal CHF, and completly pat the invoice of 200 CAD>
2011-09-27 16:37:09 +00:00
-
!python {model: account.voucher}: |
import netsvc, time
vals = {}
2011-11-03 00:19:18 +00:00
res = self.onchange_partner_id(cr, uid, [], ref("base.res_partner_seagate"), ref('bank_journal_CHF'), 200.00, ref('base.CHF'), ttype='receipt', date=False)
2011-09-27 16:37:09 +00:00
vals = {
'account_id' : ref('account.cash'),
2011-10-17 09:22:16 +00:00
'amount' : 200.00 ,
2011-09-27 16:37:09 +00:00
'company_id' : ref('base.main_company'),
'currency_id' : ref('base.CHF'),
'journal_id' : ref('bank_journal_CHF'),
2011-11-03 00:19:18 +00:00
'partner_id' : ref('base.res_partner_seagate'),
2011-09-27 16:37:09 +00:00
'period_id' : ref('account.period_3'),
'type' : 'receipt' ,
2011-10-21 15:32:58 +00:00
'date' : time.strftime("%Y-%m-%d"),
2011-09-27 16:37:09 +00:00
'payment_option' : 'with_writeoff' ,
'writeoff_acc_id' : ref('account.a_expense'),
2011-10-17 09:22:16 +00:00
'exchange_acc_id' : ref('account.o_expense'),
2011-09-27 16:37:09 +00:00
'comment' : 'Write Off' ,
2011-11-03 00:19:18 +00:00
'name': 'First payment : Case 4',
2011-09-27 16:37:09 +00:00
}
2011-10-21 15:32:58 +00:00
vals.update(self.onchange_date(cr, uid, [], time.strftime('%Y-03-01'), ref('base.CHF'), 200.0)['value'])
2011-09-27 16:37:09 +00:00
if not res['value']['line_cr_ids'] :
res['value']['line_cr_ids'] = [{'type': 'cr', 'account_id': ref('account.a_recv'),}]
for item in res['value']['line_cr_ids'] :
2011-10-17 09:22:16 +00:00
if item['amount_unreconciled'] == 186.74 :
item['amount'] = 186.74
2011-09-27 16:37:09 +00:00
vals['line_cr_ids'] = [(0,0,i) for i in res['value']['line_cr_ids']]
id = self.create(cr, uid, vals)
voucher_id = self.browse(cr, uid, id)
assert (voucher_id.state=='draft'), "Voucher is not in draft state"
-
2011-10-17 09:22:16 +00:00
I check that writeoff amount computed is 13.26
2011-09-27 16:37:09 +00:00
-
!python {model: account.voucher}: |
2011-11-03 00:19:18 +00:00
voucher = self.search(cr, uid, [('name', '=', 'First payment : Case 4'), ('partner_id', '=', ref('base.res_partner_seagate'))])
2011-09-27 16:37:09 +00:00
voucher_id = self.browse(cr, uid, voucher[0])
2011-10-17 09:22:16 +00:00
assert (round(voucher_id.writeoff_amount,2) == 13.26), "Writeoff amount is not 13.26 CHF"
2011-09-27 16:37:09 +00:00
-
I confirm the voucher
-
!python {model: account.voucher}: |
import netsvc
2011-11-03 00:19:18 +00:00
voucher = self.search(cr, uid, [('name', '=', 'First payment : Case 4'), ('partner_id', '=', ref('base.res_partner_seagate'))])
2011-09-27 16:37:09 +00:00
wf_service = netsvc.LocalService("workflow")
wf_service.trg_validate(uid, 'account.voucher', voucher[0], 'proforma_voucher', cr)
-
I check that the move of my voucher is valid
-
!python {model: account.voucher}: |
2011-11-03 00:19:18 +00:00
voucher = self.search(cr, uid, [('name', '=', 'First payment : Case 4'), ('partner_id', '=', ref('base.res_partner_seagate'))])
2011-09-27 16:37:09 +00:00
voucher_id = self.browse(cr, uid, voucher[0])
move_line_obj = self.pool.get('account.move.line')
move_lines = move_line_obj.search(cr, uid, [('move_id', '=', voucher_id.move_id.id)])
for move_line in move_line_obj.browse(cr, uid, move_lines) :
assert move_line.state == 'valid', "Voucher move is not valid"
assert voucher_id.state == 'posted', "Voucher state is not posted"
-
I check that my debtor account is correct
-
2011-10-17 09:22:16 +00:00
I check that the debtor account has 1 new line with -186.74 as amount_currency columns and 149.39 of credit and currency is CHF.
2011-09-27 16:37:09 +00:00
-
2011-10-17 09:22:16 +00:00
I check that my currency rate difference is correct. 0 in debit with no amount_currency
2011-09-27 16:37:09 +00:00
-
2011-10-17 09:22:16 +00:00
I check that my writeoff is correct. 11.05 credit and 13.26 amount_currency
2011-09-27 16:37:09 +00:00
-
!python {model: account.voucher}: |
2011-11-03 00:19:18 +00:00
voucher = self.search(cr, uid, [('name', '=', 'First payment : Case 4'), ('partner_id', '=', ref('base.res_partner_seagate'))])
2011-09-27 16:37:09 +00:00
voucher_id = self.browse(cr, uid, voucher[0])
move_line_obj = self.pool.get('account.move.line')
move_lines = move_line_obj.search(cr, uid, [('move_id', '=', voucher_id.move_id.id)])
for move_line in move_line_obj.browse(cr, uid, move_lines) :
2011-10-17 09:22:16 +00:00
if move_line.amount_currency == 200 :
assert move_line.debit == 160.00, "Bank account has wrong entry."
elif move_line.amount_currency == -186.74 :
2011-09-27 16:37:09 +00:00
assert move_line.credit == 149.39, "Debtor account has wrong entry."
2011-10-17 09:22:16 +00:00
elif move_line.debit == 0.00 and move_line.credit == 0.00 :
2011-09-27 16:37:09 +00:00
assert move_line.amount_currency == 0.00, "Incorrect Currency Difference."
2011-10-17 09:22:16 +00:00
elif move_line.credit == 10.61 :
assert move_line.amount_currency == 13.26, "Writeoff amount is wrong."
else :
assert False, "Wrong entry"
2011-09-27 16:37:09 +00:00
-
I check the residual amount of Invoice1, should be 0 in residual currency and 0 in amount_residual and paid
-
!python {model: account.invoice}: |
invoice_id = self.browse(cr, uid, ref("account_first_invoice_jan_cad"))
move_line_obj = self.pool.get('account.move.line')
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)])
move_line = move_line_obj.browse(cr, uid, move_lines[0])
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"