fix flakes8

This commit is contained in:
Yannick Vaucher
2014-07-04 16:24:36 +02:00
parent 5ee3dc7ae0
commit 95cce84d0c
14 changed files with 154 additions and 116 deletions

View File

@@ -23,4 +23,3 @@ import ir_attachment
import pingen
import pingen_document
import res_company

View File

@@ -132,7 +132,7 @@ class Pingen(object):
if response.json['error']:
raise APIError(
"%s: %s" % (response.json['errorcode'], response.json['errormessage']))
"%s: %s" % (response.json['errorcode'], response.json['errormessage']))
return response
@@ -169,10 +169,10 @@ class Pingen(object):
multipart, content_type = encode_multipart_formdata(formdata)
response = self._send(
self.session.post,
'document/upload',
headers={'Content-Type': content_type},
data=multipart)
self.session.post,
'document/upload',
headers={'Content-Type': content_type},
data=multipart)
rjson = response.json
@@ -198,10 +198,10 @@ class Pingen(object):
'color': color,
}
response = self._send(
self.session.post,
'document/send',
params={'id': document_id},
data={'data': json.dumps(data)})
self.session.post,
'document/send',
params={'id': document_id},
data={'data': json.dumps(data)})
return response.json['id']
@@ -212,9 +212,9 @@ class Pingen(object):
:return: dict of infos of the post
"""
response = self._send(
self.session.get,
'post/get',
params={'id': post_id})
self.session.get,
'post/get',
params={'id': post_id})
return response.json['item']
@@ -225,4 +225,3 @@ class Pingen(object):
:param dict post_infos: post infos returned by `post_infos`
"""
return post_infos['status'] == 200

View File

@@ -28,7 +28,7 @@ from openerp.osv import osv, orm, fields
from openerp.tools.translate import _
from openerp import pooler, tools
from .pingen import APIError, ConnectionError, POST_SENDING_STATUS, \
pingen_datetime_to_utc
pingen_datetime_to_utc
_logger = logging.getLogger(__name__)
@@ -94,7 +94,7 @@ class pingen_document(orm.Model):
def _get_pingen_session(self, cr, uid, context=None):
""" Returns a pingen session for a user """
company = self.pool.get('res.users').browse(
cr, uid, uid, context=context).company_id
cr, uid, uid, context=context).company_id
return self.pool.get('res.company')._pingen(cr, uid, company, context=context)
def _push_to_pingen(self, cr, uid, document, pingen=None, context=None):
@@ -105,7 +105,7 @@ class pingen_document(orm.Model):
attachment_obj = self.pool.get('ir.attachment')
decoded_document = attachment_obj._decoded_content(
cr, uid, document.attachment_id, context=context)
cr, uid, document.attachment_id, context=context)
if pingen is None:
pingen = self._get_pingen_session(cr, uid, context=context)
@@ -116,16 +116,16 @@ class pingen_document(orm.Model):
document.pingen_send,
document.pingen_speed,
document.pingen_color)
except ConnectionError as e:
except ConnectionError:
_logger.exception(
'Connection Error when pushing Pingen Document %s to %s.' %
(document.id, pingen.url))
'Connection Error when pushing Pingen Document %s to %s.' %
(document.id, pingen.url))
raise
except APIError as e:
except APIError:
_logger.error(
'API Error when pushing Pingen Document %s to %s.' %
(document.id, pingen.url))
'API Error when pushing Pingen Document %s to %s.' %
(document.id, pingen.url))
raise
error = False
@@ -174,8 +174,8 @@ class pingen_document(orm.Model):
except:
_logger.exception(
'Unexcepted Error when updating the status of pingen.document %s: ' %
document.id)
'Unexcepted Error when updating the status of pingen.document %s: ' %
document.id)
raise osv.except_osv(
_('Error'),
_('Unexcepted Error when updating the status of Document %s') % document.name)
@@ -263,13 +263,13 @@ class pingen_document(orm.Model):
document.pingen_id,
document.pingen_speed,
document.pingen_color)
except ConnectionError as e:
except ConnectionError:
_logger.exception('Connection Error when asking for sending Pingen Document %s to %s.' %
(document.id, pingen.url))
(document.id, pingen.url))
raise
except APIError as e:
except APIError:
_logger.exception('API Error when asking for sending Pingen Document %s to %s.' %
(document.id, pingen.url))
(document.id, pingen.url))
raise
document.write(
@@ -306,8 +306,8 @@ class pingen_document(orm.Model):
except:
_logger.exception(
'Unexcepted Error when updating the status of pingen.document %s: ' %
document.id)
'Unexcepted Error when updating the status of pingen.document %s: ' %
document.id)
raise osv.except_osv(
_('Error'),
_('Unexcepted Error when updating the status of Document %s') % document.name)
@@ -323,22 +323,22 @@ class pingen_document(orm.Model):
try:
post_infos = pingen.post_infos(document.post_id)
except ConnectionError as e:
except ConnectionError:
_logger.exception(
'Connection Error when asking for '
'sending Pingen Document %s to %s.' %
(document.id, pingen.url))
'Connection Error when asking for '
'sending Pingen Document %s to %s.' %
(document.id, pingen.url))
raise
except APIError as e:
except APIError:
_logger.exception(
'API Error when asking for sending Pingen Document %s to %s.' %
(document.id, pingen.url))
'API Error when asking for sending Pingen Document %s to %s.' %
(document.id, pingen.url))
raise
currency_ids = self.pool.get('res.currency').search(
cr, uid, [('name', '=', post_infos['currency'])], context=context)
cr, uid, [('name', '=', post_infos['currency'])], context=context)
country_ids = self.pool.get('res.country').search(
cr, uid, [('code', '=', post_infos['country'])], context=context)
cr, uid, [('code', '=', post_infos['country'])], context=context)
send_date = pingen_datetime_to_utc(infos['date'])
@@ -369,9 +369,9 @@ class pingen_document(orm.Model):
"""
if not ids:
ids = self.search(
cr, uid,
[('state', '=', 'sendcenter')],
context=context)
cr, uid,
[('state', '=', 'sendcenter')],
context=context)
with closing(pooler.get_db(cr.dbname).cursor()) as loc_cr, \
self._get_pingen_session(cr, uid, context=context) as session:
@@ -417,10 +417,9 @@ class pingen_document(orm.Model):
except:
_logger.exception(
'Unexcepted Error when updating the status of pingen.document %s: ' %
document.id)
'Unexcepted Error when updating the status of pingen.document %s: ' %
document.id)
raise osv.except_osv(
_('Error'),
_('Unexcepted Error when updating the status of Document %s') % document.name)
return True

View File

@@ -23,6 +23,7 @@ from openerp.osv import orm, fields
from openerp.osv.orm import browse_record
from .pingen import Pingen
class res_company(orm.Model):
_inherit = 'res.company'
@@ -39,4 +40,3 @@ class res_company(orm.Model):
if not isinstance(company, browse_record):
company = self.browse(cr, uid, company, context=context)
return Pingen(company.pingen_token, staging=company.pingen_staging)