Merge pull request #33 from acsone/7.0-base_report_to_printer_pep8-lga

[PEP8] + latest MQT template
This commit is contained in:
Pedro M. Baeza
2015-09-28 13:09:57 +02:00
20 changed files with 219 additions and 132 deletions

View File

@@ -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
- 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
- git clone https://github.com/OCA/reporting-engine -b ${VERSION} ${HOME}/reporting-engine
script:
- travis_run_tests
after_success:
coveralls
- travis_after_tests_success

View File

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

View File

@@ -78,7 +78,8 @@ Contributors
* Lionel Sausin <ls@numerigraphe.com>
""",
'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'],

View File

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

View File

@@ -34,6 +34,7 @@ from openerp.tools.translate import _
class printing_printer(orm.Model):
"""
Printers
"""
@@ -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)
@@ -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),
}

View File

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

View File

@@ -24,21 +24,24 @@
##############################################################################
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):
_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)
@@ -46,5 +49,3 @@ class report_xml_action(orm.Model):
'action': action.action,
'printer': action.printer_id,
}
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:

View File

@@ -24,10 +24,12 @@
##############################################################################
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):
"""
Users
"""
@@ -41,8 +43,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'),
'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:

View File

@@ -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 {}
@@ -67,6 +64,3 @@ class printing_printer_update_wizard(orm.TransientModel):
'type': 'ir.actions.act_window',
'target': 'current',
}
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:

View File

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

View File

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

View File

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

View File

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

View File

@@ -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,7 +364,8 @@ 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,
}
@@ -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

View File

@@ -36,7 +36,8 @@ class ReportXML(orm.Model):
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

View File

@@ -30,7 +30,8 @@ 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,7 +55,8 @@ 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'],
@@ -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

View File

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

View File

@@ -32,7 +32,8 @@ class ReportXMLAction(orm.Model):
}
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