[FIX] account_voucher, multicurrency treatment: correct handling of amount in currency field

bzr revid: qdp-launchpad@tinyerp.com-20101108100740-rikc62tugt14pxk7
This commit is contained in:
qdp-launchpad@tinyerp.com 2010-11-08 11:07:40 +01:00
parent c27087c76c
commit 25887e10a7
1 changed files with 13 additions and 13 deletions

View File

@ -577,8 +577,6 @@ class account_voucher(osv.osv):
tax_obj = self.pool.get('account.tax')
seq_obj = self.pool.get('ir.sequence')
for inv in self.browse(cr, uid, ids):
if not inv.line_ids:
raise osv.except_osv(_('No Lines !'), _('Please create some lines'))
if inv.move_id:
continue
if inv.number:
@ -604,21 +602,22 @@ class account_voucher(osv.osv):
#create the first line manually
company_currency = inv.journal_id.company_id.currency_id.id
current_currency = inv.currency_id.id
debit = 0.0
credit = 0.0
# TODO: is there any other alternative then the voucher type ??
# -for sale, purchase we have but for the payment and receipt we do not have as based on the bank/cash journal we can not know its payment or receipt
if inv.type in ('purchase', 'payment'):
credit = currency_pool.compute(cr, uid, inv.currency_id.id, company_currency, inv.amount)
credit = currency_pool.compute(cr, uid, current_currency, company_currency, inv.amount)
elif inv.type in ('sale', 'receipt'):
debit = currency_pool.compute(cr, uid, inv.currency_id.id, company_currency, inv.amount)
debit = currency_pool.compute(cr, uid, current_currency, company_currency, inv.amount)
if debit < 0:
credit = -debit
debit = 0.0
if credit < 0:
debit = -credit
credit = 0.0
sign = debit - credit < 0 and -1 or 1
move_line = {
'name': inv.name or '/',
'debit': debit,
@ -628,8 +627,8 @@ class account_voucher(osv.osv):
'journal_id': inv.journal_id.id,
'period_id': inv.period_id.id,
'partner_id': inv.partner_id.id,
'currency_id': inv.currency_id.id,
'amount_currency': inv.amount,
'currency_id': company_currency <> current_currency and current_currency or False,
'amount_currency': company_currency <> current_currency and sign * inv.amount or 0.0,
'date': inv.date,
'date_maturity': inv.date_due
}
@ -647,7 +646,7 @@ class account_voucher(osv.osv):
for line in inv.line_ids:
if not line.amount:
continue
amount = currency_pool.compute(cr, uid, inv.currency_id.id, company_currency, line.amount)
amount = currency_pool.compute(cr, uid, current_currency, company_currency, line.amount)
move_line = {
'journal_id': inv.journal_id.id,
'period_id': inv.period_id.id,
@ -655,8 +654,7 @@ class account_voucher(osv.osv):
'account_id': line.account_id.id,
'move_id': move_id,
'partner_id': inv.partner_id.id,
'currency_id': inv.currency_id.id,
'amount_currency': line.amount,
'currency_id': company_currency <> current_currency and current_currency or False,
'analytic_account_id': line.account_analytic_id and line.account_analytic_id.id or False,
'quantity': 1,
'credit': 0.0,
@ -685,6 +683,8 @@ class account_voucher(osv.osv):
tax_data = tax_obj.browse(cr, uid, [move_line['account_tax_id']], context=context)[0]
if not (tax_data.base_code_id and tax_data.tax_code_id):
raise osv.except_osv(_('No Account Base Code and Account Tax Code!'),_("You have to configure account base code and account tax code on the '%s' tax!") % (tax_data.name))
sign = (move_line['debit'] - move_line['credit']) < 0 and -1 or 1
move_line['amount_currency'] = company_currency <> current_currency and sign * line.amount or 0.0
master_line = move_line_pool.create(cr, uid, move_line)
if line.move_line_id.id:
rec_ids = [master_line, line.move_line_id.id]
@ -700,6 +700,8 @@ class account_voucher(osv.osv):
'date': inv.date,
'credit': diff > 0 and diff or 0.0,
'debit': diff < 0 and -diff or 0.0,
'amount_currency': company_currency <> current_currency and currency_pool.compute(cr, uid, company_currency, current_currency, diff * -1) or 0.0,
'currency_id': company_currency <> current_currency and current_currency or False,
}
account_id = False
if inv.type in ('sale', 'receipt'):
@ -844,8 +846,6 @@ class account_voucher_line(osv.osv):
elif context.get('type') == 'receipt':
account_id = partner.property_account_receivable.id
if (not account_id) and 'account_id' in fields_list:
raise osv.except_osv(_('Invalid Error !'), _('Please change partner and try again !'))
values.update({
'account_id':account_id,
'type':ttype
@ -928,4 +928,4 @@ class account_bank_statement_line(osv.osv):
account_bank_statement_line()
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: