From db562ca4f67274e6924718ec9fc17f983ff92bb7 Mon Sep 17 00:00:00 2001 From: Holger Brunn Date: Mon, 22 Sep 2014 12:35:39 +0200 Subject: [PATCH 1/3] [FIX] pylint errors --- account_banking/parsers/convert.py | 4 +- account_banking/record.py | 4 +- account_banking_iban_lookup/online.py | 98 ------------------- account_banking_nl_clieop/wizard/clieop.py | 8 +- .../model/account_move_line.py | 4 +- 5 files changed, 15 insertions(+), 103 deletions(-) diff --git a/account_banking/parsers/convert.py b/account_banking/parsers/convert.py index 2578a0582..689e719ba 100644 --- a/account_banking/parsers/convert.py +++ b/account_banking/parsers/convert.py @@ -51,10 +51,12 @@ _SWIFT = ("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789" "/-?:().,'+ ") -def to_swift(astr, schemes=['utf-8', 'latin-1', 'ascii']): +def to_swift(astr, schemes=None): ''' Reduce a string to SWIFT format ''' + if schemes is None: + schemes = ['utf-8', 'latin-1', 'ascii'] if not isinstance(astr, unicode): for scheme in schemes: try: diff --git a/account_banking/record.py b/account_banking/record.py index 54768e34b..bb986a6de 100644 --- a/account_banking/record.py +++ b/account_banking/record.py @@ -133,7 +133,9 @@ class NumberField(RightAlignedField): class RecordType(object): fields = [] - def __init__(self, fields=[]): + def __init__(self, fields=None): + if fields is None: + fields = [] if fields: self.fields = fields offset = 0 diff --git a/account_banking_iban_lookup/online.py b/account_banking_iban_lookup/online.py index aa1ba3622..9703152c4 100644 --- a/account_banking_iban_lookup/online.py +++ b/account_banking_iban_lookup/online.py @@ -198,101 +198,3 @@ def bank_info(bic): ''' return None, None - - def harvest(soup): - retval = struct() - for trsoup in soup('tr'): - for stage, tdsoup in enumerate(trsoup('td')): - if stage == 0: - attr = tdsoup.contents[0].strip().replace(' ', '_') - elif stage == 2: - if tdsoup.contents: - retval[attr] = tdsoup.contents[0].strip() - else: - retval[attr] = '' - return retval - - # Get form - agent = URLAgent() - request = agent.open(SWIFTlink) - soup = BeautifulSoup(request) - - # Parse request form. As this form is intertwined with a table, use the - # parent as root to search for form elements. - form = SoupForm(soup.find('form', {'id': 'frmFreeSearch1'}), parent=True) - - # Fill form fields - form['selected_bic'] = bic - - # Get intermediate response - response = agent.submit(form) - - # Parse response - soup = BeautifulSoup(response) - - # Isolate the full 11 BIC - there may be more, but we only use the first - bic_button = soup.find('a', {'class': 'bigbuttonblack'}) - if not bic_button: - return None, None - - # Overwrite the location with 'any' ('XXX') to narrow the results to one - # or less. - # Assume this regexp will never fail... - full_bic = bic_re.match(bic_button.get('href')).groups()[0][:8] + 'XXX' - - # Get the detail form - form = SoupForm(soup.find('form', {'id': 'frmDetail'})) - - # Fill detail fields - form['selected_bic11'] = full_bic - - # Get final response - response = agent.submit(form) - soup = BeautifulSoup(response) - - # Now parse the results - tables = soup.find('div', {'id': 'Middle'}).findAll('table') - if not tables: - return None, None - tablesoup = tables[2]('table') - if not tablesoup: - return None, None - - codes = harvest(tablesoup[0]) - if not codes: - return None, None - - bankinfo = struct( - # Most banks use the first four chars of the BIC as an identifier for - # their 'virtual bank' accross the world, containing all national - # banks world wide using the same name. - # The concatenation with the two character country code is for most - # national branches sufficient as a unique identifier. - code=full_bic[:6], - bic=full_bic, - name=codes.Institution_name, - ) - - address = harvest(tablesoup[1]) - # The address in the SWIFT database includes a postal code. - # We need to split it into two fields... - if not address.Zip_Code: - if address.Location: - iso, address.Zip_Code, address.Location = \ - postalcode.split(address.Location, full_bic[4:6]) - - bankaddress = struct( - street=address.Address.title(), - city=address.Location.strip().title(), - zip=address.Zip_Code, - country=address.Country.title(), - country_id=full_bic[4:6], - ) - if ' ' in bankaddress.street: - bankaddress.street, bankaddress.street2 = [ - x.strip() for x in bankaddress.street.split(' ', 1) - ] - else: - bankaddress.street2 = '' - - return bankinfo, bankaddress diff --git a/account_banking_nl_clieop/wizard/clieop.py b/account_banking_nl_clieop/wizard/clieop.py index 15eaf14ea..8818714e7 100644 --- a/account_banking_nl_clieop/wizard/clieop.py +++ b/account_banking_nl_clieop/wizard/clieop.py @@ -289,9 +289,11 @@ class OrdersFile(object): class Transaction(object): '''Generic transaction class''' - def __init__(self, type_=0, name=None, reference=None, messages=[], + def __init__(self, type_=0, name=None, reference=None, messages=None, accountno_beneficiary=None, accountno_payer=None, amount=0): + if messages is None: + messages = [] self.transaction = TransactionRecord() self.paymentreference = Optional(PaymentReferenceRecord) self.description = Optional(DescriptionRecord, 4) @@ -376,8 +378,10 @@ class Batch(object): transactionclass = None def __init__(self, sender, rekeningnr, execution_date=None, - test=True, messages=[], transactiongroup=None, + test=True, messages=None, transactiongroup=None, batch_tracer=1, batch_id=''): + if messages is None: + messages = [] self.header = BatchHeaderRecord() self.fixed_message = Optional(FixedMessageRecord, 4) self.sender = SenderRecord() diff --git a/account_direct_debit/model/account_move_line.py b/account_direct_debit/model/account_move_line.py index 12842e45f..4d5fb4f15 100644 --- a/account_direct_debit/model/account_move_line.py +++ b/account_direct_debit/model/account_move_line.py @@ -27,13 +27,15 @@ from openerp.osv import fields, orm class account_move_line(orm.Model): _inherit = "account.move.line" - def amount_to_receive(self, cr, uid, ids, name, arg={}, context=None): + def amount_to_receive(self, cr, uid, ids, name, arg=None, context=None): """ Return the amount still to receive regarding all the debit orders (excepting canceled orders). This is the reverse from amount_to_pay() in account_payment/account_move_line.py """ + if arg is None: + arg = {} if not ids: return {} cr.execute("""SELECT ml.id, From 9ddc98f2e4016ac78c99b4458889376cc3702d25 Mon Sep 17 00:00:00 2001 From: Holger Brunn Date: Mon, 22 Sep 2014 12:57:50 +0200 Subject: [PATCH 2/3] [FIX] remove unused import --- account_banking_iban_lookup/online.py | 1 - 1 file changed, 1 deletion(-) diff --git a/account_banking_iban_lookup/online.py b/account_banking_iban_lookup/online.py index 9703152c4..8726cce62 100644 --- a/account_banking_iban_lookup/online.py +++ b/account_banking_iban_lookup/online.py @@ -26,7 +26,6 @@ import re import urllib import urllib2 from BeautifulSoup import BeautifulSoup -from openerp.addons.account_banking.sepa import postalcode from openerp.addons.account_banking_iban_lookup.urlagent import ( URLAgent, SoupForm, From 3250c9a1a85dc198a7f24778592e71944be99c6d Mon Sep 17 00:00:00 2001 From: Holger Brunn Date: Tue, 23 Sep 2014 10:01:17 +0200 Subject: [PATCH 3/3] [IMP] use tuples where applicable --- account_banking/parsers/convert.py | 4 +--- account_banking/record.py | 4 +--- account_banking_nl_clieop/wizard/clieop.py | 8 ++------ 3 files changed, 4 insertions(+), 12 deletions(-) diff --git a/account_banking/parsers/convert.py b/account_banking/parsers/convert.py index 689e719ba..c3872b83d 100644 --- a/account_banking/parsers/convert.py +++ b/account_banking/parsers/convert.py @@ -51,12 +51,10 @@ _SWIFT = ("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789" "/-?:().,'+ ") -def to_swift(astr, schemes=None): +def to_swift(astr, schemes=('utf-8', 'latin-1', 'ascii')): ''' Reduce a string to SWIFT format ''' - if schemes is None: - schemes = ['utf-8', 'latin-1', 'ascii'] if not isinstance(astr, unicode): for scheme in schemes: try: diff --git a/account_banking/record.py b/account_banking/record.py index bb986a6de..b0fb4d54a 100644 --- a/account_banking/record.py +++ b/account_banking/record.py @@ -133,9 +133,7 @@ class NumberField(RightAlignedField): class RecordType(object): fields = [] - def __init__(self, fields=None): - if fields is None: - fields = [] + def __init__(self, fields=()): if fields: self.fields = fields offset = 0 diff --git a/account_banking_nl_clieop/wizard/clieop.py b/account_banking_nl_clieop/wizard/clieop.py index 8818714e7..cc38ebc22 100644 --- a/account_banking_nl_clieop/wizard/clieop.py +++ b/account_banking_nl_clieop/wizard/clieop.py @@ -289,11 +289,9 @@ class OrdersFile(object): class Transaction(object): '''Generic transaction class''' - def __init__(self, type_=0, name=None, reference=None, messages=None, + def __init__(self, type_=0, name=None, reference=None, messages=(), accountno_beneficiary=None, accountno_payer=None, amount=0): - if messages is None: - messages = [] self.transaction = TransactionRecord() self.paymentreference = Optional(PaymentReferenceRecord) self.description = Optional(DescriptionRecord, 4) @@ -378,10 +376,8 @@ class Batch(object): transactionclass = None def __init__(self, sender, rekeningnr, execution_date=None, - test=True, messages=None, transactiongroup=None, + test=True, messages=(), transactiongroup=None, batch_tracer=1, batch_id=''): - if messages is None: - messages = [] self.header = BatchHeaderRecord() self.fixed_message = Optional(FixedMessageRecord, 4) self.sender = SenderRecord()