From 9721b91491fe3ce06d77aaedfebd6602a3643471 Mon Sep 17 00:00:00 2001 From: Stefan Rijnhart Date: Tue, 17 Jan 2012 09:48:10 +0100 Subject: [PATCH] [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 --- account_banking/parsers/models.py | 15 ++++++++++++++- account_banking/wizard/bank_import.py | 2 +- account_banking_fi_patu/patu.py | 2 +- account_banking_nl_abnamro/abnamro.py | 17 +++++++++-------- account_banking_nl_girotel/girotel.py | 2 +- account_banking_nl_ing/ing.py | 15 +++++++-------- account_banking_nl_multibank/multibank.py | 2 +- account_banking_nl_triodos/triodos.py | 7 +++++-- 8 files changed, 39 insertions(+), 23 deletions(-) diff --git a/account_banking/parsers/models.py b/account_banking/parsers/models.py index d0451f228..febb959ab 100644 --- a/account_banking/parsers/models.py +++ b/account_banking/parsers/models.py @@ -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. diff --git a/account_banking/wizard/bank_import.py b/account_banking/wizard/bank_import.py index be4dafd70..e70f7aa39 100644 --- a/account_banking/wizard/bank_import.py +++ b/account_banking/wizard/bank_import.py @@ -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( diff --git a/account_banking_fi_patu/patu.py b/account_banking_fi_patu/patu.py index bb197edef..ff5d0c17c 100644 --- a/account_banking_fi_patu/patu.py +++ b/account_banking_fi_patu/patu.py @@ -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() diff --git a/account_banking_nl_abnamro/abnamro.py b/account_banking_nl_abnamro/abnamro.py index 1ff595637..8ae4e5824 100644 --- a/account_banking_nl_abnamro/abnamro.py +++ b/account_banking_nl_abnamro/abnamro.py @@ -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 diff --git a/account_banking_nl_girotel/girotel.py b/account_banking_nl_girotel/girotel.py index 024eb82e0..d78bf115b 100644 --- a/account_banking_nl_girotel/girotel.py +++ b/account_banking_nl_girotel/girotel.py @@ -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() diff --git a/account_banking_nl_ing/ing.py b/account_banking_nl_ing/ing.py index 4f0925c5a..4e6f110b7 100644 --- a/account_banking_nl_ing/ing.py +++ b/account_banking_nl_ing/ing.py @@ -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) diff --git a/account_banking_nl_multibank/multibank.py b/account_banking_nl_multibank/multibank.py index 3c7040919..fb642dfb5 100644 --- a/account_banking_nl_multibank/multibank.py +++ b/account_banking_nl_multibank/multibank.py @@ -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() diff --git a/account_banking_nl_triodos/triodos.py b/account_banking_nl_triodos/triodos.py index 0e6876a95..509652e54 100644 --- a/account_banking_nl_triodos/triodos.py +++ b/account_banking_nl_triodos/triodos.py @@ -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)