mirror of
https://github.com/OCA/account-reconcile.git
synced 2025-01-20 12:27:39 +02:00
[FIX] escape regexp strings (also in get_from_label_and_partner_name).
remove dead code. Fix typos. Fix indentation
This commit is contained in:
@@ -19,6 +19,7 @@
|
|||||||
#
|
#
|
||||||
##############################################################################
|
##############################################################################
|
||||||
from collections import defaultdict
|
from collections import defaultdict
|
||||||
|
from re import escape
|
||||||
|
|
||||||
from tools.translate import _
|
from tools.translate import _
|
||||||
from openerp.osv.orm import Model, fields
|
from openerp.osv.orm import Model, fields
|
||||||
@@ -275,7 +276,7 @@ class AccountStatementCompletionRule(Model):
|
|||||||
# As we have to iterate on each partner for each line,
|
# As we have to iterate on each partner for each line,
|
||||||
# we memoize the pair to avoid
|
# we memoize the pair to avoid
|
||||||
# to redo computation for each line.
|
# to redo computation for each line.
|
||||||
# Follwing code can be done by a single SQL query
|
# Following code can be done by a single SQL query
|
||||||
# but this option is not really maintanable
|
# but this option is not really maintanable
|
||||||
if not context.get('label_memoizer'):
|
if not context.get('label_memoizer'):
|
||||||
context['label_memoizer'] = defaultdict(list)
|
context['label_memoizer'] = defaultdict(list)
|
||||||
@@ -284,15 +285,13 @@ class AccountStatementCompletionRule(Model):
|
|||||||
[('bank_statement_label', '!=', False)])
|
[('bank_statement_label', '!=', False)])
|
||||||
line_ids = tuple(x.id for x in context.get('line_ids', []))
|
line_ids = tuple(x.id for x in context.get('line_ids', []))
|
||||||
for partner in partner_obj.browse(cr, uid, partner_ids, context=context):
|
for partner in partner_obj.browse(cr, uid, partner_ids, context=context):
|
||||||
vals = '|'.join(x.strip() for x in partner.bank_statement_label.split(';'))
|
vals = '|'.join(escape(x.strip()) for x in partner.bank_statement_label.split(';'))
|
||||||
or_regex = ".*%s*." % vals
|
or_regex = ".*%s*." % vals
|
||||||
sql = ("SELECT id from account_bank_statement_line"
|
sql = ("SELECT id from account_bank_statement_line"
|
||||||
" WHERE id in %s"
|
" WHERE id in %s"
|
||||||
" AND name ~* %s")
|
" AND name ~* %s")
|
||||||
cr.execute(sql, (line_ids, or_regex))
|
cr.execute(sql, (line_ids, or_regex))
|
||||||
pairs = cr.fetchall()
|
pairs = cr.fetchall()
|
||||||
if not pairs:
|
|
||||||
continue
|
|
||||||
for pair in pairs:
|
for pair in pairs:
|
||||||
context['label_memoizer'][pair[0]].append(partner)
|
context['label_memoizer'][pair[0]].append(partner)
|
||||||
st_line = st_obj.browse(cr, uid, line_id, context=context)
|
st_line = st_obj.browse(cr, uid, line_id, context=context)
|
||||||
@@ -335,23 +334,22 @@ class AccountStatementCompletionRule(Model):
|
|||||||
st_line = st_obj.browse(cr, uid, line_id, context=context)
|
st_line = st_obj.browse(cr, uid, line_id, context=context)
|
||||||
if st_line:
|
if st_line:
|
||||||
sql = "SELECT id FROM res_partner WHERE name ~* %s"
|
sql = "SELECT id FROM res_partner WHERE name ~* %s"
|
||||||
pattern = ".*%s.*" % st_line.label
|
pattern = ".*%s.*" % escape(st_line.label)
|
||||||
cr.execute(sql, (pattern,))
|
cr.execute(sql, (pattern,))
|
||||||
result = cr.fetchall()
|
result = cr.fetchall()
|
||||||
if not result:
|
if not result:
|
||||||
return res
|
return res
|
||||||
if len(result) > 1:
|
if len(result) > 1:
|
||||||
raise ErrorTooManyPartner(
|
raise ErrorTooManyPartner(_('Line named "%s" (Ref:%s) was matched by more '
|
||||||
_('Line named "%s" (Ref:%s) was matched by more '
|
'than one partner.') %
|
||||||
'than one partner.') %
|
(st_line.name, st_line.ref))
|
||||||
(st_line.name, st_line.ref))
|
|
||||||
res['partner_id'] = result[0][0] if result else False
|
res['partner_id'] = result[0][0] if result else False
|
||||||
if res:
|
if res:
|
||||||
st_vals = st_obj.get_values_for_line(
|
st_vals = st_obj.get_values_for_line(
|
||||||
cr,
|
cr,
|
||||||
uid,
|
uid,
|
||||||
profile_id=st_line.statement_id.profile_id.id,
|
profile_id=st_line.statement_id.profile_id.id,
|
||||||
partner_id=res.get['partner_id'],
|
partner_id=res['partner_id'],
|
||||||
line_type=st_line.type,
|
line_type=st_line.type,
|
||||||
amount=st_line.amount,
|
amount=st_line.amount,
|
||||||
context=context)
|
context=context)
|
||||||
|
|||||||
Reference in New Issue
Block a user