From ab7ccba26a4e4c471244050447d8f641e05408f8 Mon Sep 17 00:00:00 2001 From: Guewen Baconnier Date: Mon, 17 Nov 2014 13:40:21 +0100 Subject: [PATCH 01/21] Moved printer_tray from __unported__ to root folder --- {__unported__/printer_tray => printer_tray}/__init__.py | 0 {__unported__/printer_tray => printer_tray}/__openerp__.py | 0 {__unported__/printer_tray => printer_tray}/i18n/fr.po | 0 {__unported__/printer_tray => printer_tray}/i18n/printer_tray.po | 0 {__unported__/printer_tray => printer_tray}/ir_report.py | 0 {__unported__/printer_tray => printer_tray}/ir_report_view.xml | 0 {__unported__/printer_tray => printer_tray}/printer.py | 0 {__unported__/printer_tray => printer_tray}/printer_tray.py | 0 {__unported__/printer_tray => printer_tray}/report_xml_action.py | 0 .../printer_tray => printer_tray}/security/ir.model.access.csv | 0 {__unported__/printer_tray => printer_tray}/users.py | 0 {__unported__/printer_tray => printer_tray}/users_view.xml | 0 12 files changed, 0 insertions(+), 0 deletions(-) rename {__unported__/printer_tray => printer_tray}/__init__.py (100%) rename {__unported__/printer_tray => printer_tray}/__openerp__.py (100%) rename {__unported__/printer_tray => printer_tray}/i18n/fr.po (100%) rename {__unported__/printer_tray => printer_tray}/i18n/printer_tray.po (100%) rename {__unported__/printer_tray => printer_tray}/ir_report.py (100%) rename {__unported__/printer_tray => printer_tray}/ir_report_view.xml (100%) rename {__unported__/printer_tray => printer_tray}/printer.py (100%) rename {__unported__/printer_tray => printer_tray}/printer_tray.py (100%) rename {__unported__/printer_tray => printer_tray}/report_xml_action.py (100%) rename {__unported__/printer_tray => printer_tray}/security/ir.model.access.csv (100%) rename {__unported__/printer_tray => printer_tray}/users.py (100%) rename {__unported__/printer_tray => printer_tray}/users_view.xml (100%) diff --git a/__unported__/printer_tray/__init__.py b/printer_tray/__init__.py similarity index 100% rename from __unported__/printer_tray/__init__.py rename to printer_tray/__init__.py diff --git a/__unported__/printer_tray/__openerp__.py b/printer_tray/__openerp__.py similarity index 100% rename from __unported__/printer_tray/__openerp__.py rename to printer_tray/__openerp__.py diff --git a/__unported__/printer_tray/i18n/fr.po b/printer_tray/i18n/fr.po similarity index 100% rename from __unported__/printer_tray/i18n/fr.po rename to printer_tray/i18n/fr.po diff --git a/__unported__/printer_tray/i18n/printer_tray.po b/printer_tray/i18n/printer_tray.po similarity index 100% rename from __unported__/printer_tray/i18n/printer_tray.po rename to printer_tray/i18n/printer_tray.po diff --git a/__unported__/printer_tray/ir_report.py b/printer_tray/ir_report.py similarity index 100% rename from __unported__/printer_tray/ir_report.py rename to printer_tray/ir_report.py diff --git a/__unported__/printer_tray/ir_report_view.xml b/printer_tray/ir_report_view.xml similarity index 100% rename from __unported__/printer_tray/ir_report_view.xml rename to printer_tray/ir_report_view.xml diff --git a/__unported__/printer_tray/printer.py b/printer_tray/printer.py similarity index 100% rename from __unported__/printer_tray/printer.py rename to printer_tray/printer.py diff --git a/__unported__/printer_tray/printer_tray.py b/printer_tray/printer_tray.py similarity index 100% rename from __unported__/printer_tray/printer_tray.py rename to printer_tray/printer_tray.py diff --git a/__unported__/printer_tray/report_xml_action.py b/printer_tray/report_xml_action.py similarity index 100% rename from __unported__/printer_tray/report_xml_action.py rename to printer_tray/report_xml_action.py diff --git a/__unported__/printer_tray/security/ir.model.access.csv b/printer_tray/security/ir.model.access.csv similarity index 100% rename from __unported__/printer_tray/security/ir.model.access.csv rename to printer_tray/security/ir.model.access.csv diff --git a/__unported__/printer_tray/users.py b/printer_tray/users.py similarity index 100% rename from __unported__/printer_tray/users.py rename to printer_tray/users.py diff --git a/__unported__/printer_tray/users_view.xml b/printer_tray/users_view.xml similarity index 100% rename from __unported__/printer_tray/users_view.xml rename to printer_tray/users_view.xml From fc884fef23db94db4a6e73e9aa106e46a0428e92 Mon Sep 17 00:00:00 2001 From: Guewen Baconnier Date: Mon, 17 Nov 2014 13:40:55 +0100 Subject: [PATCH 02/21] Set printer_tray to installable --- printer_tray/__openerp__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/printer_tray/__openerp__.py b/printer_tray/__openerp__.py index 0544c8c..e193ea2 100644 --- a/printer_tray/__openerp__.py +++ b/printer_tray/__openerp__.py @@ -49,7 +49,7 @@ Report to printer - Paper tray selection 'ir_report_view.xml', ], 'test': [], - 'installable': False, + 'installable': True, 'auto_install': False, 'application': True, } From b6fea158c3abd0a2cc6625b49aecc0cbb82240ce Mon Sep 17 00:00:00 2001 From: Guewen Baconnier Date: Mon, 17 Nov 2014 13:42:10 +0100 Subject: [PATCH 03/21] Extract the module's description in a REAME.rst file --- printer_tray/README.rst | 15 +++++++++++++++ printer_tray/__openerp__.py | 17 ----------------- 2 files changed, 15 insertions(+), 17 deletions(-) create mode 100644 printer_tray/README.rst diff --git a/printer_tray/README.rst b/printer_tray/README.rst new file mode 100644 index 0000000..3e7ce79 --- /dev/null +++ b/printer_tray/README.rst @@ -0,0 +1,15 @@ +Report to printer - Paper tray selection +======================================== + +**Author:** Camptocamp SA + +*This module extends `Report to printer` module.* + +It detects trays on printer installation plus permits to select the +paper source on which you want to print directly. + +You will find this option on default user config, on default report +config and on specific config per user per report. + +This allows you to dedicate a specific paper source for exemple for +preprinted paper such as payment slip. diff --git a/printer_tray/__openerp__.py b/printer_tray/__openerp__.py index e193ea2..1a44c38 100644 --- a/printer_tray/__openerp__.py +++ b/printer_tray/__openerp__.py @@ -21,23 +21,6 @@ {'name': 'Report to printer - Paper tray selection', 'version': '1.0', 'category': 'Printer', - 'description': """ -Report to printer - Paper tray selection -======================================== - - **Author:** Camptocamp SA - - *This module extends `Report to printer` module.* - - It detects trays on printer installation plus permits to select - the paper source on which you want to print directly. - - You will find this option on default user config, on default report config - and on specific config per user per report. - - This allows you to dedicate a specific paper source for exemple for prepinted - paper such as payment slip. - """, 'author': 'Camptocamp', 'maintainer': 'Camptocamp', 'website': 'http://www.camptocamp.com/', From e9adf1b8678d4c3787ec086b86afc1297a3e4fcf Mon Sep 17 00:00:00 2001 From: Guewen Baconnier Date: Mon, 17 Nov 2014 14:06:52 +0100 Subject: [PATCH 04/21] base_report_assembler seems not to be a dependency for printer_tray --- printer_tray/__openerp__.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/printer_tray/__openerp__.py b/printer_tray/__openerp__.py index 1a44c38..a00ddd5 100644 --- a/printer_tray/__openerp__.py +++ b/printer_tray/__openerp__.py @@ -24,8 +24,7 @@ 'author': 'Camptocamp', 'maintainer': 'Camptocamp', 'website': 'http://www.camptocamp.com/', - 'depends': ['base_report_assembler', - 'base_report_to_printer', + 'depends': ['base_report_to_printer', ], 'data': [ 'users_view.xml', From 49a7599aed96806306a7b198cece1663e7cdbd63 Mon Sep 17 00:00:00 2001 From: Guewen Baconnier Date: Mon, 17 Nov 2014 14:11:08 +0100 Subject: [PATCH 05/21] print_options is now in printing, new api for ir.actions.report.xml --- printer_tray/ir_report.py | 45 ++++++--------------------------------- printer_tray/printer.py | 31 +++++++++++++++++++++++++++ 2 files changed, 38 insertions(+), 38 deletions(-) diff --git a/printer_tray/ir_report.py b/printer_tray/ir_report.py index 6181053..9b36724 100644 --- a/printer_tray/ir_report.py +++ b/printer_tray/ir_report.py @@ -18,46 +18,15 @@ # along with this program. If not, see . # ############################################################################## -from openerp.osv import orm, fields +from openerp import models, fields -class ReportXML(orm.Model): +class IrActionsReportXml(models.Model): _inherit = 'ir.actions.report.xml' - _columns = { - '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) - - # Retrieve user default values - user = self.pool.get('res.users').browse(cr, uid, context) - tray = user.printer_tray_id - report = self.browse(cr, uid, report_id, context=context) - - # Retrieve report default values - if report.printer_tray_id: - tray = report.printer_tray_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) - if act_ids: - user_action = printing_act_obj.browse(cr, uid, act_ids[0], context=context) - if user_action.tray_id: - tray = user_action.tray_id - - if tray: - options['InputSlot'] = str(tray.system_name) - return options + printer_tray_id = fields.Many2one( + comodel_name='printing.tray', + string='Paper Source', + domain="[('printer_id', '=', printing_printer_id)]", + ) diff --git a/printer_tray/printer.py b/printer_tray/printer.py index 9c18f64..283554f 100644 --- a/printer_tray/printer.py +++ b/printer_tray/printer.py @@ -97,3 +97,34 @@ class Printer(orm.Model): if not printer.tray_ids: self._update_tray_option(db_name, uid, printer, context=context) return res + + def 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) + + # Retrieve user default values + user = self.pool.get('res.users').browse(cr, uid, context) + tray = user.printer_tray_id + report = self.browse(cr, uid, report_id, context=context) + + # Retrieve report default values + if report.printer_tray_id: + tray = report.printer_tray_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) + if act_ids: + user_action = printing_act_obj.browse(cr, uid, act_ids[0], context=context) + if user_action.tray_id: + tray = user_action.tray_id + + if tray: + options['InputSlot'] = str(tray.system_name) + return options From 0a5971eab76152b750ba8da80833ca3cfdfff6b0 Mon Sep 17 00:00:00 2001 From: Guewen Baconnier Date: Mon, 17 Nov 2014 14:15:15 +0100 Subject: [PATCH 06/21] new api for res.users --- printer_tray/users.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/printer_tray/users.py b/printer_tray/users.py index 7f46f76..57d1276 100644 --- a/printer_tray/users.py +++ b/printer_tray/users.py @@ -18,15 +18,15 @@ # along with this program. If not, see . # ############################################################################## -from openerp.osv import orm, fields +from openerp import models, fields -class ResUsers(orm.Model): +class ResUsers(models.Model): _inherit = "res.users" - _columns = { - 'printer_tray_id': fields.many2one( - 'printing.tray', 'Default Printer Paper Source', - domain="[('printer_id', '=', printing_printer_id)]"), - } + printer_tray_id = fields.Many2one( + comodel_name='printing.tray', + string='Default Printer Paper Source', + domain="[('printer_id', '=', printing_printer_id)]", + ) From 6d3c5c84aa26db184bb093a45020313361575b7e Mon Sep 17 00:00:00 2001 From: Guewen Baconnier Date: Mon, 17 Nov 2014 14:16:31 +0100 Subject: [PATCH 07/21] new api for printing.tray --- printer_tray/printer_tray.py | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/printer_tray/printer_tray.py b/printer_tray/printer_tray.py index 90a90ab..186f2a1 100644 --- a/printer_tray/printer_tray.py +++ b/printer_tray/printer_tray.py @@ -18,16 +18,19 @@ # along with this program. If not, see . # ############################################################################## -from openerp.osv import orm, fields +from openerp import models, fields -class PrinterTray(orm.Model): +class PrinterTray(models.Model): _name = 'printing.tray' _description = 'Printer Tray' - _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), - } + name = fields.Char(required=True) + system_name = fields.Char(required=True) + printer_id = fields.Many2one( + comodel_name='printing.printer', + string='Printer', + required=True, + ondelete='cascade', + ) From 3ef44329da12371a614eeb42a7f5fcafc916b173 Mon Sep 17 00:00:00 2001 From: Guewen Baconnier Date: Mon, 17 Nov 2014 14:18:29 +0100 Subject: [PATCH 08/21] new api for 'printing.report.xml.action' --- printer_tray/report_xml_action.py | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/printer_tray/report_xml_action.py b/printer_tray/report_xml_action.py index 603e21b..0e29524 100644 --- a/printer_tray/report_xml_action.py +++ b/printer_tray/report_xml_action.py @@ -19,20 +19,21 @@ # ############################################################################## -from openerp.osv import orm, fields +from openerp import models, fields, api -class ReportXMLAction(orm.Model): +class ReportXMLAction(models.Model): _inherit = 'printing.report.xml.action' - _columns = { - 'printer_tray_id': fields.many2one( - 'printing.tray', 'Paper Source', - domain="[('printer_id', '=', printer_id)]"), - } + printer_tray_id = fields.Many2one( + comodel_name='printing.tray', + string='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) - action = self.browse(cr, uid, act_id, context=context) - res['tray'] = action.printer_tray_id.system_name + @api.multi + def behaviour(self): + self.ensure_one() + res = super(ReportXMLAction, self).behaviour() + res['tray'] = self.printer_tray_id.system_name return res From aef795d29501875c05615cb7cc227ea9f5262984 Mon Sep 17 00:00:00 2001 From: Guewen Baconnier Date: Mon, 17 Nov 2014 14:37:44 +0100 Subject: [PATCH 09/21] Started to migrate printing.printer to the new API --- printer_tray/printer.py | 40 +++++++++++++++++----------------------- 1 file changed, 17 insertions(+), 23 deletions(-) diff --git a/printer_tray/printer.py b/printer_tray/printer.py index 283554f..15b7845 100644 --- a/printer_tray/printer.py +++ b/printer_tray/printer.py @@ -22,16 +22,15 @@ import cups from cups import PPD from openerp import pooler -from openerp.osv import orm, fields +from openerp import models, fields, api -class Printer(orm.Model): - +class Printer(models.Model): _inherit = 'printing.printer' - _columns = { - 'tray_ids': fields.one2many('printing.tray', 'printer_id', 'Paper Sources'), - } + tray_ids = fields.One2many(comodel_name='printing.tray', + inverse_name='printer_id', + string='Paper Sources') def _update_tray_option(self, db_name, uid, printer, context=None): """ @@ -98,32 +97,27 @@ class Printer(orm.Model): self._update_tray_option(db_name, uid, printer, context=context) return res - def 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) + @api.multi + def print_options(self, report, format): + """ Hook to define Tray """ + printing_act_obj = self.env['printing.report.xml.action'] + options = super(Printer, self).print_options(report, format) # Retrieve user default values - user = self.pool.get('res.users').browse(cr, uid, context) + user = self.env.user tray = user.printer_tray_id - report = self.browse(cr, uid, report_id, context=context) # Retrieve report default values if report.printer_tray_id: tray = report.printer_tray_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) - if act_ids: - user_action = printing_act_obj.browse(cr, uid, act_ids[0], context=context) - if user_action.tray_id: - tray = user_action.tray_id + action = printing_act_obj.search([('report_id', '=', report.id), + ('user_id', '=', self.env.uid), + ('action', '!=', 'user_default')], + limit=1) + if action and action.tray_id: + tray = action.tray_id if tray: options['InputSlot'] = str(tray.system_name) From 57b91300a2f8d718337e455ce0ab6c684ac3607f Mon Sep 17 00:00:00 2001 From: Guewen Baconnier Date: Mon, 17 Nov 2014 17:11:50 +0100 Subject: [PATCH 10/21] Update the trays from cups, use the new extracted methods in base_report_to_printer --- printer_tray/printer.py | 84 +++++++++++++---------------------------- 1 file changed, 26 insertions(+), 58 deletions(-) diff --git a/printer_tray/printer.py b/printer_tray/printer.py index 15b7845..8653b5f 100644 --- a/printer_tray/printer.py +++ b/printer_tray/printer.py @@ -19,7 +19,6 @@ # ############################################################################## import cups -from cups import PPD from openerp import pooler from openerp import models, fields, api @@ -32,70 +31,39 @@ class Printer(models.Model): inverse_name='printer_id', string='Paper Sources') - def _update_tray_option(self, db_name, uid, printer, context=None): - """ - Create missing tray for a printer - """ - db, pool = pooler.get_db_and_pool(db_name) - cr = db.cursor() - tray_obj = pool.get('printing.tray') - # get printers options from a PPD file - try: - connection = cups.Connection() - ppd_file_path = connection.getPPD3(printer.system_name) - except: - return + @api.multi + def _prepare_update_from_cups(self, cups_connection, cups_printer): + vals = super(Printer, self)._prepare_update_from_cups(cups_connection, + cups_printer) + + ppd_file_path = cups_connection.getPPD3(self.system_name) if not ppd_file_path[2]: - return - ppd = PPD(ppd_file_path[2]) + return vals + + ppd = cups.PPD(ppd_file_path[2]) option = ppd.findOption('InputSlot') if not option: - return - try: - for tray_opt in option.choices: - 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, - } + return vals - tray_obj.create(cr, uid, tray_vals, context=context) - cr.commit() - except: - cr.rollback() - raise - finally: - cr.close() - return True + vals_trays = [] - def update_printers_status(self, db_name, uid, context=None): - """ - Add creation of tray if no tray are defined - """ - db, pool = pooler.get_db_and_pool(db_name) - cr = db.cursor() - res = super(Printer, self).update_printers_status(db_name, uid, context=context) - try: - connection = cups.Connection() - printers = connection.getPrinters() - server_error = False - except: - server_error = True + tray_names = set(tray.system_name for tray in self.tray_ids) + for tray_option in option.choices: + if tray_option['choice'] not in tray_names: + tray_vals = { + 'name': tray_option['text'], + 'system_name': tray_option['choice'], + } + vals_trays.append((0, 0, tray_vals)) - 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) - return res + cups_trays = set(tray_option['choice'] for tray_option + in option.choices) + for tray in self.tray_ids: + if tray.system_name not in cups_trays: + vals_trays.append((2, tray.id)) - printer_list = self.browse(cr, uid, printer_ids, context=context) - - 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) - return res + vals['tray_ids'] = vals_trays + return vals @api.multi def print_options(self, report, format): From 2da9855765d17b5f27c9fa449e5203c960e173dc Mon Sep 17 00:00:00 2001 From: Guewen Baconnier Date: Mon, 17 Nov 2014 17:14:37 +0100 Subject: [PATCH 11/21] unused import --- printer_tray/printer.py | 1 - 1 file changed, 1 deletion(-) diff --git a/printer_tray/printer.py b/printer_tray/printer.py index 8653b5f..f3dce95 100644 --- a/printer_tray/printer.py +++ b/printer_tray/printer.py @@ -20,7 +20,6 @@ ############################################################################## import cups -from openerp import pooler from openerp import models, fields, api From fb01704296eff0428f65f3eeb6bc4a8e607cfb1d Mon Sep 17 00:00:00 2001 From: Guewen Baconnier Date: Tue, 18 Nov 2014 09:34:32 +0100 Subject: [PATCH 12/21] add trays in printers view --- printer_tray/__openerp__.py | 1 + printer_tray/printer_tray.py | 3 ++- printer_tray/printer_view.xml | 25 +++++++++++++++++++++++++ 3 files changed, 28 insertions(+), 1 deletion(-) create mode 100644 printer_tray/printer_view.xml diff --git a/printer_tray/__openerp__.py b/printer_tray/__openerp__.py index a00ddd5..35c7f85 100644 --- a/printer_tray/__openerp__.py +++ b/printer_tray/__openerp__.py @@ -29,6 +29,7 @@ 'data': [ 'users_view.xml', 'ir_report_view.xml', + 'printer_view.xml', ], 'test': [], 'installable': True, diff --git a/printer_tray/printer_tray.py b/printer_tray/printer_tray.py index 186f2a1..ee25ca8 100644 --- a/printer_tray/printer_tray.py +++ b/printer_tray/printer_tray.py @@ -27,10 +27,11 @@ class PrinterTray(models.Model): _description = 'Printer Tray' name = fields.Char(required=True) - system_name = fields.Char(required=True) + system_name = fields.Char(required=True, readonly=True) printer_id = fields.Many2one( comodel_name='printing.printer', string='Printer', required=True, + readonly=True, ondelete='cascade', ) diff --git a/printer_tray/printer_view.xml b/printer_tray/printer_view.xml new file mode 100644 index 0000000..e0d4c29 --- /dev/null +++ b/printer_tray/printer_view.xml @@ -0,0 +1,25 @@ + + + + + printing.printer.form + printing.printer + + + + + +
+ + + + +
+
+
+
+
+
+ +
+
From b7077910f4485ea96d65eea471d4c0406a0c25b6 Mon Sep 17 00:00:00 2001 From: Guewen Baconnier Date: Tue, 18 Nov 2014 09:40:34 +0100 Subject: [PATCH 13/21] Add the printer tray choice in the 'My preferences' popup --- printer_tray/users_view.xml | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/printer_tray/users_view.xml b/printer_tray/users_view.xml index ba3bbbb..381583c 100644 --- a/printer_tray/users_view.xml +++ b/printer_tray/users_view.xml @@ -14,5 +14,17 @@ + + + res.users.form.printing.tray + res.users + + + + + + + + From 9b763de08796bdec6552495d9124a9f55b8eedcd Mon Sep 17 00:00:00 2001 From: Guewen Baconnier Date: Tue, 18 Nov 2014 10:01:53 +0100 Subject: [PATCH 14/21] Updated translations --- printer_tray/i18n/fr.po | 79 ++++++++++++++++++++----------- printer_tray/i18n/printer_tray.po | 75 +++++++++++++++++++---------- 2 files changed, 102 insertions(+), 52 deletions(-) diff --git a/printer_tray/i18n/fr.po b/printer_tray/i18n/fr.po index 649c87a..5e8881e 100644 --- a/printer_tray/i18n/fr.po +++ b/printer_tray/i18n/fr.po @@ -1,6 +1,6 @@ # Translation of OpenERP Server. # This file contains the translation of the following modules: -# * printer_tray +# * printer_tray # msgid "" msgstr "" @@ -10,15 +10,56 @@ msgstr "" "PO-Revision-Date: 2014-01-31 16:48+0100\n" "Last-Translator: Yannick Vaucher \n" "Language-Team: \n" +"Language: \n" "MIME-Version: 1.0\n" "Content-Type: text/plain; charset=UTF-8\n" "Content-Transfer-Encoding: 8bit\n" "Plural-Forms: \n" #. module: printer_tray -#: model:ir.model,name:printer_tray.model_printing_tray -msgid "Printer Tray" -msgstr "Bac d'impression" +#: field:printing.tray,create_uid:0 +msgid "Created by" +msgstr "" + +#. module: printer_tray +#: field:printing.tray,create_date:0 +msgid "Created on" +msgstr "" + +#. module: printer_tray +#: field:res.users,printer_tray_id:0 +msgid "Default Printer Paper Source" +msgstr "Source de papier par défaut" + +#. module: printer_tray +#: field:printing.tray,id:0 +msgid "ID" +msgstr "" + +#. module: printer_tray +#: field:printing.tray,write_uid:0 +msgid "Last Updated by" +msgstr "" + +#. module: printer_tray +#: field:printing.tray,write_date:0 +msgid "Last Updated on" +msgstr "" + +#. module: printer_tray +#: field:printing.tray,name:0 +msgid "Name" +msgstr "Nom" + +#. module: printer_tray +#: field:ir.actions.report.xml,printer_tray_id:0 +msgid "Paper Source" +msgstr "Source de papier" + +#. module: printer_tray +#: field:printing.printer,tray_ids:0 +msgid "Paper Sources" +msgstr "Sources de papier" #. module: printer_tray #: model:ir.model,name:printer_tray.model_printing_printer @@ -27,37 +68,21 @@ msgid "Printer" msgstr "Imprimante" #. module: printer_tray -#: field:res.users,printer_tray_id:0 -msgid "Default Printer Paper Source" -msgstr "Source de papier par défaut" - -#. module: printer_tray -#: field:printing.tray,name:0 -msgid "Name" -msgstr "Nom" +#: model:ir.model,name:printer_tray.model_printing_tray +msgid "Printer Tray" +msgstr "Bac d'impression" #. module: printer_tray #: field:printing.tray,system_name:0 -msgid "System Name" +msgid "System name" msgstr "Nom système" #. module: printer_tray -#: field:printing.printer,tray_ids:0 -msgid "Paper Sources" -msgstr "Sources de papier" +#: view:printing.printer:printer_tray.view_printing_printer_form +msgid "Trays" +msgstr "Bacs d'impression" #. module: printer_tray #: model:ir.model,name:printer_tray.model_res_users msgid "Users" msgstr "Utilisateur" - -#. module: printer_tray -#: model:ir.model,name:printer_tray.model_ir_actions_report_xml -msgid "ir.actions.report.xml" -msgstr "" - -#. module: printer_tray -#: field:ir.actions.report.xml,printer_tray_id:0 -msgid "Paper Source" -msgstr "Source de papier" - diff --git a/printer_tray/i18n/printer_tray.po b/printer_tray/i18n/printer_tray.po index f1cec9e..9832606 100644 --- a/printer_tray/i18n/printer_tray.po +++ b/printer_tray/i18n/printer_tray.po @@ -1,23 +1,64 @@ # Translation of OpenERP Server. # This file contains the translation of the following modules: -# * printer_tray +# * printer_tray # msgid "" msgstr "" "Project-Id-Version: OpenERP Server 7.0\n" "Report-Msgid-Bugs-To: \n" "POT-Creation-Date: 2014-01-31 15:44+0000\n" -"PO-Revision-Date: 2014-01-31 16:48+0100\n" +"PO-Revision-Date: 2014-11-18 08:58+0000\n" "Last-Translator: Yannick Vaucher \n" "Language-Team: \n" +"Language: \n" "MIME-Version: 1.0\n" "Content-Type: text/plain; charset=UTF-8\n" "Content-Transfer-Encoding: 8bit\n" "Plural-Forms: \n" #. module: printer_tray -#: model:ir.model,name:printer_tray.model_printing_tray -msgid "Printer Tray" +#: field:printing.tray,create_uid:0 +msgid "Created by" +msgstr "" + +#. module: printer_tray +#: field:printing.tray,create_date:0 +msgid "Created on" +msgstr "" + +#. module: printer_tray +#: field:res.users,printer_tray_id:0 +msgid "Default Printer Paper Source" +msgstr "" + +#. module: printer_tray +#: field:printing.tray,id:0 +msgid "ID" +msgstr "" + +#. module: printer_tray +#: field:printing.tray,write_uid:0 +msgid "Last Updated by" +msgstr "" + +#. module: printer_tray +#: field:printing.tray,write_date:0 +msgid "Last Updated on" +msgstr "" + +#. module: printer_tray +#: field:printing.tray,name:0 +msgid "Name" +msgstr "" + +#. module: printer_tray +#: field:ir.actions.report.xml,printer_tray_id:0 +msgid "Paper Source" +msgstr "" + +#. module: printer_tray +#: field:printing.printer,tray_ids:0 +msgid "Paper Sources" msgstr "" #. module: printer_tray @@ -27,37 +68,21 @@ msgid "Printer" msgstr "" #. module: printer_tray -#: field:res.users,printer_tray_id:0 -msgid "Default Printer Paper Source" -msgstr "" - -#. module: printer_tray -#: field:printing.tray,name:0 -msgid "Name" +#: model:ir.model,name:printer_tray.model_printing_tray +msgid "Printer Tray" msgstr "" #. module: printer_tray #: field:printing.tray,system_name:0 -msgid "System Name" +msgid "System name" msgstr "" #. module: printer_tray -#: field:printing.printer,tray_ids:0 -msgid "Paper Sources" +#: view:printing.printer:printer_tray.view_printing_printer_form +msgid "Trays" msgstr "" #. module: printer_tray #: model:ir.model,name:printer_tray.model_res_users msgid "Users" msgstr "" - -#. module: printer_tray -#: model:ir.model,name:printer_tray.model_ir_actions_report_xml -msgid "ir.actions.report.xml" -msgstr "" - -#. module: printer_tray -#: field:ir.actions.report.xml,printer_tray_id:0 -msgid "Paper Source" -msgstr "" - From ca856016d54e4ca19c9b6701f2a4f1061bfb2fda Mon Sep 17 00:00:00 2001 From: Guewen Baconnier Date: Tue, 18 Nov 2014 13:17:07 +0100 Subject: [PATCH 15/21] Wrong column name --- printer_tray/printer.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/printer_tray/printer.py b/printer_tray/printer.py index f3dce95..7197ff3 100644 --- a/printer_tray/printer.py +++ b/printer_tray/printer.py @@ -83,7 +83,7 @@ class Printer(models.Model): ('user_id', '=', self.env.uid), ('action', '!=', 'user_default')], limit=1) - if action and action.tray_id: + if action and action.printer_tray_id: tray = action.tray_id if tray: From 861d8d4fc96342db17815f55070e760e08e9bb3f Mon Sep 17 00:00:00 2001 From: Guewen Baconnier Date: Tue, 18 Nov 2014 13:23:54 +0100 Subject: [PATCH 16/21] Missing import --- printer_tray/__init__.py | 1 + 1 file changed, 1 insertion(+) diff --git a/printer_tray/__init__.py b/printer_tray/__init__.py index db2e915..1d70414 100644 --- a/printer_tray/__init__.py +++ b/printer_tray/__init__.py @@ -22,3 +22,4 @@ from . import ir_report from . import printer_tray from . import printer from . import users +from . import report_xml_action From d3b0c93af42ce8271a320ff9c6630d02d6dceb95 Mon Sep 17 00:00:00 2001 From: Guewen Baconnier Date: Fri, 5 Dec 2014 11:06:42 +0100 Subject: [PATCH 17/21] Remove the PPD file once read, otherwise they accumulate --- printer_tray/printer.py | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/printer_tray/printer.py b/printer_tray/printer.py index 7197ff3..3030ea0 100644 --- a/printer_tray/printer.py +++ b/printer_tray/printer.py @@ -19,6 +19,8 @@ # ############################################################################## import cups +import errno +import os from openerp import models, fields, api @@ -35,12 +37,19 @@ class Printer(models.Model): vals = super(Printer, self)._prepare_update_from_cups(cups_connection, cups_printer) - ppd_file_path = cups_connection.getPPD3(self.system_name) - if not ppd_file_path[2]: + ppd_info = cups_connection.getPPD3(self.system_name) + ppd_path = ppd_info[2] + if not ppd_path: return vals - ppd = cups.PPD(ppd_file_path[2]) + ppd = cups.PPD(ppd_path) option = ppd.findOption('InputSlot') + try: + os.unlink(ppd_path) + except OSError as err: + if err.errno == errno.ENOENT: + pass + raise if not option: return vals From a4d58ea62c6996e4f28d58a3a3099e3d5c707d4a Mon Sep 17 00:00:00 2001 From: Guewen Baconnier Date: Tue, 9 Dec 2014 14:25:58 +0100 Subject: [PATCH 18/21] Security file was not loaded --- printer_tray/__openerp__.py | 1 + 1 file changed, 1 insertion(+) diff --git a/printer_tray/__openerp__.py b/printer_tray/__openerp__.py index 35c7f85..568cb6a 100644 --- a/printer_tray/__openerp__.py +++ b/printer_tray/__openerp__.py @@ -30,6 +30,7 @@ 'users_view.xml', 'ir_report_view.xml', 'printer_view.xml', + 'security/ir.model.access.csv', ], 'test': [], 'installable': True, From 80b734b3d9a37f6f17f1e3d6db0ee715a2142de4 Mon Sep 17 00:00:00 2001 From: Guewen Baconnier Date: Tue, 20 Jan 2015 09:34:09 +0100 Subject: [PATCH 19/21] Add the trays in printing.report.xml.action view So they can be configured per user and per report --- printer_tray/__openerp__.py | 1 + printer_tray/report_xml_action_view.xml | 25 +++++++++++++++++++++++++ 2 files changed, 26 insertions(+) create mode 100644 printer_tray/report_xml_action_view.xml diff --git a/printer_tray/__openerp__.py b/printer_tray/__openerp__.py index 568cb6a..e73a2b6 100644 --- a/printer_tray/__openerp__.py +++ b/printer_tray/__openerp__.py @@ -30,6 +30,7 @@ 'users_view.xml', 'ir_report_view.xml', 'printer_view.xml', + 'report_xml_action_view.xml', 'security/ir.model.access.csv', ], 'test': [], diff --git a/printer_tray/report_xml_action_view.xml b/printer_tray/report_xml_action_view.xml new file mode 100644 index 0000000..8d60047 --- /dev/null +++ b/printer_tray/report_xml_action_view.xml @@ -0,0 +1,25 @@ + + + + + printing.report.xml.action.form + printing.report.xml.action + + + + + + + + + printing.report.xml.action.form + printing.report.xml.action + + + + + + + + + From cfdfc8e3a27de9a9b2bd9bfefc092068361470f7 Mon Sep 17 00:00:00 2001 From: Guewen Baconnier Date: Tue, 20 Jan 2015 11:00:44 +0100 Subject: [PATCH 20/21] Update the description with the OCA template --- printer_tray/README.rst | 62 +++++++++++++++++++++++++++++++++++++---- 1 file changed, 57 insertions(+), 5 deletions(-) diff --git a/printer_tray/README.rst b/printer_tray/README.rst index 3e7ce79..68e369d 100644 --- a/printer_tray/README.rst +++ b/printer_tray/README.rst @@ -1,15 +1,67 @@ Report to printer - Paper tray selection ======================================== -**Author:** Camptocamp SA +Extends the module **Report to printer** (``base_report_to_printer``) +to add the printers trays. -*This module extends `Report to printer` module.* - -It detects trays on printer installation plus permits to select the +It detects trays on printers installation plus permits to select the paper source on which you want to print directly. You will find this option on default user config, on default report config and on specific config per user per report. -This allows you to dedicate a specific paper source for exemple for +This allows you to dedicate a specific paper source for example for preprinted paper such as payment slip. + +Installation +============ + +Considering that you already use the module **Report to printer**, you +just have to install this extension. + +Configuration +============= + +To configure this module, you need to: + + * Update the CUPS printers in *Settings > Printing > Update Printers + from CUPS* + * If you want to print a report on a specific tray, you can change + their "Paper Source" in *Settings > Printing > Reports* + * If you want to print a report on a specific tray for a user, you can + change their "Paper Source" in *Settings > Printing > Reports* in + *Specific actions per user* + * Users may also select a default tray in their preferences + +Usage +===== + +There is no special usage, once configured, reports are printed in the +select tray. When no tray is configured for a report and a user, the +default tray setup on the CUPS server is used. + +Known issues / Roadmap +====================== + + +Credits +======= + +Contributors +------------ + +* Yannick Vaucher +* Guewen Baconnier + +Maintainer +---------- + +.. image:: http://odoo-community.org/logo.png + :alt: Odoo Community Association + :target: http://odoo-community.org + +This module is maintained by the OCA. + +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. + +To contribute to this module, please visit http://odoo-community.org. From cacc5423f6c0277ef23f9ef7e1d5059018a7841e Mon Sep 17 00:00:00 2001 From: Guewen Baconnier Date: Tue, 20 Jan 2015 11:44:13 +0100 Subject: [PATCH 21/21] Reset the printer's tray when the printer is changed --- printer_tray/ir_report.py | 7 ++++++- printer_tray/report_xml_action.py | 5 +++++ printer_tray/users.py | 7 ++++++- 3 files changed, 17 insertions(+), 2 deletions(-) diff --git a/printer_tray/ir_report.py b/printer_tray/ir_report.py index 9b36724..fb77593 100644 --- a/printer_tray/ir_report.py +++ b/printer_tray/ir_report.py @@ -18,7 +18,7 @@ # along with this program. If not, see . # ############################################################################## -from openerp import models, fields +from openerp import models, fields, api class IrActionsReportXml(models.Model): @@ -30,3 +30,8 @@ class IrActionsReportXml(models.Model): string='Paper Source', domain="[('printer_id', '=', printing_printer_id)]", ) + + @api.onchange('printing_printer_id') + def onchange_printing_printer_id(self): + """ Reset the tray when the printer is changed """ + self.printer_tray_id = False diff --git a/printer_tray/report_xml_action.py b/printer_tray/report_xml_action.py index 0e29524..5056150 100644 --- a/printer_tray/report_xml_action.py +++ b/printer_tray/report_xml_action.py @@ -37,3 +37,8 @@ class ReportXMLAction(models.Model): res = super(ReportXMLAction, self).behaviour() res['tray'] = self.printer_tray_id.system_name return res + + @api.onchange('printer_id') + def onchange_printer_id(self): + """ Reset the tray when the printer is changed """ + self.printer_tray_id = False diff --git a/printer_tray/users.py b/printer_tray/users.py index 57d1276..47d7faa 100644 --- a/printer_tray/users.py +++ b/printer_tray/users.py @@ -18,7 +18,7 @@ # along with this program. If not, see . # ############################################################################## -from openerp import models, fields +from openerp import models, fields, api class ResUsers(models.Model): @@ -30,3 +30,8 @@ class ResUsers(models.Model): string='Default Printer Paper Source', domain="[('printer_id', '=', printing_printer_id)]", ) + + @api.onchange('printing_printer_id') + def onchange_printing_printer_id(self): + """ Reset the tray when the printer is changed """ + self.printer_tray_id = False