mirror of
https://github.com/OCA/bank-payment.git
synced 2025-02-02 10:37:31 +02:00
[IMP] ING/Triodos regain ability to generate friendly bank statement names
[RFR] API change: models.parser.parse() is now called with extra cursor argument [IMP] models.parser.parse() can generate unique statement name
This commit is contained in:
@@ -340,7 +340,20 @@ class parser(object):
|
||||
country_code = None
|
||||
doc = __doc__
|
||||
|
||||
def parse(self, data):
|
||||
def get_unique_statement_id(self, cr, base):
|
||||
name = base
|
||||
suffix = 1
|
||||
while True:
|
||||
cr.execute(
|
||||
"select id from account_bank_statement where name = %s",
|
||||
(name,))
|
||||
if not cr.rowcount:
|
||||
break
|
||||
suffix += 1
|
||||
name = "%s-%d" % (base, suffix)
|
||||
return name
|
||||
|
||||
def parse(self, cr, data):
|
||||
'''
|
||||
Parse data.
|
||||
|
||||
|
||||
@@ -134,7 +134,7 @@ class banking_import(osv.osv_memory):
|
||||
user_obj.browse(cursor, uid, uid, context).company_id)
|
||||
|
||||
# Parse the file
|
||||
statements = parser.parse(data)
|
||||
statements = parser.parse(cursor, data)
|
||||
|
||||
if any([x for x in statements if not x.is_valid()]):
|
||||
raise osv.except_osv(
|
||||
|
||||
@@ -118,7 +118,7 @@ PATU statement format defines one or more statements in each file. This parser
|
||||
will parse all statements in a file and import them to OpenERP
|
||||
''')
|
||||
|
||||
def parse(self, data):
|
||||
def parse(self, cr, data):
|
||||
result = []
|
||||
stmnt = None
|
||||
patuparser = PatuParser()
|
||||
|
||||
@@ -261,26 +261,27 @@ format. Transactions are not explicitely tied to bank statements, although
|
||||
each file covers a period of two weeks.
|
||||
''')
|
||||
|
||||
def parse(self, data):
|
||||
def parse(self, cr, data):
|
||||
result = []
|
||||
stmnt = None
|
||||
lines = data.split('\n')
|
||||
# Transaction lines are not numbered, so keep a tracer
|
||||
subno = 0
|
||||
statement_id = False
|
||||
for line in csv.reader(lines, delimiter = '\t', quoting=csv.QUOTE_NONE):
|
||||
# Skip empty (last) lines
|
||||
if not line:
|
||||
continue
|
||||
subno += 1
|
||||
msg = transaction_message(line, subno)
|
||||
if stmnt and stmnt.id != msg.statement_id:
|
||||
result.append(stmnt)
|
||||
stmnt = None
|
||||
subno = 0
|
||||
if not stmnt:
|
||||
stmnt = statement(msg)
|
||||
else:
|
||||
if not statement_id:
|
||||
statement_id = self.get_unique_statement_id(
|
||||
cr, msg.effective_date.strftime('%Yw%W'))
|
||||
msg.statement_id = statement_id
|
||||
if stmnt:
|
||||
stmnt.import_transaction(msg)
|
||||
else:
|
||||
stmnt = statement(msg)
|
||||
result.append(stmnt)
|
||||
return result
|
||||
|
||||
|
||||
@@ -312,7 +312,7 @@ class parser(models.parser):
|
||||
The Dutch Girotel - Kommagescheiden format is basicly a MS Excel CSV format.
|
||||
''')
|
||||
|
||||
def parse(self, data):
|
||||
def parse(self, cr, data):
|
||||
result = []
|
||||
stmnt = None
|
||||
dialect = csv.excel()
|
||||
|
||||
@@ -200,7 +200,7 @@ distinct from the Dutch multibank format. Transactions are not tied to Bank
|
||||
Statements.
|
||||
''')
|
||||
|
||||
def parse(self, data):
|
||||
def parse(self, cr, data):
|
||||
result = []
|
||||
stmnt = None
|
||||
dialect = csv.excel()
|
||||
@@ -209,17 +209,16 @@ Statements.
|
||||
lines = data.split('\n')
|
||||
# Transaction lines are not numbered, so keep a tracer
|
||||
subno = 0
|
||||
# fixed statement id based on import timestamp
|
||||
statement_id = datetime.now().strftime('%Y-%m-%d %H:%M')
|
||||
statement_id = False
|
||||
for line in csv.reader(lines, dialect=dialect):
|
||||
# Skip empty (last) lines
|
||||
if not line:
|
||||
continue
|
||||
# Skip header line
|
||||
if line[0] == 'Datum':
|
||||
# Skip empty (last) lines and header line
|
||||
if not line or line[0] == 'Datum':
|
||||
continue
|
||||
subno += 1
|
||||
msg = transaction_message(line, subno)
|
||||
if not statement_id:
|
||||
statement_id = self.get_unique_statement_id(
|
||||
cr, msg.effective_date.strftime('%Yw%W'))
|
||||
msg.statement_id = statement_id
|
||||
if stmnt:
|
||||
stmnt.import_transaction(msg)
|
||||
|
||||
@@ -296,7 +296,7 @@ Both formats are covered with this parser. All transactions are tied
|
||||
to Bank Statements.
|
||||
''')
|
||||
|
||||
def parse(self, data):
|
||||
def parse(self, cr, data):
|
||||
result = []
|
||||
stmnt = None
|
||||
dialect = csv.excel()
|
||||
|
||||
@@ -187,7 +187,7 @@ distinct from the Dutch multibank format. Transactions are not tied to Bank
|
||||
Statements.
|
||||
''')
|
||||
|
||||
def parse(self, data):
|
||||
def parse(self, cr, data):
|
||||
result = []
|
||||
stmnt = None
|
||||
dialect = csv.excel()
|
||||
@@ -197,13 +197,16 @@ Statements.
|
||||
# Transaction lines are not numbered, so keep a tracer
|
||||
subno = 0
|
||||
# fixed statement id based on import timestamp
|
||||
statement_id = datetime.now().strftime('%Y-%m-%d %H:%M')
|
||||
statement_id = False
|
||||
for line in csv.reader(lines, dialect=dialect):
|
||||
# Skip empty (last) lines
|
||||
if not line:
|
||||
continue
|
||||
subno += 1
|
||||
msg = transaction_message(line, subno)
|
||||
if not statement_id:
|
||||
statement_id = self.get_unique_statement_id(
|
||||
cr, msg.effective_date.strftime('%Yw%W'))
|
||||
msg.statement_id = statement_id
|
||||
if stmnt:
|
||||
stmnt.import_transaction(msg)
|
||||
|
||||
Reference in New Issue
Block a user