[IMP] account: learn the res.partner.bank of partners in reconciliation process on bank statement + adapted l10n_be
This commit is contained in:
parent
cae213974b
commit
5e7e7cef41
|
@ -329,6 +329,7 @@ class account_bank_statement(osv.osv):
|
|||
move_ids.append(st_line.journal_entry_id.id)
|
||||
self.pool.get('account.move').post(cr, uid, move_ids, context=context)
|
||||
self.message_post(cr, uid, [st.id], body=_('Statement %s confirmed, journal items were created.') % (st.name,), context=context)
|
||||
self.link_bank_to_partner(cr, uid, ids, context=context)
|
||||
return self.write(cr, uid, ids, {'state':'confirm'}, context=context)
|
||||
|
||||
def button_cancel(self, cr, uid, ids, context=None):
|
||||
|
@ -428,6 +429,12 @@ class account_bank_statement(osv.osv):
|
|||
bsl_obj = self.pool.get('account.bank.statement.line')
|
||||
return bsl_obj.search_count(cr, uid, [('statement_id', '=', id), ('journal_entry_id', '!=', False)], context=context)
|
||||
|
||||
def link_bank_to_partner(self, cr, uid, ids, context=None):
|
||||
for statement in self.browse(cr, uid, ids, context=context):
|
||||
for st_line in statement.line_ids:
|
||||
if st_line.bank_account_id and st_line.partner_id and st_line.bank_account_id.partner_id.id != st_line.partner_id.id:
|
||||
self.pool.get('res.partner.bank').write(cr, uid, [st_line.bank_account_id.id], {'partner_id': st_line.partner_id.id}, context=context)
|
||||
|
||||
class account_bank_statement_line(osv.osv):
|
||||
|
||||
def get_data_for_reconciliations(self, cr, uid, ids, context=None):
|
||||
|
@ -504,7 +511,6 @@ class account_bank_statement_line(osv.osv):
|
|||
st_line = self.browse(cr, uid, id, context=context)
|
||||
company_currency = st_line.journal_id.company_id.currency_id.id
|
||||
statement_currency = st_line.journal_id.currency.id or company_currency
|
||||
|
||||
# either use the unsigned debit/credit fields or the signed amount_currency field
|
||||
sign = 1
|
||||
if statement_currency == company_currency:
|
||||
|
@ -535,7 +541,7 @@ class account_bank_statement_line(osv.osv):
|
|||
# get_move_lines_counterparts inverts debit and credit
|
||||
amount_field = 'debit' if amount_field == 'credit' else 'credit'
|
||||
for line in mv_lines:
|
||||
if total + line[amount_field] <= st_line.amount:
|
||||
if total + line[amount_field] <= abs(st_line.amount):
|
||||
ret.append(line)
|
||||
total += line[amount_field]
|
||||
if total >= st_line.amount:
|
||||
|
|
|
@ -28,46 +28,4 @@ class account_bank_statement(osv.osv):
|
|||
}
|
||||
|
||||
|
||||
class account_bank_statement_line(osv.osv):
|
||||
_inherit = 'account.bank.statement.line'
|
||||
_columns = {
|
||||
'coda_account_number': fields.char('Account Number', help="The Counter Party Account Number")
|
||||
}
|
||||
|
||||
def create(self, cr, uid, data, context=None):
|
||||
"""
|
||||
This function creates a Bank Account Number if, for a bank statement line,
|
||||
the partner_id field and the coda_account_number field are set,
|
||||
and the account number does not exist in the database
|
||||
"""
|
||||
if 'partner_id' in data and data['partner_id'] and 'coda_account_number' in data and data['coda_account_number']:
|
||||
acc_number_ids = self.pool.get('res.partner.bank').search(cr, uid, [('acc_number', '=', data['coda_account_number'])])
|
||||
if len(acc_number_ids) == 0:
|
||||
try:
|
||||
type_model, type_id = self.pool.get('ir.model.data').get_object_reference(cr, uid, 'base', 'bank_normal')
|
||||
type_id = self.pool.get('res.partner.bank.type').browse(cr, uid, type_id, context=context)
|
||||
self.pool.get('res.partner.bank').create(cr, uid, {'acc_number': data['coda_account_number'], 'partner_id': data['partner_id'], 'state': type_id.code}, context=context)
|
||||
except ValueError:
|
||||
pass
|
||||
return super(account_bank_statement_line, self).create(cr, uid, data, context=context)
|
||||
|
||||
def write(self, cr, uid, ids, vals, context=None):
|
||||
super(account_bank_statement_line, self).write(cr, uid, ids, vals, context)
|
||||
"""
|
||||
Same as create function above, but for write function
|
||||
"""
|
||||
if 'partner_id' in vals:
|
||||
for line in self.pool.get('account.bank.statement.line').browse(cr, uid, ids, context=context):
|
||||
if line.coda_account_number:
|
||||
acc_number_ids = self.pool.get('res.partner.bank').search(cr, uid, [('acc_number', '=', line.coda_account_number)])
|
||||
if len(acc_number_ids) == 0:
|
||||
try:
|
||||
type_model, type_id = self.pool.get('ir.model.data').get_object_reference(cr, uid, 'base', 'bank_normal')
|
||||
type_id = self.pool.get('res.partner.bank.type').browse(cr, uid, type_id, context=context)
|
||||
self.pool.get('res.partner.bank').create(cr, uid, {'acc_number': line.coda_account_number, 'partner_id': vals['partner_id'], 'state': type_id.code}, context=context)
|
||||
except ValueError:
|
||||
pass
|
||||
return True
|
||||
|
||||
|
||||
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
|
||||
|
|
|
@ -293,13 +293,24 @@ class account_coda_import(osv.osv_memory):
|
|||
line['name'] = "\n".join(filter(None, [line['counterpartyName'], line['communication']]))
|
||||
partner_id = None
|
||||
structured_com = ""
|
||||
bank_account_id = False
|
||||
if line['communication_struct'] and 'communication_type' in line and line['communication_type'] == '101':
|
||||
structured_com = line['communication']
|
||||
if 'counterpartyNumber' in line and line['counterpartyNumber']:
|
||||
ids = self.pool.get('res.partner.bank').search(cr, uid, [('acc_number', '=', str(line['counterpartyNumber']))])
|
||||
if ids and len(ids) > 0:
|
||||
partner = self.pool.get('res.partner.bank').browse(cr, uid, ids[0], context=context).partner_id
|
||||
partner_id = partner.id
|
||||
if ids:
|
||||
bank_account_id = ids[0]
|
||||
partner_id = self.pool.get('res.partner.bank').browse(cr, uid, bank_account_id, context=context).partner_id.id
|
||||
else:
|
||||
#create the bank account, not linked to any partner. The reconciliation will link the partner manually
|
||||
#chosen at the bank statement final confirmation time.
|
||||
try:
|
||||
type_model, type_id = self.pool.get('ir.model.data').get_object_reference(cr, uid, 'base', 'bank_normal')
|
||||
type_id = self.pool.get('res.partner.bank.type').browse(cr, uid, type_id, context=context)
|
||||
bank_code = type_id.code
|
||||
except ValueError:
|
||||
bank_code = 'bank'
|
||||
bank_account_id = self.pool.get('res.partner.bank').create(cr, uid, {'acc_number': str(line['counterpartyNumber']), 'state': bank_code}, context=context)
|
||||
if 'communication' in line and line['communication'] != '':
|
||||
note.append(_('Communication') + ': ' + line['communication'])
|
||||
data = {
|
||||
|
@ -311,7 +322,7 @@ class account_coda_import(osv.osv_memory):
|
|||
'statement_id': statement['id'],
|
||||
'ref': structured_com,
|
||||
'sequence': line['sequence'],
|
||||
'coda_account_number': line['counterpartyNumber'],
|
||||
'bank_account_id': bank_account_id,
|
||||
}
|
||||
self.pool.get('account.bank.statement.line').create(cr, uid, data, context=context)
|
||||
if statement['coda_note'] != '':
|
||||
|
|
|
@ -128,8 +128,7 @@ class res_partner_bank(osv.osv):
|
|||
change_default=True, domain="[('country_id','=',country_id)]"),
|
||||
'company_id': fields.many2one('res.company', 'Company',
|
||||
ondelete='cascade', help="Only if this bank account belong to your company"),
|
||||
'partner_id': fields.many2one('res.partner', 'Account Owner', required=True,
|
||||
ondelete='cascade', select=True),
|
||||
'partner_id': fields.many2one('res.partner', 'Account Owner', ondelete='cascade', select=True),
|
||||
'state': fields.selection(_bank_type_get, 'Bank Account Type', required=True,
|
||||
change_default=True),
|
||||
'sequence': fields.integer('Sequence'),
|
||||
|
|
Loading…
Reference in New Issue