diff --git a/base_report_to_printer/__openerp__.py b/base_report_to_printer/__openerp__.py index 3732e1d7043..b7b5eb48992 100644 --- a/base_report_to_printer/__openerp__.py +++ b/base_report_to_printer/__openerp__.py @@ -81,7 +81,7 @@ 'author': 'Agile Business Group & Domsense, Pegueroles SCP, NaN', 'website': 'http://www.agilebg.com', 'license': 'AGPL-3', - "depends" : ['base', 'base_calendar'], + "depends": ['base', 'base_calendar'], 'data': [ 'security/security.xml', 'printing_data.xml', diff --git a/base_report_to_printer/ir_report.py b/base_report_to_printer/ir_report.py index a6364637d41..96cd1c17766 100644 --- a/base_report_to_printer/ir_report.py +++ b/base_report_to_printer/ir_report.py @@ -30,12 +30,11 @@ from openerp.osv import orm, fields -# -# Reports -# class report_xml(orm.Model): - + """ + Reports + """ def set_print_options(self, cr, uid, report_id, format, context=None): """ @@ -79,7 +78,10 @@ def print_direct(self, cr, uid, report_id, result, format, printer, context=None 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'), + '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): @@ -105,16 +107,18 @@ def behaviour(self, cr, uid, ids, context=None): 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 # Retrieve report-user specific values - act_ids = printing_act_obj.search(cr, uid, - [('report_id', '=', report.id), - ('user_id', '=', uid), - ('action', '!=', 'user_default')], context=context) + act_ids = printing_act_obj.search( + cr, uid, + [('report_id', '=', report.id), + ('user_id', '=', uid), + ('action', '!=', 'user_default')], context=context) if act_ids: user_action = printing_act_obj.behaviour(cr, uid, act_ids[0], context) action = user_action['action'] diff --git a/base_report_to_printer/printing.py b/base_report_to_printer/printing.py index 61257b9b4e7..c9e9694bf8a 100644 --- a/base_report_to_printer/printing.py +++ b/base_report_to_printer/printing.py @@ -23,7 +23,6 @@ # ############################################################################## import time -import base64 import cups from threading import Thread @@ -32,25 +31,53 @@ from openerp import pooler from openerp.osv import orm, fields from openerp.tools.translate import _ -from openerp.addons.base_calendar import base_calendar -# -# Printers -# class printing_printer(orm.Model): + """ + Printers + """ _name = "printing.printer" _description = "Printer" _columns = { - 'name' : fields.char('Name',size=64,required=True,select="1"), - 'system_name': fields.char('System Name',size=64,required=True,select="1"), - 'default':fields.boolean('Default Printer', readonly=True), - 'status': fields.selection([('unavailable','Unavailable'),('printing','Printing'),('unknown','Unknown'),('available','Available'),('error','Error'),('server-error','Server Error')], 'Status', required=True, readonly=True), - 'status_message': fields.char('Status Message', size=500, readonly=True), - 'model': fields.char('Model', size=500, readonly=True), - 'location': fields.char('Location', size=500, readonly=True), - 'uri': fields.char('URI', size=500, readonly=True), + 'name': fields.char( + 'Name', + size=64, + required=True, + select="1"), + 'system_name': fields.char( + 'System Name', + size=64, + required=True, + select="1"), + 'default': fields.boolean( + 'Default Printer', + readonly=True), + 'status': fields.selection( + [('unavailable', 'Unavailable'), + ('printing', 'Printing'), + ('unknown', 'Unknown'), + ('available', 'Available'), + ('error', 'Error'), + ('server-error', 'Server Error')], + 'Status', required=True, readonly=True), + 'status_message': fields.char( + 'Status Message', + size=500, + readonly=True), + 'model': fields.char( + 'Model', + size=500, + readonly=True), + 'location': fields.char( + 'Location', + size=500, + readonly=True), + 'uri': fields.char( + 'URI', + size=500, + readonly=True), } _order = "name" @@ -78,9 +105,9 @@ def update_printers_status(self, db_name, uid, context=None): server_error = True mapping = { - 3 : 'available', - 4 : 'printing', - 5 : 'error' + 3: 'available', + 4: 'printing', + 5: 'error' } if context is None: @@ -96,7 +123,7 @@ def update_printers_status(self, db_name, uid, context=None): status = 'server-error' elif printer.system_name in printers: info = printers[printer.system_name] - status = mapping.get( info['printer-state'], 'unknown' ) + status = mapping.get(info['printer-state'], 'unknown') vals = { 'model': info.get('printer-make-and-model', False), 'location': info.get('printer-location', False), @@ -117,7 +144,6 @@ def update_printers_status(self, db_name, uid, context=None): self.updating = False self.last_update = time.time() - def start_printer_update(self, cr, uid, context): self.lock.acquire() if self.updating: @@ -140,7 +166,7 @@ def update(self, cr, uid, context=None): 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 - for x in range(0,5): + for x in range(0, 5): time.sleep(1) self.lock.acquire() updating = self.updating @@ -149,28 +175,32 @@ def update(self, cr, uid, context=None): break return True - def search(self, cr, uid, args, offset=0, limit=None, order=None, context=None, count=False): + def search(self, cr, uid, args, offset=0, limit=None, order=None, + context=None, count=False): self.update(cr, uid, context) - return super(printing_printer,self).search(cr, uid, args, offset, limit, order, context, count) + return super(printing_printer, self + ).search(cr, uid, args, offset, + limit, order, context, count) 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) + return super(printing_printer, self + ).read(cr, uid, ids, fields, context, load) def browse(self, cr, uid, ids, context=None): self.update(cr, uid, context) - return super(printing_printer,self).browse(cr, uid, ids, context) + return super(printing_printer, self).browse(cr, uid, ids, context) def set_default(self, cr, uid, ids, context): if not ids: return - default_ids= self.search(cr, uid,[('default','=',True)]) - self.write(cr, uid, default_ids, {'default':False}, context) - self.write(cr, uid, ids[0], {'default':True}, context) + default_ids = self.search(cr, uid, [('default', '=', True)]) + self.write(cr, uid, default_ids, {'default': False}, context) + self.write(cr, uid, ids[0], {'default': True}, context) return True - def get_default(self,cr,uid,context): - printer_ids = self.search(cr, uid,[('default','=',True)]) + def get_default(self, cr, uid, context): + printer_ids = self.search(cr, uid, [('default', '=', True)]) if printer_ids: return printer_ids[0] return False @@ -182,11 +212,12 @@ def get_default(self,cr,uid,context): def _available_action_types(self, cr, uid, context=None): return [ - ('server',_('Send to Printer')), - ('client',_('Send to Client')), - ('user_default',_("Use user's defaults")), + ('server', _('Send to Printer')), + ('client', _('Send to Client')), + ('user_default', _("Use user's defaults")), ] + class printing_action(orm.Model): _name = 'printing.action' _description = 'Print Job Action' @@ -195,5 +226,3 @@ class printing_action(orm.Model): 'name': fields.char('Name', size=256, required=True), 'type': fields.selection(_available_action_types, 'Type', required=True), } - -# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: diff --git a/base_report_to_printer/report_service.py b/base_report_to_printer/report_service.py index 6dfa956d481..a736a1004b3 100644 --- a/base_report_to_printer/report_service.py +++ b/base_report_to_printer/report_service.py @@ -27,6 +27,7 @@ from openerp import pooler 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): @@ -41,22 +42,26 @@ def exp_report_get(self, db, uid, report_id): pool = pooler.get_pool(cr.dbname) # 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'])]) + report = report_obj.search( + cr, uid, [('report_name', '=', self._reports[report_id]['report_name'])]) if report: - report = report_obj.browse(cr,uid,report[0]) - name = report.name + 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)): - report_obj.print_direct(cr, uid, report.id, base64.encodestring(self._reports[report_id]['result']), + 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']), self._reports[report_id]['format'], printer) # XXX "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 - #raise osv.except_osv(_('Printing...'), _('Document sent to printer %s') % (printer,)) + # raise osv.except_osv( + # _('Printing...'), + # _('Document sent to printer %s') % (printer,)) except: cr.rollback() diff --git a/base_report_to_printer/users.py b/base_report_to_printer/users.py index f27790486e9..1aa546e172d 100644 --- a/base_report_to_printer/users.py +++ b/base_report_to_printer/users.py @@ -26,17 +26,19 @@ from printing import _available_action_types -# -# Users -# + class res_users(orm.Model): + """ + Users + """ _name = "res.users" _inherit = "res.users" def _user_available_action_types(self, cr, uid, context=None): if context is None: - context={} - return [x for x in _available_action_types(self, cr, uid, context) if x[0] != 'user_default'] + context = {} + return [x for x in _available_action_types(self, cr, uid, context) + if x[0] != 'user_default'] _columns = { 'printing_action': fields.selection(_user_available_action_types, 'Printing Action'), diff --git a/base_report_to_printer/wizard/__init__.py b/base_report_to_printer/wizard/__init__.py index 926dc4399ca..05d46853dba 100644 --- a/base_report_to_printer/wizard/__init__.py +++ b/base_report_to_printer/wizard/__init__.py @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- ############################################################################## -# +# # Copyright (c) 2009 Albert Cervera i Areny # Copyright (C) 2011 Agile Business Group sagl () # Copyright (C) 2011 Domsense srl () diff --git a/base_report_to_printer/wizard/update_printers.py b/base_report_to_printer/wizard/update_printers.py index 43ccbd9d2d6..d599a0317f0 100644 --- a/base_report_to_printer/wizard/update_printers.py +++ b/base_report_to_printer/wizard/update_printers.py @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- ############################################################################## -# +# # Copyright (c) 2009 Albert Cervera i Areny # Copyright (C) 2011 Agile Business Group sagl () # Copyright (C) 2011 Domsense srl () @@ -37,14 +37,16 @@ def action_cancel(self, cr, uid, ids, context=None): def action_ok(self, cr, uid, ids, context=None): # Update Printers + printer_obj = self.pool['printing.printer'] try: connection = cups.Connection() printers = connection.getPrinters() except: return {} - ids = self.pool.get('printing.printer').search(cr, uid, [('system_name','in',printers.keys())], context=context) - for printer in self.pool.get('printing.printer').browse(cr, uid, ids, context=context): + ids = printer_obj.search( + cr, uid, [('system_name', 'in', printers.keys())], context=context) + for printer in printer_obj.browse(cr, uid, ids, context=context): del printers[printer.system_name] for name in printers: diff --git a/pingen/__init__.py b/pingen/__init__.py index a00e542ea74..4ff2feaecd5 100644 --- a/pingen/__init__.py +++ b/pingen/__init__.py @@ -23,4 +23,3 @@ import pingen import pingen_document import res_company - diff --git a/pingen/pingen.py b/pingen/pingen.py index ecb8c2e0a66..475407b39ee 100644 --- a/pingen/pingen.py +++ b/pingen/pingen.py @@ -132,7 +132,7 @@ def _send(self, method, endpoint, **kwargs): 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 @@ def push_document(self, filename, filestream, send=None, speed=None, color=None) 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 @@ def send_document(self, document_id, speed=None, color=None): '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 @@ def post_infos(self, post_id): :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 @@ def is_posted(post_infos): :param dict post_infos: post infos returned by `post_infos` """ return post_infos['status'] == 200 - diff --git a/pingen/pingen_document.py b/pingen/pingen_document.py index b613327f724..ac59a028f67 100644 --- a/pingen/pingen_document.py +++ b/pingen/pingen_document.py @@ -28,7 +28,7 @@ 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 @@ def _push_to_pingen(self, cr, uid, document, pingen=None, context=None): 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 @@ def _push_to_pingen(self, cr, uid, document, pingen=None, context=None): 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 @@ def push_to_pingen(self, cr, uid, ids, context=None): 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 @@ def _ask_pingen_send(self, cr, uid, document, pingen, context=None): 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 @@ def ask_pingen_send(self, cr, uid, ids, context=None): 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,24 +323,24 @@ def _update_post_infos(self, cr, uid, document, pingen, context=None): 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']) + send_date = pingen_datetime_to_utc(post_infos['date']) vals = { 'post_status': POST_SENDING_STATUS[post_infos['status']], @@ -369,9 +369,9 @@ def _update_post_infos_cron(self, cr, uid, ids, context=None): """ 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 @@ def update_post_infos(self, cr, uid, ids, context=None): 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 - diff --git a/pingen/res_company.py b/pingen/res_company.py index c8e2260a14a..ad0c2c88771 100644 --- a/pingen/res_company.py +++ b/pingen/res_company.py @@ -23,6 +23,7 @@ from openerp.osv.orm import browse_record from .pingen import Pingen + class res_company(orm.Model): _inherit = 'res.company' @@ -39,4 +40,3 @@ def _pingen(self, cr, uid, company, context=None): if not isinstance(company, browse_record): company = self.browse(cr, uid, company, context=context) return Pingen(company.pingen_token, staging=company.pingen_staging) - diff --git a/pingen_document/__init__.py b/pingen_document/__init__.py index b35b46c1133..414def05cda 100644 --- a/pingen_document/__init__.py +++ b/pingen_document/__init__.py @@ -18,4 +18,3 @@ # along with this program. If not, see . # ############################################################################## - diff --git a/pingen_document/__openerp__.py b/pingen_document/__openerp__.py index ff4d1dfa5f8..fb113c3592c 100644 --- a/pingen_document/__openerp__.py +++ b/pingen_document/__openerp__.py @@ -20,14 +20,14 @@ ############################################################################## { - 'name' : 'pingen.com integration (document)', - 'version' : '1.0', - 'author' : 'Camptocamp', + 'name': 'pingen.com integration (document)', + 'version': '1.0', + 'author': 'Camptocamp', 'maintainer': 'Camptocamp', 'license': 'AGPL-3', 'category': 'Reporting', 'complexity': 'easy', - 'depends' : ['document', 'pingen'], + 'depends': ['document', 'pingen'], 'description': """ Glue module between the `pingen` and the `document` modules. """, diff --git a/printer_tray/ir_report.py b/printer_tray/ir_report.py index 4230d575e16..6181053cc59 100644 --- a/printer_tray/ir_report.py +++ b/printer_tray/ir_report.py @@ -49,10 +49,10 @@ def set_print_options(self, cr, uid, report_id, format, context=None): # Retrieve report-user specific values act_ids = printing_act_obj.search( - cr, uid, - [('report_id', '=', report.id), - ('user_id', '=', uid), - ('action', '!=', 'user_default')], context=context) + cr, uid, + [('report_id', '=', report.id), + ('user_id', '=', uid), + ('action', '!=', 'user_default')], context=context) if act_ids: user_action = printing_act_obj.browse(cr, uid, act_ids[0], context=context) if user_action.tray_id: