[FIX] Select account receivable/payable based on partner settings if any

This commit is contained in:
Stefan Rijnhart
2013-08-23 13:55:17 +02:00
parent 158b6f6127
commit 7f7eb28226
2 changed files with 50 additions and 23 deletions

View File

@@ -1112,21 +1112,23 @@ class banking_import_transaction(orm.Model):
# the internal type of these accounts to either 'payable'
# or 'receivable' to enable usage like this.
if transaction.statement_line_id.amount < 0:
if len(partner_banks) == 1:
account_id = (
partner_banks[0].partner_id.property_account_payable and
partner_banks[0].partner_id.property_account_payable.id)
if len(partner_banks) != 1 or not account_id or account_id == def_pay_account_id:
account_id = (account_info.default_credit_account_id and
account_info.default_credit_account_id.id)
account_type = 'payable'
else:
if len(partner_banks) == 1:
account_id = (
partner_banks[0].partner_id.property_account_receivable and
partner_banks[0].partner_id.property_account_receivable.id)
if len(partner_banks) != 1 or not account_id or account_id == def_rec_account_id:
account_id = (account_info.default_debit_account_id and
account_info.default_debit_account_id.id)
account_type = 'receivable'
if len(partner_banks) == 1:
partner = partner_banks[0].partner_id
if partner.supplier and not partner.customer:
account_type = 'payable'
elif partner.customer and not partner.supplier:
account_type = 'payable'
if partner['property_acccount_' + account_type]:
account_id = partner['property_acccount_' + account_type].id
if not account_id or account_id in (def_pay_account_id, def_rec_account_id):
if account_type == 'payable':
account_id = account_info.default_credit_account_id
else:
account_id = account_info.default_debit_account_id
values = {'account_id': account_id}
self_values = {}
if move_info:
@@ -1495,7 +1497,7 @@ class account_bank_statement_line(orm.Model):
if (not statement_line.import_transaction_id or
not statement_line.import_transaction_id.remote_account):
raise osv.except_osv(
raise orm.except_orm(
_("Error"),
_("No bank account available to link partner to"))

View File

@@ -256,14 +256,7 @@ class banking_transaction_wizard(orm.TransientModel):
account_id = False
journal_id = wiz.statement_line_id.statement_id.journal_id.id
setting_ids = settings_pool.find(cr, uid, journal_id, context=context)
if len(setting_ids)>0:
setting = settings_pool.browse(cr, uid, setting_ids[0], context=context)
if wiz.amount < 0:
account_id = setting.default_credit_account_id and setting.default_credit_account_id.id
else:
account_id = setting.default_debit_account_id and setting.default_debit_account_id.id
statement_pool.write(cr, uid, wiz.statement_line_id.id, {'account_id':account_id})
# Restore partner id from the bank account or else reset
partner_id = False
if (wiz.statement_line_id.partner_bank_id and
@@ -271,6 +264,38 @@ class banking_transaction_wizard(orm.TransientModel):
partner_id = wiz.statement_line_id.partner_bank_id.partner_id.id
wiz.write({'partner_id': partner_id})
# Select account type by parter customer or supplier,
# or default based on amount sign
if wiz.amount < 0:
account_type = 'payable'
else:
account_type = 'receivable'
if partner_id:
partner = wiz.statement_line_id.partner_bank_id.partner_id
if partner.supplier and not partner.customer:
account_type = 'payable'
elif partner.customer and not partner.supplier:
account_type = 'payable'
if partner['property_acccount_' + account_type]:
account_id = partner['property_acccount_' + account_type].id
company_partner = wiz.statement_line_id.statement_id.company_id.partner_id
if len(setting_ids) and (
not account_id
or account_id in (
company_partner.property_account_payable.id,
company_partner.property_account_receivable.id)
):
setting = settings_pool.browse(cr, uid, setting_ids[0], context=context)
if account_type == 'payable':
account_id = setting.default_credit_account_id.id
else:
account_id = setting.default_debit_account_id.id
if account_id:
wiz.statement_line_id.write({'account_id': account_id})
if wiz.statement_line_id:
#delete splits causing an unsplit if this is a split
#transaction