[FIX] account_voucher: select the right credit/debit account for the payment

If different debit/credit accounts are configured for a journal, the
appropriate account must be selected.

opw-640745
This commit is contained in:
Nicolas Martinelli 2015-06-02 12:08:45 +02:00
parent d9e8c3ade4
commit e470385d55
1 changed files with 20 additions and 2 deletions

View File

@ -573,7 +573,12 @@ class account_voucher(osv.osv):
else:
if not journal.default_credit_account_id or not journal.default_debit_account_id:
raise osv.except_osv(_('Error!'), _('Please define default credit/debit accounts on the journal "%s".') % (journal.name))
account_id = journal.default_credit_account_id.id or journal.default_debit_account_id.id
if ttype in ('sale', 'receipt'):
account_id = journal.default_debit_account_id.id
elif ttype in ('purchase', 'payment'):
account_id = journal.default_credit_account_id.id
else:
account_id = journal.default_credit_account_id.id or journal.default_debit_account_id.id
tr_type = 'receipt'
default['value']['account_id'] = account_id
@ -665,6 +670,10 @@ class account_voucher(osv.osv):
account_id = partner.property_account_receivable.id
elif journal.type in ('purchase', 'purchase_refund','expense'):
account_id = partner.property_account_payable.id
elif ttype in ('sale', 'receipt'):
account_id = journal.default_debit_account_id.id
elif ttype in ('purchase', 'payment'):
account_id = journal.default_credit_account_id.id
else:
account_id = journal.default_credit_account_id.id or journal.default_debit_account_id.id
@ -921,7 +930,12 @@ class account_voucher(osv.osv):
return False
journal_pool = self.pool.get('account.journal')
journal = journal_pool.browse(cr, uid, journal_id, context=context)
account_id = journal.default_credit_account_id or journal.default_debit_account_id
if ttype in ('sale', 'receipt'):
account_id = journal.default_debit_account_id
elif ttype in ('purchase', 'payment'):
account_id = journal.default_credit_account_id
else:
account_id = journal.default_credit_account_id or journal.default_debit_account_id
tax_id = False
if account_id and account_id.tax_ids:
tax_id = account_id.tax_ids[0].id
@ -1012,6 +1026,10 @@ class account_voucher(osv.osv):
account_id = partner.property_account_receivable.id
elif journal.type in ('purchase', 'purchase_refund','expense'):
account_id = partner.property_account_payable.id
elif ttype in ('sale', 'receipt'):
account_id = journal.default_debit_account_id.id
elif ttype in ('purchase', 'payment'):
account_id = journal.default_credit_account_id.id
else:
account_id = journal.default_credit_account_id.id or journal.default_debit_account_id.id
if account_id: