From 4813a728cf9f129b8639550197b65940b33e0640 Mon Sep 17 00:00:00 2001 From: Alexandre Fayolle Date: Wed, 3 Dec 2014 09:15:11 +0100 Subject: [PATCH 1/8] move docstring at top of the module --- account_direct_debit/model/account_invoice.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/account_direct_debit/model/account_invoice.py b/account_direct_debit/model/account_invoice.py index fe2e92337..a8cac7865 100644 --- a/account_direct_debit/model/account_invoice.py +++ b/account_direct_debit/model/account_invoice.py @@ -21,10 +21,6 @@ # along with this program. If not, see . # ############################################################################## - -from openerp.osv import orm -from openerp.tools.translate import _ - """ This module adds support for Direct debit orders as applicable in the Netherlands. Debit orders are advanced in total by the bank. @@ -122,6 +118,9 @@ Two cases need to be distinguisted: open invoices with a matured invoice- or due date. """ +from openerp.osv import orm +from openerp.tools.translate import _ + class account_invoice(orm.Model): _inherit = "account.invoice" From 7a729770586d3c954e794f72e4979f50eed6cbe7 Mon Sep 17 00:00:00 2001 From: Alexandre Fayolle Date: Wed, 3 Dec 2014 09:45:51 +0100 Subject: [PATCH 2/8] fix relative imports --- account_bank_statement_tax/__init__.py | 2 +- account_bank_statement_tax/model/__init__.py | 4 ++-- account_banking/__init__.py | 18 ++++++++-------- account_banking/sepa/__init__.py | 4 +++- account_banking_camt/__init__.py | 2 +- account_banking_nl_abnamro/__init__.py | 2 +- account_banking_nl_ing/__init__.py | 2 +- account_banking_payment/__init__.py | 2 +- account_banking_payment/model/__init__.py | 14 ++++++------- account_banking_tests/tests/__init__.py | 2 +- account_banking_uk_hsbc/__init__.py | 8 +++---- account_banking_uk_hsbc/hsbc_mt940.py | 6 +++--- account_banking_uk_hsbc/mt940_parser.py | 21 +++++++++---------- account_banking_uk_hsbc/wizard/export_hsbc.py | 2 +- account_banking_uk_hsbc/wizard/paymul_test.py | 2 +- account_direct_debit/__init__.py | 2 +- account_direct_debit/model/__init__.py | 10 ++++----- account_iban_preserve_domestic/__init__.py | 2 +- base_iban_bic_not_required/__init__.py | 2 +- base_iban_bic_not_required/model/__init__.py | 2 +- 20 files changed, 55 insertions(+), 54 deletions(-) diff --git a/account_bank_statement_tax/__init__.py b/account_bank_statement_tax/__init__.py index 16e8b082f..9186ee3ad 100644 --- a/account_bank_statement_tax/__init__.py +++ b/account_bank_statement_tax/__init__.py @@ -1 +1 @@ -import model +from . import model diff --git a/account_bank_statement_tax/model/__init__.py b/account_bank_statement_tax/model/__init__.py index 0a522c87a..5d5fe647d 100644 --- a/account_bank_statement_tax/model/__init__.py +++ b/account_bank_statement_tax/model/__init__.py @@ -1,2 +1,2 @@ -import account_bank_statement_line -import account_bank_statement +from . import account_bank_statement_line +from . import account_bank_statement diff --git a/account_banking/__init__.py b/account_banking/__init__.py index d7a19ee70..227d93962 100644 --- a/account_banking/__init__.py +++ b/account_banking/__init__.py @@ -25,12 +25,12 @@ # ############################################################################## -import sepa -import record -import banking_import_transaction -import account_banking -import parsers -import wizard -import res_partner -import res_bank -import res_partner_bank +from . import sepa +from . import record +from . import banking_import_transaction +from . import account_banking +from . import parsers +from . import wizard +from . import res_partner +from . import res_bank +from . import res_partner_bank diff --git a/account_banking/sepa/__init__.py b/account_banking/sepa/__init__.py index 0735d2123..a4fb060a4 100644 --- a/account_banking/sepa/__init__.py +++ b/account_banking/sepa/__init__.py @@ -18,6 +18,8 @@ # along with this program. If not, see . # ############################################################################## -import iban +from . import iban + + IBAN = iban.IBAN BBAN = iban.BBAN diff --git a/account_banking_camt/__init__.py b/account_banking_camt/__init__.py index f8b1d5b3a..26130391c 100644 --- a/account_banking_camt/__init__.py +++ b/account_banking_camt/__init__.py @@ -1 +1 @@ -import camt +from . import camt diff --git a/account_banking_nl_abnamro/__init__.py b/account_banking_nl_abnamro/__init__.py index 151e7f003..cf5962720 100644 --- a/account_banking_nl_abnamro/__init__.py +++ b/account_banking_nl_abnamro/__init__.py @@ -1,2 +1,2 @@ # -*- coding: utf-8 -*- -import abnamro +from . import abnamro diff --git a/account_banking_nl_ing/__init__.py b/account_banking_nl_ing/__init__.py index e25cf133f..87a2f5b07 100644 --- a/account_banking_nl_ing/__init__.py +++ b/account_banking_nl_ing/__init__.py @@ -1,2 +1,2 @@ # -*- coding: utf-8 -*- -import ing +from . import ing diff --git a/account_banking_payment/__init__.py b/account_banking_payment/__init__.py index 16e8b082f..9186ee3ad 100644 --- a/account_banking_payment/__init__.py +++ b/account_banking_payment/__init__.py @@ -1 +1 @@ -import model +from . import model diff --git a/account_banking_payment/model/__init__.py b/account_banking_payment/model/__init__.py index 60600f542..35f98be77 100644 --- a/account_banking_payment/model/__init__.py +++ b/account_banking_payment/model/__init__.py @@ -1,7 +1,7 @@ -import account_payment -import payment_line -import payment_mode -import payment_order_create -import banking_import_transaction -import banking_transaction_wizard -import banking_import_line +from . import account_payment +from . import payment_line +from . import payment_mode +from . import payment_order_create +from . import banking_import_transaction +from . import banking_transaction_wizard +from . import banking_import_line diff --git a/account_banking_tests/tests/__init__.py b/account_banking_tests/tests/__init__.py index 2a658a292..0fdf0f213 100644 --- a/account_banking_tests/tests/__init__.py +++ b/account_banking_tests/tests/__init__.py @@ -1,4 +1,4 @@ -import test_payment_roundtrip +from . import test_payment_roundtrip fast_suite = [ test_payment_roundtrip, diff --git a/account_banking_uk_hsbc/__init__.py b/account_banking_uk_hsbc/__init__.py index 887cb5d93..c2bbe4c8d 100644 --- a/account_banking_uk_hsbc/__init__.py +++ b/account_banking_uk_hsbc/__init__.py @@ -19,8 +19,8 @@ # ############################################################################## -import account_banking_uk_hsbc -import wizard -import hsbc_mt940 -import hsbc_clientid +from . import account_banking_uk_hsbc +from . import wizard +from . import hsbc_mt940 +from . import hsbc_clientid # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: diff --git a/account_banking_uk_hsbc/hsbc_mt940.py b/account_banking_uk_hsbc/hsbc_mt940.py index ea2f45238..6b33d1660 100644 --- a/account_banking_uk_hsbc/hsbc_mt940.py +++ b/account_banking_uk_hsbc/hsbc_mt940.py @@ -20,12 +20,12 @@ ############################################################################## # Import of HSBC data in Swift MT940 format # - -from account_banking.parsers import models -from mt940_parser import HSBCParser import re import logging +from account_banking.parsers import models +from .mt940_parser import HSBCParser + bt = models.mem_bank_transaction logger = logging.getLogger('hsbc_mt940') diff --git a/account_banking_uk_hsbc/mt940_parser.py b/account_banking_uk_hsbc/mt940_parser.py index e8ec6e3a6..1a1d1730d 100644 --- a/account_banking_uk_hsbc/mt940_parser.py +++ b/account_banking_uk_hsbc/mt940_parser.py @@ -27,7 +27,6 @@ Based on fi_patu's parser import re from datetime import datetime - class HSBCParser(object): def __init__(self): @@ -35,18 +34,18 @@ class HSBCParser(object): patterns = {'ebcdic': "\w/\?:\(\).,'+{} -"} # MT940 header - recparse["20"] = ":(?P20):(?P.{1,16})" - recparse["25"] = (":(?P25):(?P\d{6})" - "(?P\d{1,29})") - recparse["28"] = ":(?P28C?):(?P.{1,8})" + recparse["20"] = r":(?P20):(?P.{1,16})" + recparse["25"] = (r":(?P25):(?P\d{6})" + r"(?P\d{1,29})") + recparse["28"] = r":(?P28C?):(?P.{1,8})" # Opening balance 60F - recparse["60F"] = (":(?P60F):(?P[CD])" - "(?P\d{6})(?P.{3})" - "(?P[\d,]{1,15})") + recparse["60F"] = (r":(?P60F):(?P[CD])" + r"(?P\d{6})(?P.{3})" + r"(?P[\d,]{1,15})") # Transaction - recparse["61"] = """\ + recparse["61"] = r"""\ :(?P61):\ (?P\d{6})(?P\d{4})?\ (?PR?[CD])\ @@ -60,7 +59,7 @@ class HSBCParser(object): """ % (patterns) # Further info - recparse["86"] = (":(?P86):" + recparse["86"] = (r":(?P86):" "(?P.{1,80})?" "(?:\n(?P.{1,80}))?" "(?:\n(?P.{1,80}))?" @@ -69,7 +68,7 @@ class HSBCParser(object): # Forward available balance (64) / Closing balance (62F) # / Interim balance (62M) - recparse["64"] = (":(?P64|62[FM]):" + recparse["64"] = (r":(?P64|62[FM]):" "(?P[CD])" "(?P\d{6})(?P.{3})" "(?P[\d,]{1,15})") diff --git a/account_banking_uk_hsbc/wizard/export_hsbc.py b/account_banking_uk_hsbc/wizard/export_hsbc.py index 486432032..012f3cf91 100644 --- a/account_banking_uk_hsbc/wizard/export_hsbc.py +++ b/account_banking_uk_hsbc/wizard/export_hsbc.py @@ -23,7 +23,6 @@ import base64 from datetime import datetime, date from decimal import Decimal -import paymul import string import random import logging @@ -32,6 +31,7 @@ from openerp.osv import orm, fields from openerp.tools import ustr from openerp.tools.translate import _ +from . import paymul def strpdate(arg, format='%Y-%m-%d'): """shortcut""" diff --git a/account_banking_uk_hsbc/wizard/paymul_test.py b/account_banking_uk_hsbc/wizard/paymul_test.py index e6225b93c..057db4042 100644 --- a/account_banking_uk_hsbc/wizard/paymul_test.py +++ b/account_banking_uk_hsbc/wizard/paymul_test.py @@ -21,7 +21,7 @@ import datetime import unittest2 as unittest -import paymul +from . import paymul from decimal import Decimal diff --git a/account_direct_debit/__init__.py b/account_direct_debit/__init__.py index 16e8b082f..9186ee3ad 100644 --- a/account_direct_debit/__init__.py +++ b/account_direct_debit/__init__.py @@ -1 +1 @@ -import model +from . import model diff --git a/account_direct_debit/model/__init__.py b/account_direct_debit/model/__init__.py index b3558c40e..0f9e6e196 100644 --- a/account_direct_debit/model/__init__.py +++ b/account_direct_debit/model/__init__.py @@ -1,5 +1,5 @@ -import account_payment -import payment_line -import account_move_line -import account_invoice -import payment_order_create +from . import account_payment +from . import payment_line +from . import account_move_line +from . import account_invoice +from . import payment_order_create diff --git a/account_iban_preserve_domestic/__init__.py b/account_iban_preserve_domestic/__init__.py index 3f2925496..7ff1ea226 100644 --- a/account_iban_preserve_domestic/__init__.py +++ b/account_iban_preserve_domestic/__init__.py @@ -1 +1 @@ -import res_partner_bank +from . import res_partner_bank diff --git a/base_iban_bic_not_required/__init__.py b/base_iban_bic_not_required/__init__.py index 16e8b082f..9186ee3ad 100644 --- a/base_iban_bic_not_required/__init__.py +++ b/base_iban_bic_not_required/__init__.py @@ -1 +1 @@ -import model +from . import model diff --git a/base_iban_bic_not_required/model/__init__.py b/base_iban_bic_not_required/model/__init__.py index 3f2925496..7ff1ea226 100644 --- a/base_iban_bic_not_required/model/__init__.py +++ b/base_iban_bic_not_required/model/__init__.py @@ -1 +1 @@ -import res_partner_bank +from . import res_partner_bank From fff650242c243135175ff9155d2ce0f23c6c602f Mon Sep 17 00:00:00 2001 From: Alexandre Fayolle Date: Wed, 3 Dec 2014 09:46:47 +0100 Subject: [PATCH 3/8] remove duplicate key in dict --- account_bank_statement_tax/model/account_bank_statement.py | 3 --- 1 file changed, 3 deletions(-) diff --git a/account_bank_statement_tax/model/account_bank_statement.py b/account_bank_statement_tax/model/account_bank_statement.py index 8de910448..59e0d07f4 100644 --- a/account_bank_statement_tax/model/account_bank_statement.py +++ b/account_bank_statement_tax/model/account_bank_statement.py @@ -90,9 +90,6 @@ class AccountBankStatement(orm.Model): defaults['account_id'])), 'credit': tax['amount'] < 0 and - tax['amount'] or 0.0, 'debit': tax['amount'] > 0 and tax['amount'] or 0.0, - 'account_id': ( - tax.get('account_collected_id', - defaults['account_id'])), }) return move_lines, update_move_line From 42f47cfdc86c0ad45b988fe35cf221c14cdcf80c Mon Sep 17 00:00:00 2001 From: Alexandre Fayolle Date: Wed, 3 Dec 2014 09:48:10 +0100 Subject: [PATCH 4/8] use raw strings for regexp with escape sequences --- account_banking/parsers/models.py | 2 +- account_banking_fi_patu/parser.py | 186 +++++++++--------- account_banking_nl_abnamro/abnamro.py | 8 +- account_banking_nl_girotel/girotel.py | 4 +- account_banking_nl_ing/ing.py | 8 +- .../account_banking_nl_ing_mt940.py | 4 +- .../account_banking_nl_rabo_mt940.py | 4 +- account_banking_nl_triodos/triodos.py | 2 +- account_banking_uk_hsbc/hsbc_mt940.py | 4 +- account_banking_uk_hsbc/mt940_parser.py | 18 +- 10 files changed, 120 insertions(+), 120 deletions(-) diff --git a/account_banking/parsers/models.py b/account_banking/parsers/models.py index c94b7e443..c33add722 100644 --- a/account_banking/parsers/models.py +++ b/account_banking/parsers/models.py @@ -397,7 +397,7 @@ class parser(object): param being a company account is not enforced here either. """ def normalize(account_no): - return re.sub('\s', '', account_no) + return re.sub(r'\s', '', account_no) account = normalize(account) cr.execute( diff --git a/account_banking_fi_patu/parser.py b/account_banking_fi_patu/parser.py index 5d5d0bd3b..7df2ca0b6 100644 --- a/account_banking_fi_patu/parser.py +++ b/account_banking_fi_patu/parser.py @@ -27,111 +27,111 @@ class PatuParser(object): recparse = dict() recparse["00"] = ( - "T(?P00)(?P\d{3})" - "(?P\d{3})(?P\d{14})" - "(?P\d{3})(?P\d{6})" - "(?P\d{6})" - "(?P\d{6})(?P\d{4})" - "(?P.{17})(?P\d{6})" - "(?P.{19})" - "(?P\d{6})(?P.{3})" - "(?P.{30})" - "(?P\d{18})(?P.{35})" - "(?P.{40})(?P.{40})" - "(?P.{30})(?P.{30})" + r"T(?P00)(?P\d{3})" + r"(?P\d{3})(?P\d{14})" + r"(?P\d{3})(?P\d{6})" + r"(?P\d{6})" + r"(?P\d{6})(?P\d{4})" + r"(?P.{17})(?P\d{6})" + r"(?P.{19})" + r"(?P\d{6})(?P.{3})" + r"(?P.{30})" + r"(?P\d{18})(?P.{35})" + r"(?P.{40})(?P.{40})" + r"(?P.{30})(?P.{30})" ) recparse["10"] = ( - "T(?P[18]0)(?P\d{3})" - "(?P\d{6})" - "(?P.{18})(?P\d{6})" - "(?P\d{6})" - "(?P\d{6})(?P\d)" - "(?P.{3})(?P.{35})" - "(?P.{19})(?P.)(?P.)" - "(?P.{35})(?P.)" - "(?P.{14})(?P.)" - "(?P.{20})" - "(?P.{8})(?P.)" + r"T(?P[18]0)(?P\d{3})" + r"(?P\d{6})" + r"(?P.{18})(?P\d{6})" + r"(?P\d{6})" + r"(?P\d{6})(?P\d)" + r"(?P.{3})(?P.{35})" + r"(?P.{19})(?P.)(?P.)" + r"(?P.{35})(?P.)" + r"(?P.{14})(?P.)" + r"(?P.{20})" + r"(?P.{8})(?P.)" ) recparse["11"] = ( - "T(?P[18]1)(?P\d{3})" - "(?P.{2})" - "(?:(?# Match specific info)" - "(?<=00)(?P.{35})+" - "|" - "(?<=01)(?P\d{8})" - "|" - "(?<=02)(?P.{10})\s(?P.{15})\s" - "(?P\d{6})" - "|" - "(?<=03)(?P.{19})\s(?P.{14})" - "|" - "(?<=04)(?P.{18})" - "|" - "(?<=05)(?P.{19})\s(?P.{3})\s" - "(?P.{11})(?P.{6})" - "|" - "(?<=06)(?P.{35})(?P.{35})" - "|" - "(?<=07)(?P.{35})" - "(?P.{35})?" - "(?P.{35})?" - "(?P.{35})?" - "(?P.{35})?" - "(?P.{35})?" - "(?P.{35})?" - "(?P.{35})?" - "(?P.{35})?" - "(?P.{35})?" - "(?P.{35})?" - "(?P.{35})?" - "|" - "(?<=08)(?P\d{3})\s(?P.{31})" - "|" - "(?<=09)(?P.{35})" - "|" - "(?<=11)(?P.{35})(?P.{35})" - "(?P.{35})(?P.{70})" - "(?P.{70})(?P.{35})" - "(?P.{70})" - ")" + r"T(?P[18]1)(?P\d{3})" + r"(?P.{2})" + r"(?:(?# Match specific info)" + r"(?<=00)(?P.{35})+" + r"|" + r"(?<=01)(?P\d{8})" + r"|" + r"(?<=02)(?P.{10})\s(?P.{15})\s" + r"(?P\d{6})" + r"|" + r"(?<=03)(?P.{19})\s(?P.{14})" + r"|" + r"(?<=04)(?P.{18})" + r"|" + r"(?<=05)(?P.{19})\s(?P.{3})\s" + r"(?P.{11})(?P.{6})" + r"|" + r"(?<=06)(?P.{35})(?P.{35})" + r"|" + r"(?<=07)(?P.{35})" + r"(?P.{35})?" + r"(?P.{35})?" + r"(?P.{35})?" + r"(?P.{35})?" + r"(?P.{35})?" + r"(?P.{35})?" + r"(?P.{35})?" + r"(?P.{35})?" + r"(?P.{35})?" + r"(?P.{35})?" + r"(?P.{35})?" + r"|" + r"(?<=08)(?P\d{3})\s(?P.{31})" + r"|" + r"(?<=09)(?P.{35})" + r"|" + r"(?<=11)(?P.{35})(?P.{35})" + r"(?P.{35})(?P.{70})" + r"(?P.{70})(?P.{35})" + r"(?P.{70})" + r")" ) recparse["40"] = ( - "T(?P40)(?P\d{3})" - "(?P\d{6})(?P.{19})" - "(?P.{19})" + r"T(?P40)(?P\d{3})" + r"(?P\d{6})(?P.{19})" + r"(?P.{19})" ) recparse["50"] = ( - "T(?P50)(?P\d{3})" - "(?P\d)(?P\d{6})" - "(?P\d{8})(?P.{19})" - "(?P\d{8})(?P.{19})" + r"T(?P50)(?P\d{3})" + r"(?P\d)(?P\d{6})" + r"(?P\d{8})(?P.{19})" + r"(?P\d{8})(?P.{19})" ) recparse["60"] = ( - "T(?P60)(?P\d{3})" - "(?P.{3})(?P01)" - "(?P\d{6})-" - "(?P\d{6})" - "(?P.)(?P.{19})" - "(?P.)(?P\d{7})" - "(?P.)(?P.{19})" - "(?P.)(?P\d{7})" - "(?P.)(?P\d{7})" - "(?P.)(?P.{19})" - "(?P.)(?P.{35})" - "(?P\d{7})" - "(?P.)(?P.{35})" - "(?P\d{7})" + r"T(?P60)(?P\d{3})" + r"(?P.{3})(?P01)" + r"(?P\d{6})-" + r"(?P\d{6})" + r"(?P.)(?P.{19})" + r"(?P.)(?P\d{7})" + r"(?P.)(?P.{19})" + r"(?P.)(?P\d{7})" + r"(?P.)(?P\d{7})" + r"(?P.)(?P.{19})" + r"(?P.)(?P.{35})" + r"(?P\d{7})" + r"(?P.)(?P.{35})" + r"(?P\d{7})" ) recparse["70"] = ( - "T(?P70)(?P\d{3})" - "(?P\d{3})" - "(?P.{80})" - "(?P.{80})?" - "(?P.{80})?" - "(?P.{80})?" - "(?P.{80})?" - "(?P.{80})?" + r"T(?P70)(?P\d{3})" + r"(?P\d{3})" + r"(?P.{80})" + r"(?P.{80})?" + r"(?P.{80})?" + r"(?P.{80})?" + r"(?P.{80})?" + r"(?P.{80})?" ) for record in recparse: recparse[record] = re.compile(recparse[record]) diff --git a/account_banking_nl_abnamro/abnamro.py b/account_banking_nl_abnamro/abnamro.py index 95aff2cf3..013487257 100644 --- a/account_banking_nl_abnamro/abnamro.py +++ b/account_banking_nl_abnamro/abnamro.py @@ -223,7 +223,7 @@ class transaction(models.mem_bank_transaction): transfer_type = 'GIRO' # field has markup 'GIRO ACCOUNT OWNER' # separated by clusters of space of varying size - account_match = re.match('\s*([0-9]+)\s(.*)$', field[5:]) + account_match = re.match(r'\s*([0-9]+)\s(.*)$', field[5:]) if account_match: remote_account = account_match.group(1).zfill(10) remote_owner = account_match.group(2).strip() or '' @@ -245,7 +245,7 @@ class transaction(models.mem_bank_transaction): # format elif field.startswith('MAANDBIJDRAGE ABNAMRO'): transfer_type = 'COSTS' - elif re.match("^\s([0-9]+\.){3}[0-9]+\s", field): + elif re.match(r"^\s([0-9]+\.){3}[0-9]+\s", field): transfer_type = 'BANK' remote_account = field[1:13].strip().replace('.', '').zfill(10) # column 14 to 31 is either empty or contains the remote owner @@ -325,8 +325,8 @@ class transaction(models.mem_bank_transaction): # but can be any numeric line really for field in fields[1:]: m = re.match( - "^\s*((BETALINGSKENM\.)|(ACCEPTGIRO))?\s*([0-9]+" - "([ /][0-9]+)*)\s*$", + r"^\s*((BETALINGSKENM\.)|(ACCEPTGIRO))?\s*([0-9]+" + r"([ /][0-9]+)*)\s*$", field) if m: self.reference = m.group(4) diff --git a/account_banking_nl_girotel/girotel.py b/account_banking_nl_girotel/girotel.py index 997530ed9..8cfe5deaa 100644 --- a/account_banking_nl_girotel/girotel.py +++ b/account_banking_nl_girotel/girotel.py @@ -117,7 +117,7 @@ class transaction_message(object): # payment batch done via clieop if (self.transfer_type == 'VZ' and (not self.remote_account or self.remote_account == '0') - and (not self.message or re.match('^\s*$', self.message)) + and (not self.message or re.match(r'^\s*$', self.message)) and self.remote_owner.startswith('TOTAAL ')): self.transfer_type = 'PB' self.message = self.remote_owner @@ -127,7 +127,7 @@ class transaction_message(object): and not self.remote_account\ and not self.remote_owner\ and re.match( - '^Verzamel Eurobetaling .* TOTAAL \d+ POSTEN\s*$', + r'^Verzamel Eurobetaling .* TOTAAL \d+ POSTEN\s*$', self.message): self.transfer_type = 'PB' else: diff --git a/account_banking_nl_ing/ing.py b/account_banking_nl_ing/ing.py index 9faf70bc6..8a749138c 100644 --- a/account_banking_nl_ing/ing.py +++ b/account_banking_nl_ing/ing.py @@ -116,7 +116,7 @@ class transaction(models.mem_bank_transaction): } # global expression for matching storno references - ref_expr = re.compile('REF[\*:]([0-9A-Z-z_-]+)') + ref_expr = re.compile(r'REF[\*:]([0-9A-Z-z_-]+)') # match references for Acceptgiro's through Internet banking kn_expr = re.compile('KN: ([^ ]+)') @@ -178,8 +178,8 @@ class transaction(models.mem_bank_transaction): before = self.message[:index] self.message = self.message[index:] expression = ( - "^\s*(KN:\s*(?P[^\s]+))?(\s*)" - "(?PNAVR:\s*[^\s]+)?(\s*)(?P.*?)$") + r"^\s*(KN:\s*(?P[^\s]+))?(\s*)" + r"(?PNAVR:\s*[^\s]+)?(\s*)(?P.*?)$") msg_match = re.match(expression, self.message) after = msg_match.group('after') kn = msg_match.group('kn') @@ -196,7 +196,7 @@ class transaction(models.mem_bank_transaction): if parts: zip_city = parts.pop(0).strip() zip_match = re.match( - "^(?P[^ ]{6})\s+(?P.*?)$", zip_city) + r"^(?P[^ ]{6})\s+(?P.*?)$", zip_city) if zip_match: self.remote_owner_postalcode = zip_match.group('zipcode') self.remote_owner_city = zip_match.group('city') diff --git a/account_banking_nl_ing_mt940/account_banking_nl_ing_mt940.py b/account_banking_nl_ing_mt940/account_banking_nl_ing_mt940.py index 82cf6771e..32f560c77 100644 --- a/account_banking_nl_ing_mt940/account_banking_nl_ing_mt940.py +++ b/account_banking_nl_ing_mt940/account_banking_nl_ing_mt940.py @@ -39,8 +39,8 @@ class IngMT940Parser(MT940, parser): code = 'INT_MT940_STRUC' tag_61_regex = re.compile( - '^(?P\d{6})(?P[CD])(?P\d+,\d{2})N(?P.{3})' - '(?P\w{1,16})') + r'^(?P\d{6})(?P[CD])(?P\d+,\d{2})N(?P.{3})' + r'(?P\w{1,16})') def create_transaction(self, cr): return transaction() diff --git a/account_banking_nl_rabo_mt940/account_banking_nl_rabo_mt940.py b/account_banking_nl_rabo_mt940/account_banking_nl_rabo_mt940.py index 7c695ad4d..a3c703578 100644 --- a/account_banking_nl_rabo_mt940/account_banking_nl_rabo_mt940.py +++ b/account_banking_nl_rabo_mt940/account_banking_nl_rabo_mt940.py @@ -38,8 +38,8 @@ class RaboMT940Parser(MT940, parser): header_lines = 1 tag_61_regex = re.compile( - '^(?P\d{6})(?P[CD])(?P\d+,\d{2})N(?P.{3})' - '(?P\w{1,16})') + r'^(?P\d{6})(?P[CD])(?P\d+,\d{2})N(?P.{3})' + r'(?P\w{1,16})') def parse(self, cr, data): 'implements account_banking.parsers.models.parser.parse()' diff --git a/account_banking_nl_triodos/triodos.py b/account_banking_nl_triodos/triodos.py index 3b3ccadd1..9a2418f57 100644 --- a/account_banking_nl_triodos/triodos.py +++ b/account_banking_nl_triodos/triodos.py @@ -61,7 +61,7 @@ class transaction_message(object): self.__dict__.update(dict(zip(self.attrnames, values))) # for lack of a standardized locale function to parse amounts self.transferred_amount = float( - re.sub(',', '.', re.sub('\.', '', self.transferred_amount))) + re.sub(',', '.', re.sub(r'\.', '', self.transferred_amount))) if self.debcred == 'Debet': self.transferred_amount = -self.transferred_amount self.execution_date = str2date(self.date, '%d-%m-%Y') diff --git a/account_banking_uk_hsbc/hsbc_mt940.py b/account_banking_uk_hsbc/hsbc_mt940.py index 6b33d1660..4cc7a2939 100644 --- a/account_banking_uk_hsbc/hsbc_mt940.py +++ b/account_banking_uk_hsbc/hsbc_mt940.py @@ -178,10 +178,10 @@ class parser_hsbc_mt940(models.parser): result = [] parser = HSBCParser() # Split into statements - statements = [st for st in re.split('[\r\n]*(?=:20:)', data)] + statements = [st for st in re.split(r'[\r\n]*(?=:20:)', data)] # Split by records statement_list = [ - re.split('[\r\n ]*(?=:\d\d[\w]?:)', st) + re.split(r'[\r\n ]*(?=:\d\d[\w]?:)', st) for st in statements ] diff --git a/account_banking_uk_hsbc/mt940_parser.py b/account_banking_uk_hsbc/mt940_parser.py index 1a1d1730d..70943c432 100644 --- a/account_banking_uk_hsbc/mt940_parser.py +++ b/account_banking_uk_hsbc/mt940_parser.py @@ -31,7 +31,7 @@ class HSBCParser(object): def __init__(self): recparse = dict() - patterns = {'ebcdic': "\w/\?:\(\).,'+{} -"} + patterns = {'ebcdic': r"\w/\?:\(\).,'+{} -"} # MT940 header recparse["20"] = r":(?P20):(?P.{1,16})" @@ -60,18 +60,18 @@ class HSBCParser(object): # Further info recparse["86"] = (r":(?P86):" - "(?P.{1,80})?" - "(?:\n(?P.{1,80}))?" - "(?:\n(?P.{1,80}))?" - "(?:\n(?P.{1,80}))?" - "(?:\n(?P.{1,80}))?") + r"(?P.{1,80})?" + r"(?:\n(?P.{1,80}))?" + r"(?:\n(?P.{1,80}))?" + r"(?:\n(?P.{1,80}))?" + r"(?:\n(?P.{1,80}))?") # Forward available balance (64) / Closing balance (62F) # / Interim balance (62M) recparse["64"] = (r":(?P64|62[FM]):" - "(?P[CD])" - "(?P\d{6})(?P.{3})" - "(?P[\d,]{1,15})") + r"(?P[CD])" + r"(?P\d{6})(?P.{3})" + r"(?P[\d,]{1,15})") for record in recparse: recparse[record] = re.compile(recparse[record]) From 7b02b88c38a3d4a9eedbe5145250d61f95164345 Mon Sep 17 00:00:00 2001 From: Alexandre Fayolle Date: Wed, 3 Dec 2014 09:50:09 +0100 Subject: [PATCH 5/8] remove crufty work arounds these datetime workarounds are no longer needed in 7.0 --- account_banking/parsers/convert.py | 6 +----- account_banking/record.py | 16 +++------------- 2 files changed, 4 insertions(+), 18 deletions(-) diff --git a/account_banking/parsers/convert.py b/account_banking/parsers/convert.py index c3872b83d..680e7d511 100644 --- a/account_banking/parsers/convert.py +++ b/account_banking/parsers/convert.py @@ -23,11 +23,7 @@ import unicodedata __all__ = ['str2date', 'date2str', 'date2date', 'to_swift'] -try: - from datetime import datetime - datetime.strptime -except AttributeError: - from mx import DateTime as datetime +from datetime import datetime def str2date(datestr, format='%d/%m/%y'): diff --git a/account_banking/record.py b/account_banking/record.py index b0fb4d54a..8d741cebf 100644 --- a/account_banking/record.py +++ b/account_banking/record.py @@ -26,22 +26,12 @@ __all__ = [ __doc__ = '''Ease working with fixed length records in files''' +import unicodedata from datetime import datetime, date -# Correct python2.4 issues -try: - datetime.strptime +def strpdate(str, format): + return datetime.strptime(str, format).date() - def strpdate(str, format): - return datetime.strptime(str, format).date() -except AttributeError: - import time - - def strpdate(str, format): - tm = time.strptime(str, format) - return date(tm.tm_year, tm.tm_mon, tm.tm_mday) - -import unicodedata class Field(object): From ca3d306f7d0f4a8e5fdcb77c68b1477bc2a2d9fc Mon Sep 17 00:00:00 2001 From: Alexandre Fayolle Date: Wed, 3 Dec 2014 09:51:38 +0100 Subject: [PATCH 6/8] print statement fixes convert the print statement to a WARN level log line or to a call to the print function, depending on the context. --- account_banking/sepa/iban.py | 1 + account_banking/struct.py | 2 +- account_banking_fi_patu/parser.py | 4 +++- account_banking_mt940/mt940.py | 10 ++++++---- account_banking_uk_hsbc/mt940_parser.py | 5 ++++- 5 files changed, 15 insertions(+), 7 deletions(-) diff --git a/account_banking/sepa/iban.py b/account_banking/sepa/iban.py index 20deb01c7..0d4e981c1 100644 --- a/account_banking/sepa/iban.py +++ b/account_banking/sepa/iban.py @@ -41,6 +41,7 @@ # deviation to take the warning from SEPA seriously: this is the domain of the # account owning banks. Don't use it, unless you are prepared to loose your # money. It is for heuristic validation purposes only. +from __future__ import print_function __all__ = ['IBAN', 'BBAN'] diff --git a/account_banking/struct.py b/account_banking/struct.py index b5e27e57d..8b511ee85 100644 --- a/account_banking/struct.py +++ b/account_banking/struct.py @@ -23,7 +23,7 @@ Define a struct class which behaves like a dict, but allows using object.attr alongside object['attr']. ''' - +from __future__ import print_function __all__ = ['struct'] diff --git a/account_banking_fi_patu/parser.py b/account_banking_fi_patu/parser.py index 7df2ca0b6..e399e87d2 100644 --- a/account_banking_fi_patu/parser.py +++ b/account_banking_fi_patu/parser.py @@ -3,7 +3,9 @@ """Parser for PATU format files""" import re import datetime +import logging +_logger = logging.getLogger(__name__) def fixchars(line): """Fix the characters mangled in the input @@ -150,7 +152,7 @@ class PatuParser(object): if matchobj: break if not matchobj: - print(" **** failed to match line '%s'" % (line)) + _logger.warning("failed to match line %r", line) return # Strip strings matchdict = matchobj.groupdict() diff --git a/account_banking_mt940/mt940.py b/account_banking_mt940/mt940.py index 010c4b07e..a665dff76 100644 --- a/account_banking_mt940/mt940.py +++ b/account_banking_mt940/mt940.py @@ -23,6 +23,8 @@ """ Parser for MT940 format files """ + +from __future__ import print_function import re import datetime import logging @@ -219,12 +221,12 @@ def main(filename): parser = MT940() parser.parse(None, open(filename, 'r').read()) for statement in parser.statements: - print '''statement found for %(local_account)s at %(date)s + print('''statement found for %(local_account)s at %(date)s with %(local_currency)s%(start_balance)s to %(end_balance)s - ''' % statement.__dict__ + ''' % statement.__dict__) for transaction in statement.transactions: - print ''' - transaction on %(execution_date)s''' % transaction.__dict__ + print(''' + transaction on %(execution_date)s''' % transaction.__dict__) if __name__ == '__main__': import sys diff --git a/account_banking_uk_hsbc/mt940_parser.py b/account_banking_uk_hsbc/mt940_parser.py index 70943c432..100b32e52 100644 --- a/account_banking_uk_hsbc/mt940_parser.py +++ b/account_banking_uk_hsbc/mt940_parser.py @@ -26,6 +26,9 @@ Based on fi_patu's parser """ import re from datetime import datetime +import logging + +_logger = logging.getLogger(__name__) class HSBCParser(object): @@ -86,7 +89,7 @@ class HSBCParser(object): if matchobj: break if not matchobj: - print(" **** failed to match line '%s'" % (line)) + _logger.warning("failed to match line %r", line) return # Strip strings matchdict = matchobj.groupdict() From d9cd6c0ba582e462e4c7ffa6fac5da711146c61c Mon Sep 17 00:00:00 2001 From: Alexandre Fayolle Date: Wed, 3 Dec 2014 09:52:45 +0100 Subject: [PATCH 7/8] 'floating' docstring fixes move module docstrings to the top of the module convert some 'docstrings' to comments remove useless docs --- account_banking/wizard/banking_transaction_wizard.py | 9 ++++----- account_banking_mt940/mt940.py | 3 +-- account_banking_nl_abnamro/abnamro.py | 2 +- 3 files changed, 6 insertions(+), 8 deletions(-) diff --git a/account_banking/wizard/banking_transaction_wizard.py b/account_banking/wizard/banking_transaction_wizard.py index 0ea119aa5..34147c9f1 100644 --- a/account_banking/wizard/banking_transaction_wizard.py +++ b/account_banking/wizard/banking_transaction_wizard.py @@ -21,17 +21,16 @@ # ############################################################################## -from openerp.osv import orm, fields -from openerp.tools.translate import _ - """ - The banking transaction wizard is linked to a button in the statement line tree view. It allows the user to undo the duplicate flag, select between multiple matches or select a manual match. - """ +from openerp.osv import orm, fields +from openerp.tools.translate import _ + + class banking_transaction_wizard(orm.TransientModel): _name = 'banking.transaction.wizard' diff --git a/account_banking_mt940/mt940.py b/account_banking_mt940/mt940.py index a665dff76..d1aa6e408 100644 --- a/account_banking_mt940/mt940.py +++ b/account_banking_mt940/mt940.py @@ -72,7 +72,6 @@ class MT940(object): def __init__(self, *args, **kwargs): super(MT940, self).__init__(*args, **kwargs) - 'state variables' self.current_statement = None 'type account_banking.parsers.models.mem_bank_statement' self.current_transaction = None @@ -200,7 +199,7 @@ class MT940(object): transaction.execution_date = str2date(data[:6]) transaction.effective_date = str2date(data[:6]) transaction.value_date = str2date(data[:6]) - '...and the rest already is highly bank dependent' + # ...and the rest already is highly bank dependent def handle_tag_86(self, cr, data): '''details for previous transaction, here most differences between diff --git a/account_banking_nl_abnamro/abnamro.py b/account_banking_nl_abnamro/abnamro.py index 013487257..1e6bcfc10 100644 --- a/account_banking_nl_abnamro/abnamro.py +++ b/account_banking_nl_abnamro/abnamro.py @@ -60,7 +60,7 @@ class transaction_message(object): _('Invalid transaction line: expected %d columns, found ' '%d') % (len(self.attrnames), len(values)) ) - ''' Strip all values except the blob ''' + # Strip all values except the blob for (key, val) in zip(self.attrnames, values): self.__dict__[key] = key == 'blob' and val or val.strip() # for lack of a standardized locale function to parse amounts From 3478ab1abb31b632e4004e26fc38942576ade156 Mon Sep 17 00:00:00 2001 From: Alexandre Fayolle Date: Wed, 3 Dec 2014 09:55:24 +0100 Subject: [PATCH 8/8] please flake8 about blank lines --- account_banking/record.py | 2 +- account_banking/wizard/banking_transaction_wizard.py | 1 - account_banking_fi_patu/parser.py | 1 + account_banking_uk_hsbc/mt940_parser.py | 2 ++ account_banking_uk_hsbc/wizard/export_hsbc.py | 1 + 5 files changed, 5 insertions(+), 2 deletions(-) diff --git a/account_banking/record.py b/account_banking/record.py index 8d741cebf..d6ac25b0c 100644 --- a/account_banking/record.py +++ b/account_banking/record.py @@ -29,11 +29,11 @@ __doc__ = '''Ease working with fixed length records in files''' import unicodedata from datetime import datetime, date + def strpdate(str, format): return datetime.strptime(str, format).date() - class Field(object): '''Base Field class - fixed length left aligned string field in a record''' def __init__(self, name, length=1, fillchar=' ', cast=str): diff --git a/account_banking/wizard/banking_transaction_wizard.py b/account_banking/wizard/banking_transaction_wizard.py index 34147c9f1..a46e491ee 100644 --- a/account_banking/wizard/banking_transaction_wizard.py +++ b/account_banking/wizard/banking_transaction_wizard.py @@ -31,7 +31,6 @@ from openerp.osv import orm, fields from openerp.tools.translate import _ - class banking_transaction_wizard(orm.TransientModel): _name = 'banking.transaction.wizard' _description = 'Match transaction' diff --git a/account_banking_fi_patu/parser.py b/account_banking_fi_patu/parser.py index e399e87d2..43420d46b 100644 --- a/account_banking_fi_patu/parser.py +++ b/account_banking_fi_patu/parser.py @@ -7,6 +7,7 @@ import logging _logger = logging.getLogger(__name__) + def fixchars(line): """Fix the characters mangled in the input diff --git a/account_banking_uk_hsbc/mt940_parser.py b/account_banking_uk_hsbc/mt940_parser.py index 100b32e52..65449f8c0 100644 --- a/account_banking_uk_hsbc/mt940_parser.py +++ b/account_banking_uk_hsbc/mt940_parser.py @@ -28,8 +28,10 @@ import re from datetime import datetime import logging + _logger = logging.getLogger(__name__) + class HSBCParser(object): def __init__(self): diff --git a/account_banking_uk_hsbc/wizard/export_hsbc.py b/account_banking_uk_hsbc/wizard/export_hsbc.py index 012f3cf91..422a48b0e 100644 --- a/account_banking_uk_hsbc/wizard/export_hsbc.py +++ b/account_banking_uk_hsbc/wizard/export_hsbc.py @@ -33,6 +33,7 @@ from openerp.tools.translate import _ from . import paymul + def strpdate(arg, format='%Y-%m-%d'): """shortcut""" return datetime.strptime(arg, format).date()