From 5033da0104b0e785c8f0730bd1e14061d12ac1e2 Mon Sep 17 00:00:00 2001 From: Laetitia Gangloff Date: Mon, 28 Sep 2015 11:49:45 +0200 Subject: [PATCH 1/5] [PEP8] - base_report_to_printer --- base_report_to_printer/__openerp__.py | 5 ++-- base_report_to_printer/ir_report.py | 28 +++++++++++-------- base_report_to_printer/printing.py | 23 +++++++++------ base_report_to_printer/report_service.py | 27 ++++++++++-------- base_report_to_printer/report_xml_action.py | 18 ++++++------ base_report_to_printer/users.py | 11 ++++---- .../wizard/update_printers.py | 10 ++----- 7 files changed, 67 insertions(+), 55 deletions(-) diff --git a/base_report_to_printer/__openerp__.py b/base_report_to_printer/__openerp__.py index 6bc9369..3ba8cac 100644 --- a/base_report_to_printer/__openerp__.py +++ b/base_report_to_printer/__openerp__.py @@ -78,7 +78,8 @@ Contributors * Lionel Sausin """, - 'author': "Agile Business Group & Domsense, Pegueroles SCP, NaN,Odoo Community Association (OCA)", + 'author': "Agile Business Group & Domsense, Pegueroles SCP, NaN," + "Odoo Community Association (OCA)", 'website': 'http://www.agilebg.com', 'license': 'AGPL-3', "depends": ['base', 'base_calendar'], @@ -93,5 +94,5 @@ Contributors 'application': True, 'external_dependencies': { 'python': ['cups'] - } + } } diff --git a/base_report_to_printer/ir_report.py b/base_report_to_printer/ir_report.py index 96cd1c1..fb3e36d 100644 --- a/base_report_to_printer/ir_report.py +++ b/base_report_to_printer/ir_report.py @@ -32,6 +32,7 @@ from openerp.osv import orm, fields class report_xml(orm.Model): + """ Reports """ @@ -45,7 +46,8 @@ class report_xml(orm.Model): options['raw'] = True return options - def print_direct(self, cr, uid, report_id, result, format, printer, context=None): + def print_direct(self, cr, uid, report_id, result, format, printer, + context=None): fd, file_name = mkstemp() try: os.write(fd, base64.decodestring(result)) @@ -59,9 +61,11 @@ class report_xml(orm.Model): printer_system_name = printer.system_name connection = cups.Connection() - options = self.set_print_options(cr, uid, report_id, format, context=context) + options = self.set_print_options(cr, uid, report_id, format, + context=context) - connection.printFile(printer_system_name, file_name, file_name, options=options) + connection.printFile(printer_system_name, file_name, file_name, + options=options) logger = logging.getLogger('base_report_to_printer') logger.info("Printing job : '%s'" % file_name) return True @@ -69,20 +73,20 @@ class report_xml(orm.Model): _inherit = 'ir.actions.report.xml' _columns = { 'property_printing_action': fields.property( - #'ir.actions.report.xml', + # 'ir.actions.report.xml', 'printing.action', type='many2one', relation='printing.action', string='Action', view_load=True, method=True, - ), + ), 'printing_printer_id': fields.many2one('printing.printer', 'Printer'), 'printing_action_ids': fields.one2many( 'printing.report.xml.action', 'report_id', 'Actions', help='This field allows configuring action and printer on a per ' 'user basis'), - } + } def behaviour(self, cr, uid, ids, context=None): result = {} @@ -93,7 +97,8 @@ class report_xml(orm.Model): # Retrieve system wide printer default_printer = printer_obj.get_default(cr, uid, context=context) if default_printer: - default_printer = printer_obj.browse(cr, uid, default_printer, context=context) + default_printer = printer_obj.browse(cr, uid, default_printer, + context=context) # Retrieve user default values user = self.pool['res.users'].browse(cr, uid, uid, context=context) @@ -107,8 +112,8 @@ class report_xml(orm.Model): printer = default_printer # Retrieve report default values - if (report.property_printing_action - and report.property_printing_action.type != 'user_default'): + if (report.property_printing_action and + report.property_printing_action.type != 'user_default'): action = report.property_printing_action.type if report.printing_printer_id: printer = report.printing_printer_id @@ -120,7 +125,8 @@ class report_xml(orm.Model): ('user_id', '=', uid), ('action', '!=', 'user_default')], context=context) if act_ids: - user_action = printing_act_obj.behaviour(cr, uid, act_ids[0], context) + user_action = printing_act_obj.behaviour(cr, uid, act_ids[0], + context) action = user_action['action'] if user_action['printer']: printer = user_action['printer'] @@ -128,5 +134,5 @@ class report_xml(orm.Model): result[report.id] = { 'action': action, 'printer': printer, - } + } return result diff --git a/base_report_to_printer/printing.py b/base_report_to_printer/printing.py index 2d0cc1b..9abbf29 100644 --- a/base_report_to_printer/printing.py +++ b/base_report_to_printer/printing.py @@ -34,6 +34,7 @@ from openerp.tools.translate import _ class printing_printer(orm.Model): + """ Printers """ @@ -78,14 +79,14 @@ class printing_printer(orm.Model): 'URI', size=500, readonly=True), - } + } _order = "name" _defaults = { 'default': lambda *a: False, 'status': lambda *a: 'unknown', - } + } def __init__(self, pool, cr): super(printing_printer, self).__init__(pool, cr) @@ -113,7 +114,7 @@ class printing_printer(orm.Model): if context is None: context = {} try: - # Skip update to avoid the thread being created again + # Skip update to avoid the thread being created again ctx = context.copy() ctx['skip_update'] = True ids = self.search(cr, uid, [], context=ctx) @@ -151,7 +152,8 @@ class printing_printer(orm.Model): return self.updating = True self.lock.release() - thread = Thread(target=self.update_printers_status, args=(cr.dbname, uid, context.copy())) + thread = Thread(target=self.update_printers_status, + args=(cr.dbname, uid, context.copy())) thread.start() def update(self, cr, uid, context=None): @@ -161,7 +163,8 @@ class printing_printer(orm.Model): return True last_update = self.last_update now = time.time() - # Only update printer status if current status is more than 10 seconds old. + # Only update printer status if current status is more than + # 10 seconds old. if not last_update or now - last_update > 10: self.start_printer_update(cr, uid, context) # Wait up to five seconds for printer status update @@ -178,7 +181,8 @@ class printing_printer(orm.Model): ).search(cr, uid, args, offset, limit, order, context, count) - def read(self, cr, uid, ids, fields=None, context=None, load='_classic_read'): + def read(self, cr, uid, ids, fields=None, context=None, + load='_classic_read'): self.update(cr, uid, context) return super(printing_printer, self ).read(cr, uid, ids, fields, context, load) @@ -211,7 +215,7 @@ def _available_action_types(self, cr, uid, context=None): ('server', _('Send to Printer')), ('client', _('Send to Client')), ('user_default', _("Use user's defaults")), - ] + ] class printing_action(orm.Model): @@ -220,5 +224,6 @@ class printing_action(orm.Model): _columns = { 'name': fields.char('Name', size=256, required=True), - 'type': fields.selection(_available_action_types, 'Type', required=True), - } + 'type': fields.selection(_available_action_types, 'Type', + required=True), + } diff --git a/base_report_to_printer/report_service.py b/base_report_to_printer/report_service.py index d4f936b..da4a8b1 100644 --- a/base_report_to_printer/report_service.py +++ b/base_report_to_printer/report_service.py @@ -31,7 +31,8 @@ from openerp.addons.base_calendar import base_calendar class virtual_report_spool(base_calendar.virtual_report_spool): def exp_report(self, db, uid, object, ids, datas=None, context=None): - res = super(virtual_report_spool, self).exp_report(db, uid, object, ids, datas, context) + res = super(virtual_report_spool, self).exp_report( + db, uid, object, ids, datas, context) self._reports[res]['report_name'] = object return res @@ -43,22 +44,27 @@ class virtual_report_spool(base_calendar.virtual_report_spool): # First of all load report defaults: name, action and printer report_obj = pool.get('ir.actions.report.xml') report = report_obj.search( - cr, uid, [('report_name', '=', self._reports[report_id]['report_name'])]) + cr, uid, [('report_name', '=', + self._reports[report_id]['report_name'])]) if report: report = report_obj.browse(cr, uid, report[0]) data = report.behaviour()[report.id] action = data['action'] printer = data['printer'] if action != 'client': - if (self._reports and self._reports.get(report_id, False) - and self._reports[report_id].get('result', False) - and self._reports[report_id].get('format', False)): + if (self._reports and + self._reports.get(report_id, False) and + self._reports[report_id].get('result', False) and + self._reports[report_id].get('format', False)): report_obj.print_direct( - cr, uid, report.id, base64.encodestring(self._reports[report_id]['result']), + cr, uid, report.id, base64.encodestring( + self._reports[report_id]['result']), self._reports[report_id]['format'], printer) # FIXME "Warning" removed as it breaks the workflow - # it would be interesting to have a dialog box to confirm if we really want to print - # in this case it must be with a by pass parameter to allow massive impression + # it would be interesting to have a dialog box to + # confirm if we really want to print + # in this case it must be with a by pass parameter to + # allow massive impression # raise osv.except_osv( # _('Printing...'), # _('Document sent to printer %s') % (printer,)) @@ -69,9 +75,8 @@ class virtual_report_spool(base_calendar.virtual_report_spool): finally: cr.close() - res = super(virtual_report_spool, self).exp_report_get(db, uid, report_id) + res = super(virtual_report_spool, self).exp_report_get(db, uid, + report_id) return res virtual_report_spool() - -# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: diff --git a/base_report_to_printer/report_xml_action.py b/base_report_to_printer/report_xml_action.py index d1ca02b..679a8b6 100644 --- a/base_report_to_printer/report_xml_action.py +++ b/base_report_to_printer/report_xml_action.py @@ -26,25 +26,25 @@ from openerp.osv import orm, fields from printing import _available_action_types + class report_xml_action(orm.Model): _name = 'printing.report.xml.action' _description = 'Report Printing Actions' _columns = { - 'report_id': fields.many2one('ir.actions.report.xml', 'Report', required=True, ondelete='cascade'), - 'user_id': fields.many2one('res.users', 'User', required=True, ondelete='cascade'), - 'action': fields.selection(_available_action_types, 'Action', required=True), + 'report_id': fields.many2one('ir.actions.report.xml', 'Report', + required=True, ondelete='cascade'), + 'user_id': fields.many2one('res.users', 'User', required=True, + ondelete='cascade'), + 'action': fields.selection(_available_action_types, 'Action', + required=True), 'printer_id': fields.many2one('printing.printer', 'Printer'), - } - + } def behaviour(self, cr, uid, act_id, context=None): - result = {} if not act_id: return False action = self.browse(cr, uid, act_id, context=context) return { 'action': action.action, 'printer': action.printer_id, - } - -# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: + } diff --git a/base_report_to_printer/users.py b/base_report_to_printer/users.py index 1aa546e..29af48c 100644 --- a/base_report_to_printer/users.py +++ b/base_report_to_printer/users.py @@ -28,6 +28,7 @@ from printing import _available_action_types class res_users(orm.Model): + """ Users """ @@ -41,8 +42,8 @@ class res_users(orm.Model): if x[0] != 'user_default'] _columns = { - 'printing_action': fields.selection(_user_available_action_types, 'Printing Action'), - 'printing_printer_id': fields.many2one('printing.printer', 'Default Printer'), - } - -# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: + 'printing_action': fields.selection(_user_available_action_types, + 'Printing Action'), + 'printing_printer_id': fields.many2one('printing.printer', + 'Default Printer'), + } diff --git a/base_report_to_printer/wizard/update_printers.py b/base_report_to_printer/wizard/update_printers.py index d599a03..bc233ec 100644 --- a/base_report_to_printer/wizard/update_printers.py +++ b/base_report_to_printer/wizard/update_printers.py @@ -29,9 +29,6 @@ from openerp.osv import orm class printing_printer_update_wizard(orm.TransientModel): _name = "printing.printer.update.wizard" - _columns = { - } - def action_cancel(self, cr, uid, ids, context=None): return {} @@ -57,7 +54,7 @@ class printing_printer_update_wizard(orm.TransientModel): 'model': printer.get('printer-make-and-model', False), 'location': printer.get('printer-location', False), 'uri': printer.get('device-uri', False), - }, context) + }, context) return { 'name': 'Printers', @@ -66,7 +63,4 @@ class printing_printer_update_wizard(orm.TransientModel): 'res_model': 'printing.printer', 'type': 'ir.actions.act_window', 'target': 'current', - } - - -# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: + } From 4d567c52c028be9e6f999d82ef53bfa5bb2b1cf5 Mon Sep 17 00:00:00 2001 From: Laetitia Gangloff Date: Mon, 28 Sep 2015 12:22:56 +0200 Subject: [PATCH 2/5] [IMP] update README.md, .travis.yml to latest MQT template / add transifex support --- .travis.yml | 36 ++++++++++++++++++++++++------------ README.md | 15 +++++++++++++++ 2 files changed, 39 insertions(+), 12 deletions(-) diff --git a/.travis.yml b/.travis.yml index 9820f2f..7e49412 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,6 +1,10 @@ +language: python sudo: false cache: pip +python: + - "2.7" + addons: apt: packages: @@ -9,24 +13,32 @@ addons: - cups - libcups2-dev -language: python -python: - - "2.7" +env: + global: + - VERSION="7.0" TESTS="0" LINT_CHECK="0" TRANSIFEX="0" + - TRANSIFEX_USER='transbot@odoo-community.org' + - secure: PjP88tPSwimBv4tsgn3UcQAD1heK/wcuSaSfhi2xUt/jSrOaTmWzjaW2gH/eKM1ilxPXwlPGyAIShJ2JJdBiA97hQufOeiqxdkWDctnNVVEDx2Tk0BiG3PPYyhXPgUZ+FNOnjZFF3pNWvzXTQaB0Nvz8plqp93Ov/DEyhrCxHDs= + + matrix: + - LINT_CHECK="1" + - TRANSIFEX="1" + - TESTS="1" ODOO_REPO="odoo/odoo" + - TESTS="1" ODOO_REPO="OCA/OCB" virtualenv: system_site_packages: true install: - - git clone https://github.com/OCA/maintainer-quality-tools.git $HOME/maintainer-quality-tools - - export PATH=$HOME/maintainer-quality-tools/travis:$PATH - - travis_install_nightly - - pip install pycups==1.9.66 - - pip install PyPDF2==1.18 - - pip install requests - - git clone https://github.com/OCA/reporting-engine -b ${VERSION} $HOME/reporting-engine + - git clone --depth=1 https://github.com/OCA/maintainer-quality-tools.git ${HOME}/maintainer-quality-tools + - export PATH=${HOME}/maintainer-quality-tools/travis:${PATH} + - travis_install_nightly + - pip install pycups==1.9.66 + - pip install PyPDF2==1.18 + - pip install requests + - git clone https://github.com/OCA/reporting-engine -b ${VERSION} ${HOME}/reporting-engine script: - - travis_run_tests + - travis_run_tests after_success: - coveralls + - travis_after_tests_success diff --git a/README.md b/README.md index 53eeaa3..290a7db 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,8 @@ +[![Runbot Status](https://runbot.odoo-community.org/runbot/badge/flat/144/7.0.svg)](https://runbot.odoo-community.org/runbot/repo/github-com-oca-report-print-send-144) [![Build Status](https://travis-ci.org/OCA/report-print-send.svg?branch=7.0)](https://travis-ci.org/OCA/report-print-send) [![Coverage Status](https://coveralls.io/repos/OCA/report-print-send/badge.png?branch=7.0)](https://coveralls.io/r/OCA/report-print-send?branch=7.0) +[![Code Climate](https://codeclimate.com/github/OCA/report-print-send/badges/gpa.svg)](https://codeclimate.com/github/OCA/report-pint-send) + Report - Printing and Sending ============================= @@ -10,3 +13,15 @@ This project aim to deal with modules related to manage document printing and se - Add an printing queue - Allow to choose printer - ... + +Translation Status +------------------ +[![Transifex Status](https://www.transifex.com/projects/p/OCA-report-print-send-7-0/chart/image_png)](https://www.transifex.com/projects/p/OCA-report-print-send-7-0) + +---- + +OCA, or the Odoo Community Association, is a nonprofit organization whose +mission is to support the collaborative development of Odoo features and +promote its widespread use. + +http://odoo-community.org/ From 5e46167775ce482b7a20496ec2fae71b7f673819 Mon Sep 17 00:00:00 2001 From: Laetitia Gangloff Date: Mon, 28 Sep 2015 12:33:55 +0200 Subject: [PATCH 3/5] [PEP8] - pingen --- pingen/__openerp__.py | 8 ++--- pingen/ir_attachment.py | 32 ++++++++++++------- pingen/pingen.py | 16 +++++++--- pingen/pingen_document.py | 66 ++++++++++++++++++++++++++------------- 4 files changed, 79 insertions(+), 43 deletions(-) diff --git a/pingen/__openerp__.py b/pingen/__openerp__.py index 4ae5dc8..93b796d 100644 --- a/pingen/__openerp__.py +++ b/pingen/__openerp__.py @@ -30,7 +30,7 @@ 'depends': [], 'external_dependencies': { 'python': ['requests'], - }, + }, 'description': """ Integration with pingen.com =========================== @@ -91,8 +91,8 @@ you will need to manually handle the case, either from the pingen.com backend, or by changing the document on OpenERP and resolving the error on the Pingen Document. -When a connection error occurs, the action will be retried on the next scheduler -run. +When a connection error occurs, the action will be retried on the next +scheduler run. Dependencies ------------ @@ -111,7 +111,7 @@ Dependencies 'pingen_data.xml', 'res_company_view.xml', 'security/ir.model.access.csv', - ], + ], 'tests': [], 'installable': False, 'auto_install': False, diff --git a/pingen/ir_attachment.py b/pingen/ir_attachment.py index ba00c47..6f5b7a0 100644 --- a/pingen/ir_attachment.py +++ b/pingen/ir_attachment.py @@ -41,8 +41,10 @@ class ir_attachment(orm.Model): 'pingen_speed': fields.selection( [('1', 'Priority'), ('2', 'Economy')], 'Speed', - help="Defines the sending speed if the document is automatically sent"), - 'pingen_color': fields.selection([('0', 'B/W'), ('1', 'Color')], 'Type of print'), + help="Defines the sending speed if the document is " + "automatically sent"), + 'pingen_color': fields.selection([('0', 'B/W'), ('1', 'Color')], + 'Type of print'), } _defaults = { @@ -56,14 +58,15 @@ class ir_attachment(orm.Model): 'config': 'created from attachment'} def _handle_pingen_document(self, cr, uid, attachment_id, context=None): - """ Reponsible of the related ``pingen.document`` when the ``send_to_pingen`` - field is modified. + """ Reponsible of the related ``pingen.document`` + when the ``send_to_pingen`` field is modified. Only one pingen document can be created per attachment. When ``send_to_pingen`` is activated: * Create a ``pingen.document`` if it does not already exist - * Put the related ``pingen.document`` to ``pending`` if it already exist + * Put the related ``pingen.document`` to ``pending`` if + it already exist When it is deactivated: * Do nothing if no related ``pingen.document`` exists * Or cancel it @@ -72,7 +75,8 @@ class ir_attachment(orm.Model): """ pingen_document_obj = self.pool.get('pingen.document') attachment = self.browse(cr, uid, attachment_id, context=context) - document = attachment.pingen_document_ids[0] if attachment.pingen_document_ids else None + document = attachment.pingen_document_ids[ + 0] if attachment.pingen_document_ids else None if attachment.send_to_pingen: if document: document.write({'state': 'pending'}, context=context) @@ -87,22 +91,26 @@ class ir_attachment(orm.Model): if document.state == 'pushed': raise osv.except_osv( _('Error'), - _('The attachment %s is already pushed to pingen.com.') % - attachment.name) + _('The attachment %s is already pushed to ' + 'pingen.com.') % attachment.name) document.write({'state': 'canceled'}, context=context) return def create(self, cr, uid, vals, context=None): - attachment_id = super(ir_attachment, self).create(cr, uid, vals, context=context) + attachment_id = super(ir_attachment, self).create( + cr, uid, vals, context=context) if 'send_to_pingen' in vals: - self._handle_pingen_document(cr, uid, attachment_id, context=context) + self._handle_pingen_document( + cr, uid, attachment_id, context=context) return attachment_id def write(self, cr, uid, ids, vals, context=None): - res = super(ir_attachment, self).write(cr, uid, ids, vals, context=context) + res = super(ir_attachment, self).write( + cr, uid, ids, vals, context=context) if 'send_to_pingen' in vals: for attachment_id in ids: - self._handle_pingen_document(cr, uid, attachment_id, context=context) + self._handle_pingen_document( + cr, uid, attachment_id, context=context) return res def _decoded_content(self, cr, uid, attachment, context=None): diff --git a/pingen/pingen.py b/pingen/pingen.py index 475407b..df35a3f 100644 --- a/pingen/pingen.py +++ b/pingen/pingen.py @@ -58,19 +58,23 @@ def pingen_datetime_to_utc(dt): class PingenException(RuntimeError): + """There was an ambiguous exception that occurred while handling your request.""" class ConnectionError(PingenException): + """An Error occured with the pingen API""" class APIError(PingenException): + """An Error occured with the pingen API""" class Pingen(object): + """ Interface to the pingen.com API """ def __init__(self, token, staging=True): @@ -132,11 +136,13 @@ 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 - def push_document(self, filename, filestream, send=None, speed=None, color=None): + def push_document(self, filename, filestream, send=None, speed=None, + color=None): """ Upload a document to pingen.com and eventually ask to send it :param str filename: name of the file to push @@ -154,7 +160,7 @@ class Pingen(object): 'send': send, 'speed': speed, 'color': color, - } + } # we cannot use the `files` param alongside # with the `datas`param when data is a @@ -164,7 +170,7 @@ class Pingen(object): formdata = { 'file': (filename, filestream.read()), 'data': json.dumps(data), - } + } multipart, content_type = encode_multipart_formdata(formdata) @@ -196,7 +202,7 @@ class Pingen(object): data = { 'speed': speed, 'color': color, - } + } response = self._send( self.session.post, 'document/send', diff --git a/pingen/pingen_document.py b/pingen/pingen_document.py index ac59a02..de7e399 100644 --- a/pingen/pingen_document.py +++ b/pingen/pingen_document.py @@ -34,6 +34,7 @@ _logger = logging.getLogger(__name__) class pingen_document(orm.Model): + """ A pingen document is the state of the synchronization of an attachment with pingen.com @@ -75,7 +76,8 @@ class pingen_document(orm.Model): 'post_status': fields.char('Post Status', size=128, readonly=True), 'parsed_address': fields.text('Parsed Address', readonly=True), 'cost': fields.float('Cost', readonly=True), - 'currency_id': fields.many2one('res.currency', 'Currency', readonly=True), + 'currency_id': fields.many2one('res.currency', 'Currency', + readonly=True), 'country_id': fields.many2one('res.country', 'Country', readonly=True), 'send_date': fields.datetime('Date of sending', readonly=True), 'pages': fields.integer('Pages', readonly=True), @@ -95,7 +97,8 @@ class pingen_document(orm.Model): """ Returns a pingen session for a user """ company = self.pool.get('res.users').browse( cr, uid, uid, context=context).company_id - return self.pool.get('res.company')._pingen(cr, uid, company, context=context) + return self.pool.get('res.company')._pingen(cr, uid, company, + context=context) def _push_to_pingen(self, cr, uid, document, pingen=None, context=None): """ Push a document to pingen.com @@ -141,11 +144,13 @@ class pingen_document(orm.Model): document.write( {'last_error_message': error, 'state': state, - 'push_date': push_date.strftime(tools.DEFAULT_SERVER_DATETIME_FORMAT), + 'push_date': push_date.strftime( + tools.DEFAULT_SERVER_DATETIME_FORMAT), 'pingen_id': doc_id, 'post_id': post_id}, context=context) - _logger.info('Pingen Document %s: pushed to %s' % (document.id, pingen.url)) + _logger.info('Pingen Document %s: pushed to %s' % (document.id, + pingen.url)) def push_to_pingen(self, cr, uid, ids, context=None): """ Push a document to pingen.com @@ -164,7 +169,8 @@ class pingen_document(orm.Model): except ConnectionError as e: raise osv.except_osv( _('Pingen Connection Error'), - _('Connection Error when asking for sending the document %s to Pingen') % document.name) + _('Connection Error when asking for sending the ' + 'document %s to Pingen') % document.name) except APIError as e: raise osv.except_osv( @@ -174,11 +180,13 @@ class pingen_document(orm.Model): except: _logger.exception( - 'Unexcepted Error when updating the status of pingen.document %s: ' % + '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) + _('Unexcepted Error when updating the status ' + 'of Document %s') % document.name) return True def _push_and_send_to_pingen_cron(self, cr, uid, ids, context=None): @@ -209,11 +217,13 @@ class pingen_document(orm.Model): try: if document.state == 'pending': self._push_to_pingen( - loc_cr, uid, document, pingen=session, context=context) + loc_cr, uid, document, pingen=session, + context=context) elif document.state == 'pushed': self._ask_pingen_send( - loc_cr, uid, document, pingen=session, context=context) + loc_cr, uid, document, pingen=session, + context=context) except ConnectionError as e: document.write({'last_error_message': e, 'state': 'error'}, @@ -264,11 +274,13 @@ class pingen_document(orm.Model): document.pingen_speed, document.pingen_color) except ConnectionError: - _logger.exception('Connection Error when asking for sending Pingen Document %s to %s.' % + _logger.exception('Connection Error when asking for sending ' + 'Pingen Document %s to %s.' % (document.id, pingen.url)) raise except APIError: - _logger.exception('API Error when asking for sending Pingen Document %s to %s.' % + _logger.exception('API Error when asking for sending ' + 'Pingen Document %s to %s.' % (document.id, pingen.url)) raise @@ -277,7 +289,8 @@ class pingen_document(orm.Model): 'state': 'sendcenter', 'post_id': post_id}, context=context) - _logger.info('Pingen Document %s: asked for sending to %s' % (document.id, pingen.url)) + _logger.info('Pingen Document %s: asked for sending to %s' % + (document.id, pingen.url)) return True @@ -291,7 +304,8 @@ class pingen_document(orm.Model): with self._get_pingen_session(cr, uid, context=context) as session: for document in self.browse(cr, uid, ids, context=context): try: - self._ask_pingen_send(cr, uid, document, pingen=session, context=context) + self._ask_pingen_send( + cr, uid, document, pingen=session, context=context) except ConnectionError as e: raise osv.except_osv( _('Pingen Connection Error'), @@ -306,11 +320,13 @@ class pingen_document(orm.Model): except: _logger.exception( - 'Unexcepted Error when updating the status of pingen.document %s: ' % + '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) + _('Unexcepted Error when updating the status ' + 'of Document %s') % document.name) return True def _update_post_infos(self, cr, uid, document, pingen, context=None): @@ -348,10 +364,11 @@ class pingen_document(orm.Model): 'currency_id': currency_ids[0] if currency_ids else False, 'parsed_address': post_infos['address'], 'country_id': country_ids[0] if country_ids else False, - 'send_date': send_date.strftime(tools.DEFAULT_SERVER_DATETIME_FORMAT), + 'send_date': send_date.strftime( + tools.DEFAULT_SERVER_DATETIME_FORMAT), 'pages': post_infos['pages'], 'last_error_message': False, - } + } if pingen.is_posted(post_infos): vals['state'] = 'sent' @@ -381,7 +398,8 @@ class pingen_document(orm.Model): loc_cr, uid, document, pingen=session, context=context) except (ConnectionError, APIError): # will be retried the next time - # In any case, the error has been logged by _update_post_infos + # In any case, the error has been logged by + # _update_post_infos loc_cr.rollback() except: _logger.error('Unexcepted error in pingen cron') @@ -406,20 +424,24 @@ class pingen_document(orm.Model): except ConnectionError as e: raise osv.except_osv( _('Pingen Connection Error'), - _('Connection Error when updating the status of Document %s' + _('Connection Error when updating the status of ' + 'Document %s' ' from Pingen') % document.name) except APIError as e: raise osv.except_osv( _('Pingen Error'), - _('Error when updating the status of Document %s from Pingen: ' + _('Error when updating the status of Document %s ' + 'from Pingen: ' '\n%s') % (document.name, e)) except: _logger.exception( - 'Unexcepted Error when updating the status of pingen.document %s: ' % + '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) + _('Unexcepted Error when updating the status of ' + 'Document %s') % document.name) return True From f5f2028d34d8f11552a42e596365add26633c02d Mon Sep 17 00:00:00 2001 From: Laetitia Gangloff Date: Mon, 28 Sep 2015 12:37:17 +0200 Subject: [PATCH 4/5] [PEP8] - printer_tray --- printer_tray/__openerp__.py | 2 +- printer_tray/ir_report.py | 8 +++++--- printer_tray/printer.py | 20 +++++++++++++------- printer_tray/printer_tray.py | 5 +++-- printer_tray/report_xml_action.py | 5 +++-- printer_tray/users.py | 2 +- 6 files changed, 26 insertions(+), 16 deletions(-) diff --git a/printer_tray/__openerp__.py b/printer_tray/__openerp__.py index da9e224..2e41571 100644 --- a/printer_tray/__openerp__.py +++ b/printer_tray/__openerp__.py @@ -47,7 +47,7 @@ Report to printer - Paper tray selection 'data': [ 'users_view.xml', 'ir_report_view.xml', - ], + ], 'test': [], 'installable': True, 'auto_install': False, diff --git a/printer_tray/ir_report.py b/printer_tray/ir_report.py index 6181053..f787536 100644 --- a/printer_tray/ir_report.py +++ b/printer_tray/ir_report.py @@ -29,14 +29,15 @@ class ReportXML(orm.Model): 'printer_tray_id': fields.many2one( 'printing.tray', 'Paper Source', domain="[('printer_id', '=', printing_printer_id)]"), - } + } def set_print_options(self, cr, uid, report_id, format, context=None): """ Hook to define Tray """ printing_act_obj = self.pool.get('printing.report.xml.action') - options = super(ReportXML, self).set_print_options(cr, uid, report_id, format, context=context) + options = super(ReportXML, self).set_print_options( + cr, uid, report_id, format, context=context) # Retrieve user default values user = self.pool.get('res.users').browse(cr, uid, context) @@ -54,7 +55,8 @@ class ReportXML(orm.Model): ('user_id', '=', uid), ('action', '!=', 'user_default')], context=context) if act_ids: - user_action = printing_act_obj.browse(cr, uid, act_ids[0], context=context) + user_action = printing_act_obj.browse( + cr, uid, act_ids[0], context=context) if user_action.tray_id: tray = user_action.tray_id diff --git a/printer_tray/printer.py b/printer_tray/printer.py index 9c18f64..0185b22 100644 --- a/printer_tray/printer.py +++ b/printer_tray/printer.py @@ -30,8 +30,9 @@ class Printer(orm.Model): _inherit = 'printing.printer' _columns = { - 'tray_ids': fields.one2many('printing.tray', 'printer_id', 'Paper Sources'), - } + 'tray_ids': fields.one2many('printing.tray', 'printer_id', + 'Paper Sources'), + } def _update_tray_option(self, db_name, uid, printer, context=None): """ @@ -54,12 +55,13 @@ class Printer(orm.Model): return try: for tray_opt in option.choices: - if tray_opt['choice'] not in [t.system_name for t in printer.tray_ids]: + if tray_opt['choice'] not in [ + t.system_name for t in printer.tray_ids]: tray_vals = { 'name': tray_opt['text'], 'system_name': tray_opt['choice'], 'printer_id': printer.id, - } + } tray_obj.create(cr, uid, tray_vals, context=context) cr.commit() @@ -76,7 +78,8 @@ class Printer(orm.Model): """ db, pool = pooler.get_db_and_pool(db_name) cr = db.cursor() - res = super(Printer, self).update_printers_status(db_name, uid, context=context) + res = super(Printer, self).update_printers_status(db_name, uid, + context=context) try: connection = cups.Connection() printers = connection.getPrinters() @@ -84,7 +87,9 @@ class Printer(orm.Model): except: server_error = True - printer_ids = self.search(cr, uid, [('system_name', 'in', printers.keys())], context=context) + printer_ids = self.search(cr, uid, + [('system_name', 'in', printers.keys())], + context=context) if server_error: vals = {'status': 'server_error'} self.write(cr, uid, printer_ids, vals, context=context) @@ -95,5 +100,6 @@ class Printer(orm.Model): for printer in printer_list: # XXX we consider config of printer won't change if not printer.tray_ids: - self._update_tray_option(db_name, uid, printer, context=context) + self._update_tray_option(db_name, uid, printer, + context=context) return res diff --git a/printer_tray/printer_tray.py b/printer_tray/printer_tray.py index 90a90ab..cb253b9 100644 --- a/printer_tray/printer_tray.py +++ b/printer_tray/printer_tray.py @@ -29,5 +29,6 @@ class PrinterTray(orm.Model): _columns = { 'name': fields.char('Name', size=64, required=True), 'system_name': fields.char('System Name', size=64, required=True), - 'printer_id': fields.many2one('printing.printer', 'Printer', required=True), - } + 'printer_id': fields.many2one('printing.printer', 'Printer', + required=True), + } diff --git a/printer_tray/report_xml_action.py b/printer_tray/report_xml_action.py index 603e21b..f687a56 100644 --- a/printer_tray/report_xml_action.py +++ b/printer_tray/report_xml_action.py @@ -29,10 +29,11 @@ class ReportXMLAction(orm.Model): 'printer_tray_id': fields.many2one( 'printing.tray', 'Paper Source', domain="[('printer_id', '=', printer_id)]"), - } + } def behaviour(self, cr, uid, act_id, context=None): - res = super(ReportXMLAction, self).behaviour(cr, uid, act_id, context=context) + res = super(ReportXMLAction, self).behaviour(cr, uid, act_id, + context=context) action = self.browse(cr, uid, act_id, context=context) res['tray'] = action.printer_tray_id.system_name return res diff --git a/printer_tray/users.py b/printer_tray/users.py index 7f46f76..bd30f0e 100644 --- a/printer_tray/users.py +++ b/printer_tray/users.py @@ -29,4 +29,4 @@ class ResUsers(orm.Model): 'printer_tray_id': fields.many2one( 'printing.tray', 'Default Printer Paper Source', domain="[('printer_id', '=', printing_printer_id)]"), - } + } From 4a621964b53c88ddf310f5a84589bd69b83116d1 Mon Sep 17 00:00:00 2001 From: Laetitia Gangloff Date: Mon, 28 Sep 2015 12:57:54 +0200 Subject: [PATCH 5/5] [PEP8] --- base_report_to_printer/report_xml_action.py | 3 ++- base_report_to_printer/users.py | 3 ++- pingen/__init__.py | 8 ++++---- 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/base_report_to_printer/report_xml_action.py b/base_report_to_printer/report_xml_action.py index 679a8b6..4734c78 100644 --- a/base_report_to_printer/report_xml_action.py +++ b/base_report_to_printer/report_xml_action.py @@ -24,7 +24,8 @@ ############################################################################## from openerp.osv import orm, fields -from printing import _available_action_types +from openerp.addons.base_report_to_printer.printing import \ + _available_action_types class report_xml_action(orm.Model): diff --git a/base_report_to_printer/users.py b/base_report_to_printer/users.py index 29af48c..118a1f2 100644 --- a/base_report_to_printer/users.py +++ b/base_report_to_printer/users.py @@ -24,7 +24,8 @@ ############################################################################## from openerp.osv import orm, fields -from printing import _available_action_types +from openerp.addons.base_report_to_printer.printing import \ + _available_action_types class res_users(orm.Model): diff --git a/pingen/__init__.py b/pingen/__init__.py index 4ff2fea..73a128d 100644 --- a/pingen/__init__.py +++ b/pingen/__init__.py @@ -19,7 +19,7 @@ # ############################################################################## -import ir_attachment -import pingen -import pingen_document -import res_company +from . import ir_attachment +from . import pingen +from . import pingen_document +from . import res_company