[FIX] Simplify query + clean som useless variables

This commit is contained in:
Florian da Costa
2014-02-07 15:42:09 +01:00
parent 6f64c0c102
commit d58a22a7d1
2 changed files with 21 additions and 21 deletions

View File

@@ -91,6 +91,7 @@ class FileParser(BankStatementImportParser):
else: else:
res = self._parse_xls() res = self._parse_xls()
self.result_row_list = res self.result_row_list = res
print "******************", self.result_row_list
return True return True
def _validate(self, *args, **kwargs): def _validate(self, *args, **kwargs):

View File

@@ -22,12 +22,13 @@
from openerp.osv import fields, orm from openerp.osv import fields, orm
from collections import defaultdict from collections import defaultdict
from openerp.addons.account_statement_base_completion.statement import ErrorTooManyPartner
class ErrorTooManyLabel(Exception): class ErrorTooManyLabel(Exception):
""" """
New Exception definition that is raised when more than one label is matched by New Exception definition that is raised when more than one label is matched
the completion rule. by the completion rule.
""" """
def __init__(self, value): def __init__(self, value):
self.value = value self.value = value
@@ -62,7 +63,8 @@ class AccountStatementCompletionRule(orm.Model):
""" """
Match the partner and the account based on the name field of the Match the partner and the account based on the name field of the
statement line and the table account.statement.label. statement line and the table account.statement.label.
If more than one statement label matched, raise the ErrorTooManylabel error. If more than one statement label matched, raise the ErrorTooManylabel
error.
:param int line_id: id of the concerned account.bank.statement.line :param int line_id: id of the concerned account.bank.statement.line
:return: :return:
@@ -74,31 +76,28 @@ class AccountStatementCompletionRule(orm.Model):
...} ...}
""" """
st_obj = self.pool.get('account.bank.statement') st_obj = self.pool.get('account.bank.statement')
st_line_obj = self.pool.get('account.bank.statement.line') statement = st_obj.browse(cr, uid, st_line['statement_id'][0],
label_obj = self.pool.get('account.statement.label') context=context)
statement = st_obj.browse(cr, uid, st_line['statement_id'][0], context=context)
res = {} res = {}
if not context.get('label_memorizer'): if not context.get('label_memorizer'):
context['label_memorizer'] = defaultdict(list) context['label_memorizer'] = defaultdict(list)
for line in statement.line_ids: for line in statement.line_ids:
print "ll***"
sub_query = "SELECT st_l.name FROM account_bank_statement_line as st_l WHERE st_l.id = %s" % (line.id)
sign = "'%'"
cr.execute(""" cr.execute("""
SELECT l.partner_id, SELECT l.partner_id,
l.account_id l.account_id
FROM account_statement_label as l FROM account_statement_label as l,
WHERE ( account_bank_statement as s
SELECT st_l.name LEFT JOIN
FROM account_bank_statement_line as st_l account_bank_statement_line as st_l
WHERE st_l.id = %s) ILIKE %s || l.label || %s ON
AND l.profile_id = ( st_l.statement_id = s.id
SELECT s.profile_id WHERE
FROM account_bank_statement as s st_l.name ~* l.label
LEFT JOIN account_bank_statement_line st_l AND
ON st_l.statement_id = s.id l.profile_id = s.profile_id
WHERE st_l.id = %s) AND
""" % (line.id, sign, sign, line.id)) st_l.id = %s
""" % (line.id))
for partner, account in cr.fetchall(): for partner, account in cr.fetchall():
context['label_memorizer'][line.id].append({'partner_id': partner, context['label_memorizer'][line.id].append({'partner_id': partner,
'account_id': account}) 'account_id': account})