[FIX] pylint errors

This commit is contained in:
Holger Brunn
2014-09-22 12:35:39 +02:00
parent 3969c20eb4
commit db562ca4f6
5 changed files with 15 additions and 103 deletions

View File

@@ -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:

View File

@@ -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

View File

@@ -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

View File

@@ -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()

View File

@@ -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,