[FIX] account: fixes of bank statement reconciliation widget. Add of a partner_name field to hold the name of the counterparty in case it is not detected instead of merging it to the communication. Structured communication goes in the same communication field, while reference field holds the reference of the transaction (for whatever that means)"

This commit is contained in:
qdp-odoo 2014-08-29 19:13:41 +02:00
parent 25b4d8a089
commit cbc52f80eb
5 changed files with 31 additions and 28 deletions

View File

@ -439,6 +439,15 @@ class account_bank_statement(osv.osv):
class account_bank_statement_line(osv.osv): class account_bank_statement_line(osv.osv):
def unlink(self, cr, uid, ids, context=None):
for item in self.browse(cr, uid, ids, context=context):
if item.journal_entry_id:
raise osv.except_osv(
_('Invalid Action!'),
_('In order to delete a bank statement line, you must first cancel it to delete related journal items.')
)
return super(account_bank_statement_line, self).unlink(cr, uid, ids, context=context)
def cancel(self, cr, uid, ids, context=None): def cancel(self, cr, uid, ids, context=None):
account_move_obj = self.pool.get('account.move') account_move_obj = self.pool.get('account.move')
move_ids = [] move_ids = []
@ -522,7 +531,7 @@ class account_bank_statement_line(osv.osv):
'statement_id': line.statement_id.id, 'statement_id': line.statement_id.id,
'account_code': line.journal_id.default_debit_account_id.code, 'account_code': line.journal_id.default_debit_account_id.code,
'account_name': line.journal_id.default_debit_account_id.name, 'account_name': line.journal_id.default_debit_account_id.name,
'partner_name': line.partner_id.name, 'partner_name': line.partner_id and line.partner_id.name or line.partner_name,
'amount_currency_str': amount_currency_str, 'amount_currency_str': amount_currency_str,
'has_no_partner': not line.partner_id.id, 'has_no_partner': not line.partner_id.id,
} }
@ -533,9 +542,7 @@ class account_bank_statement_line(osv.osv):
return data return data
def search_structured_com(self, cr, uid, st_line, context=None): def search_structured_com(self, cr, uid, st_line, context=None):
if not st_line.ref: domain = [('ref', '=', st_line.name.replace('/', ''))]
return
domain = [('ref', '=', st_line.ref)]
if st_line.partner_id: if st_line.partner_id:
domain += [('partner_id', '=', st_line.partner_id.id)] domain += [('partner_id', '=', st_line.partner_id.id)]
ids = self.pool.get('account.move.line').search(cr, uid, domain, limit=1, context=context) ids = self.pool.get('account.move.line').search(cr, uid, domain, limit=1, context=context)
@ -600,14 +607,13 @@ class account_bank_statement_line(osv.osv):
""" """
mv_line_pool = self.pool.get('account.move.line') mv_line_pool = self.pool.get('account.move.line')
domain = additional_domain + [('reconcile_id', '=', False),('state', '=', 'valid')] domain = additional_domain + [('reconcile_id', '=', False), ('state', '=', 'valid')]
if st_line.partner_id.id: if st_line.partner_id.id:
domain += [('partner_id', '=', st_line.partner_id.id), domain += [('partner_id', '=', st_line.partner_id.id),
'|', ('account_id.type', '=', 'receivable'), '|', ('account_id.type', '=', 'receivable'),
('account_id.type', '=', 'payable')] ('account_id.type', '=', 'payable')]
else: else:
domain += [('account_id.reconcile', '=', True)] domain += [('account_id.reconcile', '=', True), ('account_id.type', '=', 'other')]
#domain += [('account_id.reconcile', '=', True), ('account_id.type', '=', 'other')]
if excluded_ids: if excluded_ids:
domain.append(('id', 'not in', excluded_ids)) domain.append(('id', 'not in', excluded_ids))
line_ids = mv_line_pool.search(cr, uid, domain, order="date_maturity asc, id asc", context=context) line_ids = mv_line_pool.search(cr, uid, domain, order="date_maturity asc, id asc", context=context)
@ -829,7 +835,7 @@ class account_bank_statement_line(osv.osv):
_description = "Bank Statement Line" _description = "Bank Statement Line"
_inherit = ['ir.needaction_mixin'] _inherit = ['ir.needaction_mixin']
_columns = { _columns = {
'name': fields.char('Description', required=True), 'name': fields.char('Communication', required=True),
'date': fields.date('Date', required=True), 'date': fields.date('Date', required=True),
'amount': fields.float('Amount', digits_compute=dp.get_precision('Account')), 'amount': fields.float('Amount', digits_compute=dp.get_precision('Account')),
'partner_id': fields.many2one('res.partner', 'Partner'), 'partner_id': fields.many2one('res.partner', 'Partner'),
@ -837,7 +843,8 @@ class account_bank_statement_line(osv.osv):
'account_id': fields.many2one('account.account', 'Account', help="This technical field can be used at the statement line creation/import time in order to avoid the reconciliation process on it later on. The statement line will simply create a counterpart on this account"), 'account_id': fields.many2one('account.account', 'Account', help="This technical field can be used at the statement line creation/import time in order to avoid the reconciliation process on it later on. The statement line will simply create a counterpart on this account"),
'statement_id': fields.many2one('account.bank.statement', 'Statement', select=True, required=True, ondelete='cascade'), 'statement_id': fields.many2one('account.bank.statement', 'Statement', select=True, required=True, ondelete='cascade'),
'journal_id': fields.related('statement_id', 'journal_id', type='many2one', relation='account.journal', string='Journal', store=True, readonly=True), 'journal_id': fields.related('statement_id', 'journal_id', type='many2one', relation='account.journal', string='Journal', store=True, readonly=True),
'ref': fields.char('Structured Communication'), 'partner_name': fields.char('Partner Name', help="This field is used to record the third party name when importing bank statement in electronic format, when the partner doesn't exist yet in the database (or cannot be found)."),
'ref': fields.char('Reference'),
'note': fields.text('Notes'), 'note': fields.text('Notes'),
'sequence': fields.integer('Sequence', select=True, help="Gives the sequence order when displaying a list of bank statement lines."), 'sequence': fields.integer('Sequence', select=True, help="Gives the sequence order when displaying a list of bank statement lines."),
'company_id': fields.related('statement_id', 'company_id', type='many2one', relation='res.company', string='Company', store=True, readonly=True), 'company_id': fields.related('statement_id', 'company_id', type='many2one', relation='res.company', string='Company', store=True, readonly=True),

View File

@ -26,11 +26,11 @@
<field name="partner_id" ref="base.res_partner_9"/> <field name="partner_id" ref="base.res_partner_9"/>
</record> </record>
<record id="demo_bank_statement_line_2" model="account.bank.statement.line"> <record id="demo_bank_statement_line_2" model="account.bank.statement.line">
<field name="ref">SAJ2014002</field> <field name="ref"></field>
<field name="statement_id" ref="demo_bank_statement_1"/> <field name="statement_id" ref="demo_bank_statement_1"/>
<field name="sequence" eval="2"/> <field name="sequence" eval="2"/>
<field name="company_id" ref="base.main_company"/> <field name="company_id" ref="base.main_company"/>
<field name="name">SAJ/2014/002</field> <field name="name">SAJ2014002</field>
<field name="journal_id" ref="account.bank_journal"/> <field name="journal_id" ref="account.bank_journal"/>
<field name="amount" eval="650.0"/> <field name="amount" eval="650.0"/>
<field name="date" eval="time.strftime('%Y')+'-01-01'"/> <field name="date" eval="time.strftime('%Y')+'-01-01'"/>

View File

@ -768,10 +768,10 @@ openerp.account = function (instance) {
line.q_amount = (line.debit !== 0 ? "- "+line.q_debit : "") + (line.credit !== 0 ? line.q_credit : ""); line.q_amount = (line.debit !== 0 ? "- "+line.q_debit : "") + (line.credit !== 0 ? line.q_credit : "");
line.q_popover = QWeb.render("bank_statement_reconciliation_move_line_details", {line: line}); line.q_popover = QWeb.render("bank_statement_reconciliation_move_line_details", {line: line});
line.q_label = line.name; line.q_label = line.name;
if (line.has_no_partner){ if (line.has_no_partner){
line.q_label = line.partner_name + ': ' +line.q_label; line.q_label = line.partner_name + ': ' +line.q_label;
} }
// WARNING : pretty much of a ugly hack // WARNING : pretty much of a ugly hack
// The value of account_move.ref is either the move's communication or it's name without the slashes // The value of account_move.ref is either the move's communication or it's name without the slashes
if (line.ref && line.ref !== line.name.replace(/\//g,'')) if (line.ref && line.ref !== line.name.replace(/\//g,''))

View File

@ -53,7 +53,7 @@
<table class="accounting_view"> <table class="accounting_view">
<caption> <caption>
<button class="button_ok"></button> <button class="button_ok"></button>
<span class="partner_name"><t t-esc="line.partner_name"/></span> <span class="partner_name"><t t-if="line.partner_id"><t t-esc="line.partner_name"/></t></span>
<div class="change_partner_container oe_form"></div> <div class="change_partner_container oe_form"></div>
</caption> </caption>
<tbody class="tbody_initial_line"> <tbody class="tbody_initial_line">
@ -61,7 +61,8 @@
<td><span class="toggle_match glyphicon glyphicon-cog"></span></td> <td><span class="toggle_match glyphicon glyphicon-cog"></span></td>
<td><t t-esc="line.account_code"/></td> <td><t t-esc="line.account_code"/></td>
<td><t t-esc="line.date"/></td> <td><t t-esc="line.date"/></td>
<td><t t-esc="line.name"/> <td><t t-if="!line.partner_id"><t t-if="line.partner_name"><t t-esc="line.partner_name"/>: </t></t>
<t t-esc="line.name"/>
<t t-if="line.amount_currency_str"> (<t t-esc="line.amount_currency_str"/>)</t></td> <t t-if="line.amount_currency_str"> (<t t-esc="line.amount_currency_str"/>)</t></td>
<td><t t-if="line.amount &gt; 0"> <td><t t-if="line.amount &gt; 0">
<t t-esc="line.amount_str"/></t></td> <t t-esc="line.amount_str"/></t></td>

View File

@ -59,6 +59,7 @@ class account_coda_import(osv.osv_memory):
return {} return {}
recordlist = unicode(base64.decodestring(codafile), 'windows-1252', 'strict').split('\n') recordlist = unicode(base64.decodestring(codafile), 'windows-1252', 'strict').split('\n')
statements = [] statements = []
globalisation_comm = {}
for line in recordlist: for line in recordlist:
if not line: if not line:
pass pass
@ -69,7 +70,6 @@ class account_coda_import(osv.osv_memory):
statement['version'] = line[127] statement['version'] = line[127]
if statement['version'] not in ['1', '2']: if statement['version'] not in ['1', '2']:
raise osv.except_osv(_('Error') + ' R001', _('CODA V%s statements are not supported, please contact your bank') % statement['version']) raise osv.except_osv(_('Error') + ' R001', _('CODA V%s statements are not supported, please contact your bank') % statement['version'])
statement['globalisation_stack'] = []
statement['lines'] = [] statement['lines'] = []
statement['date'] = time.strftime(tools.DEFAULT_SERVER_DATE_FORMAT, time.strptime(rmspaces(line[5:11]), '%d%m%y')) statement['date'] = time.strftime(tools.DEFAULT_SERVER_DATE_FORMAT, time.strptime(rmspaces(line[5:11]), '%d%m%y'))
statement['separateApplication'] = rmspaces(line[83:88]) statement['separateApplication'] = rmspaces(line[83:88])
@ -154,16 +154,11 @@ class account_coda_import(osv.osv_memory):
statementLine['entryDate'] = time.strftime(tools.DEFAULT_SERVER_DATE_FORMAT, time.strptime(rmspaces(line[115:121]), '%d%m%y')) statementLine['entryDate'] = time.strftime(tools.DEFAULT_SERVER_DATE_FORMAT, time.strptime(rmspaces(line[115:121]), '%d%m%y'))
statementLine['type'] = 'normal' statementLine['type'] = 'normal'
statementLine['globalisation'] = int(line[124]) statementLine['globalisation'] = int(line[124])
if len(statement['globalisation_stack']) > 0 and statementLine['communication'] != '':
statementLine['communication'] = "\n".join([statement['globalisation_stack'][-1]['communication'], statementLine['communication']])
if statementLine['globalisation'] > 0: if statementLine['globalisation'] > 0:
if len(statement['globalisation_stack']) > 0 and statement['globalisation_stack'][-1]['globalisation'] == statementLine['globalisation']: statementLine['type'] = 'globalisation'
# Destack globalisation_comm[statementLine['ref_move']] = statementLine['communication']
statement['globalisation_stack'].pop() if not statementLine.get('communication'):
else: statementLine['communication'] = globalisation_comm.get(statementLine['ref_move'], '')
#Stack
statementLine['type'] = 'globalisation'
statement['globalisation_stack'].append(statementLine)
statement['lines'].append(statementLine) statement['lines'].append(statementLine)
elif line[1] == '2': elif line[1] == '2':
if statement['lines'][-1]['ref'][0:4] != line[2:6]: if statement['lines'][-1]['ref'][0:4] != line[2:6]:
@ -290,7 +285,6 @@ class account_coda_import(osv.osv_memory):
if 'counterpartyAddress' in line and line['counterpartyAddress'] != '': if 'counterpartyAddress' in line and line['counterpartyAddress'] != '':
note.append(_('Counter Party Address') + ': ' + line['counterpartyAddress']) note.append(_('Counter Party Address') + ': ' + line['counterpartyAddress'])
line['name'] = "\n".join(filter(None, [line['counterpartyName'], line['communication']]))
partner_id = None partner_id = None
structured_com = "" structured_com = ""
bank_account_id = False bank_account_id = False
@ -311,16 +305,17 @@ class account_coda_import(osv.osv_memory):
except ValueError: except ValueError:
bank_code = 'bank' 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) 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'] != '': if line.get('communication', ''):
note.append(_('Communication') + ': ' + line['communication']) note.append(_('Communication') + ': ' + line['communication'])
data = { data = {
'name': line['name'], 'name': structured_com or line['communication'],
'note': "\n".join(note), 'note': "\n".join(note),
'date': line['entryDate'], 'date': line['entryDate'],
'amount': line['amount'], 'amount': line['amount'],
'partner_id': partner_id, 'partner_id': partner_id,
'partner_name': line['counterpartyName'],
'statement_id': statement['id'], 'statement_id': statement['id'],
'ref': structured_com, 'ref': line['ref'],
'sequence': line['sequence'], 'sequence': line['sequence'],
'bank_account_id': bank_account_id, 'bank_account_id': bank_account_id,
} }