From c5060c992fe2e1492abfa5f5baa5c181c6895268 Mon Sep 17 00:00:00 2001 From: czoellner Date: Sun, 25 Oct 2015 12:14:52 +0100 Subject: [PATCH 01/10] pass context to printer to use it for example in print_options() * context was lost while getting report * now it will be passed using with_context * could be used for print_options (example: pass copies amount for productlabals) --- base_report_to_printer/report.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/base_report_to_printer/report.py b/base_report_to_printer/report.py index 4986d15..d63c388 100644 --- a/base_report_to_printer/report.py +++ b/base_report_to_printer/report.py @@ -42,7 +42,8 @@ class Report(models.Model): raise exceptions.Warning( _('No printer configured to print this report.') ) - return printer.print_document(report, document, report.report_type) + return printer.with_context(context).print_document( + report, document, report.report_type) @api.v8 def print_document(self, records, report_name, html=None, data=None): From 73ee88eac47934b6a1b4b4a85993a6e98f7e3078 Mon Sep 17 00:00:00 2001 From: Alexis de Lattre Date: Mon, 2 Nov 2015 22:49:28 +0100 Subject: [PATCH 02/10] Add support for multiple copies --- base_report_to_printer/printing.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/base_report_to_printer/printing.py b/base_report_to_printer/printing.py index 742859b..129fc62 100644 --- a/base_report_to_printer/printing.py +++ b/base_report_to_printer/printing.py @@ -108,15 +108,17 @@ class PrintingPrinter(models.Model): self.write(vals) @api.multi - def print_options(self, report, format): + def print_options(self, report, format, copies=1): """ Hook to set print options """ options = {} if format == 'raw': options['raw'] = 'True' + if copies > 1: + options['copies'] = str(copies) return options @api.multi - def print_document(self, report, content, format): + def print_document(self, report, content, format, copies=1): """ Print a file Format could be pdf, qweb-pdf, raw, ... @@ -142,7 +144,7 @@ class PrintingPrinter(models.Model): "you can reach it from the Odoo server.") % (CUPS_HOST, CUPS_PORT)) - options = self.print_options(report, format) + options = self.print_options(report, format, copies) _logger.debug( 'Sending job to CUPS printer %s on %s' From a0d1438b0e88c6f4d074625860b07d825198d53a Mon Sep 17 00:00:00 2001 From: Yannick Vaucher Date: Tue, 24 Nov 2015 13:45:21 +0100 Subject: [PATCH 03/10] Merge branch '8.0' of https://github.com/intero-chz/report-print-send into 8.0 --- base_report_to_printer/__openerp__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/base_report_to_printer/__openerp__.py b/base_report_to_printer/__openerp__.py index b6c8f49..9259a54 100644 --- a/base_report_to_printer/__openerp__.py +++ b/base_report_to_printer/__openerp__.py @@ -23,7 +23,7 @@ ############################################################################## { 'name': "Report to printer", - 'version': '8.0.0.1.1', + 'version': '8.0.0.1.2', 'category': 'Generic Modules/Base', 'author': "Agile Business Group & Domsense, Pegueroles SCP, NaN," "Odoo Community Association (OCA)", From 52e1aa44ee457b0ae7aba9a1d454ee76c66c92c8 Mon Sep 17 00:00:00 2001 From: Roel Adriaans Date: Thu, 10 Dec 2015 12:29:02 +0100 Subject: [PATCH 04/10] [IMP] Soft fail on missing cups import cups is an external dependency, if it is not installed Odoo will not start. OCA guidelines specify guidelines for External dependencies, code is from there. --- base_report_to_printer/printing.py | 10 ++++++++-- base_report_to_printer/wizard/update_printers.py | 11 ++++++++--- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/base_report_to_printer/printing.py b/base_report_to_printer/printing.py index 129fc62..b4dd364 100644 --- a/base_report_to_printer/printing.py +++ b/base_report_to_printer/printing.py @@ -22,14 +22,20 @@ # ############################################################################## import logging +_logger = logging.getLogger(__name__) + import os from tempfile import mkstemp -import cups + +try: + import cups +except ImportError: + _logger.debug('Cannot `import cups`.') + from openerp import models, fields, api, _ from openerp.exceptions import Warning from openerp.tools.config import config -_logger = logging.getLogger(__name__) CUPS_HOST = config.get('cups_host', 'localhost') CUPS_PORT = int(config.get('cups_port', 631)) # config.get returns a string diff --git a/base_report_to_printer/wizard/update_printers.py b/base_report_to_printer/wizard/update_printers.py index 7af8f10..0282c15 100644 --- a/base_report_to_printer/wizard/update_printers.py +++ b/base_report_to_printer/wizard/update_printers.py @@ -21,13 +21,18 @@ # ############################################################################## -import cups +import logging +_logger = logging.getLogger(__name__) + +try: + import cups +except ImportError: + _logger.debug('Cannot `import cups`.') + from openerp.exceptions import Warning from openerp import models, api, _ from openerp.tools.config import config -import logging -_logger = logging.getLogger(__name__) CUPS_HOST = config.get('cups_host', 'localhost') CUPS_PORT = int(config.get('cups_port', 631)) From 4b080d7a631675d1988c7442f119dda2d52ee9b3 Mon Sep 17 00:00:00 2001 From: Dave Lasley Date: Mon, 4 Jul 2016 14:36:57 -0700 Subject: [PATCH 05/10] [MIG] base_report_to_printer: Upgrade to v9 --- base_report_to_printer/README.rst | 66 +++++++- base_report_to_printer/__init__.py | 37 +--- base_report_to_printer/__openerp__.py | 55 +++--- .../base_report_to_printer.xml | 11 -- .../{ => data}/printing_data.xml | 10 +- base_report_to_printer/i18n/fr.po | 44 ++--- base_report_to_printer/i18n/it.po | 14 +- base_report_to_printer/models/__init__.py | 8 + .../ir_actions_report_xml.py} | 37 +--- .../models/printing_action.py | 28 ++++ .../printing_printer.py} | 64 ++----- .../models/printing_report_xml_action.py | 39 +++++ base_report_to_printer/{ => models}/report.py | 21 +-- base_report_to_printer/models/res_users.py | 27 +++ base_report_to_printer/printing_view.xml | 158 ------------------ base_report_to_printer/report_service.py | 36 ++-- base_report_to_printer/report_xml_action.py | 52 ------ base_report_to_printer/security/security.xml | 44 ++--- ...ctionmanager.js => qweb_action_manager.js} | 27 +-- base_report_to_printer/users.py | 43 ----- base_report_to_printer/views/assets.xml | 9 + .../views/ir_actions_report_xml_view.xml | 23 +++ .../views/printing_printer_view.xml | 81 +++++++++ .../views/printing_report_view.xml | 34 ++++ .../views/res_users_view.xml | 32 ++++ base_report_to_printer/wizard/__init__.py | 22 --- base_report_to_printer/wizards/__init__.py | 3 + .../printing_printer_update_wizard.py} | 40 ++--- .../printing_printer_update_wizard_view.xml} | 2 +- printer_tray/i18n/fr.po | 2 +- printer_tray/i18n/printer_tray.po | 2 +- printer_tray/ir_report_view.xml | 4 +- printer_tray/printer_view.xml | 4 +- printer_tray/report_xml_action_view.xml | 8 +- printer_tray/users_view.xml | 4 +- 35 files changed, 512 insertions(+), 579 deletions(-) delete mode 100644 base_report_to_printer/base_report_to_printer.xml rename base_report_to_printer/{ => data}/printing_data.xml (84%) create mode 100644 base_report_to_printer/models/__init__.py rename base_report_to_printer/{ir_report.py => models/ir_actions_report_xml.py} (66%) create mode 100644 base_report_to_printer/models/printing_action.py rename base_report_to_printer/{printing.py => models/printing_printer.py} (76%) create mode 100644 base_report_to_printer/models/printing_report_xml_action.py rename base_report_to_printer/{ => models}/report.py (77%) create mode 100644 base_report_to_printer/models/res_users.py delete mode 100644 base_report_to_printer/printing_view.xml delete mode 100644 base_report_to_printer/report_xml_action.py rename base_report_to_printer/static/src/js/{qwebactionmanager.js => qweb_action_manager.js} (70%) delete mode 100644 base_report_to_printer/users.py create mode 100644 base_report_to_printer/views/assets.xml create mode 100644 base_report_to_printer/views/ir_actions_report_xml_view.xml create mode 100644 base_report_to_printer/views/printing_printer_view.xml create mode 100644 base_report_to_printer/views/printing_report_view.xml create mode 100644 base_report_to_printer/views/res_users_view.xml delete mode 100644 base_report_to_printer/wizard/__init__.py create mode 100644 base_report_to_printer/wizards/__init__.py rename base_report_to_printer/{wizard/update_printers.py => wizards/printing_printer_update_wizard.py} (61%) rename base_report_to_printer/{wizard/update_printers.xml => wizards/printing_printer_update_wizard_view.xml} (95%) diff --git a/base_report_to_printer/README.rst b/base_report_to_printer/README.rst index 8ff2575..3e7180d 100644 --- a/base_report_to_printer/README.rst +++ b/base_report_to_printer/README.rst @@ -1,5 +1,11 @@ -Report to printer ------------------ +.. image:: https://img.shields.io/badge/licence-AGPL--3-blue.svg + :target: http://www.gnu.org/licenses/agpl-3.0-standalone.html + :alt: License: AGPL-3 + +================= +Report To Printer +================= + This module allows users to send reports to a printer attached to the server. @@ -18,11 +24,22 @@ Settings can be configured: * per report * per user and report +Installation +============ -After installing enable the "Printing / Print Operator" option under access +* Install PyCups - https://pypi.python.org/pypi/pycups + + +Configuration +============= + +After installing enable the "Printing / Print User" option under access rights to give users the ability to view the print menu. +Usage +===== + To show all available printers for your server, use the `Settings/Configuration/Printing/Update Printers from CUPS` wizard. @@ -36,12 +53,31 @@ Caveat The notification when a report is sent to a printer will not be displayed for the deprecated report types (RML, Webkit, ...). -Dependencies ------------- +.. image:: https://odoo-community.org/website/image/ir.attachment/5784_f2813bd/datas + :alt: Try me on Runbot + :target: https://runbot.odoo-community.org/runbot/144/9.0 -This module requires pycups -https://pypi.python.org/pypi/pycups +Known issues / Roadmap +====================== + + + +Bug Tracker +=========== + +Bugs are tracked on `GitHub Issues +`_. In case of trouble, please +check there if your issue has already been reported. If you spotted it first, +help us smashing it by providing a detailed and welcomed feedback. + +Credits +======= + +Images +------ + +* Odoo Community Association: `Icon `_. Contributors ------------ @@ -53,3 +89,19 @@ Contributors * Yannick Vaucher * Lionel Sausin * Guewen Baconnier +* Dave Lasley + +Maintainer +---------- + +.. image:: https://odoo-community.org/logo.png + :alt: Odoo Community Association + :target: https://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 https://odoo-community.org. diff --git a/base_report_to_printer/__init__.py b/base_report_to_printer/__init__.py index ddd67e1..754152d 100644 --- a/base_report_to_printer/__init__.py +++ b/base_report_to_printer/__init__.py @@ -1,30 +1,11 @@ # -*- coding: utf-8 -*- -############################################################################## -# -# Copyright (c) 2007 Ferran Pegueroles -# Copyright (c) 2009 Albert Cervera i Areny -# Copyright (C) 2011 Agile Business Group sagl () -# Copyright (C) 2011 Domsense srl () -# Copyright (C) 2013-2014 Camptocamp () -# -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU Affero General Public License as published -# by the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU Affero General Public License -# along with this program. If not, see . -# -############################################################################## -from . import printing -from . import report -from . import report_xml_action +# Copyright (c) 2007 Ferran Pegueroles +# Copyright (c) 2009 Albert Cervera i Areny +# Copyright (C) 2011 Agile Business Group sagl () +# Copyright (C) 2011 Domsense srl () +# Copyright (C) 2013-2014 Camptocamp () +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from . import models from . import report_service -from . import users -from . import ir_report -from . import wizard +from . import wizards diff --git a/base_report_to_printer/__openerp__.py b/base_report_to_printer/__openerp__.py index 9259a54..1d95b65 100644 --- a/base_report_to_printer/__openerp__.py +++ b/base_report_to_printer/__openerp__.py @@ -1,48 +1,33 @@ # -*- coding: utf-8 -*- -############################################################################## -# -# Copyright (c) 2007 Ferran Pegueroles -# Copyright (c) 2009 Albert Cervera i Areny -# Copyright (C) 2011 Agile Business Group sagl () -# Copyright (C) 2011 Domsense srl () -# Copyright (C) 2013-2014 Camptocamp () -# -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU Affero General Public License as published -# by the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU Affero General Public License -# along with this program. If not, see . -# -############################################################################## +# Copyright (c) 2007 Ferran Pegueroles +# Copyright (c) 2009 Albert Cervera i Areny +# Copyright (C) 2011 Agile Business Group sagl () +# Copyright (C) 2011 Domsense srl () +# Copyright (C) 2013-2014 Camptocamp () +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + { 'name': "Report to printer", - 'version': '8.0.0.1.2', + 'version': '9.0.1.0.0', 'category': 'Generic Modules/Base', 'author': "Agile Business Group & Domsense, Pegueroles SCP, NaN," - "Odoo Community Association (OCA)", + " LasLabs, Odoo Community Association (OCA)", 'website': 'http://www.agilebg.com', 'license': 'AGPL-3', - "depends": ['base', - 'report', - ], + "depends": ['report'], 'data': [ + 'data/printing_data.xml', 'security/security.xml', - 'printing_data.xml', - 'printing_view.xml', - 'base_report_to_printer.xml', - 'wizard/update_printers.xml', + 'views/assets.xml', + 'views/printing_printer_view.xml', + 'views/printing_report_view.xml', + 'views/res_users_view.xml', + 'views/ir_actions_report_xml_view.xml', + 'wizards/printing_printer_update_wizard_view.xml', ], - 'installable': False, - 'auto_install': False, + 'installable': True, 'application': True, 'external_dependencies': { - 'python': ['cups'] - } + 'python': ['cups'], + }, } diff --git a/base_report_to_printer/base_report_to_printer.xml b/base_report_to_printer/base_report_to_printer.xml deleted file mode 100644 index c1c0bbc..0000000 --- a/base_report_to_printer/base_report_to_printer.xml +++ /dev/null @@ -1,11 +0,0 @@ - - - - - - - diff --git a/base_report_to_printer/printing_data.xml b/base_report_to_printer/data/printing_data.xml similarity index 84% rename from base_report_to_printer/printing_data.xml rename to base_report_to_printer/data/printing_data.xml index 5998d14..f1fca1d 100644 --- a/base_report_to_printer/printing_data.xml +++ b/base_report_to_printer/data/printing_data.xml @@ -1,5 +1,5 @@ - + @@ -11,9 +11,9 @@ client - - property_printing_action - + + property_printing_action_id + @@ -31,4 +31,4 @@ - + diff --git a/base_report_to_printer/i18n/fr.po b/base_report_to_printer/i18n/fr.po index 8c198cd..7f65d29 100644 --- a/base_report_to_printer/i18n/fr.po +++ b/base_report_to_printer/i18n/fr.po @@ -18,7 +18,7 @@ msgstr "" "X-Generator: Launchpad (build 16996)\n" #. module: base_report_to_printer -#: field:ir.actions.report.xml,property_printing_action:0 +#: field:ir.actions.report.xml,property_printing_action_id:0 #: field:printing.report.xml.action,action:0 msgid "Action" msgstr "Action" @@ -70,7 +70,7 @@ msgstr "Imprimante par défaut" #. module: base_report_to_printer #. openerp-web -#: code:addons/base_report_to_printer/static/src/js/qwebactionmanager.js:27 +#: code:addons/base_report_to_printer/static/src/js/qweb_action_manager.js:27 #, python-format msgid "Document sent to the printer " msgstr "Document envoyé à l'imprimante " @@ -82,7 +82,7 @@ msgstr "Erreur" #. module: base_report_to_printer #. openerp-web -#: code:addons/base_report_to_printer/static/src/js/qwebactionmanager.js:30 +#: code:addons/base_report_to_printer/static/src/js/qweb_action_manager.js:30 #, python-format msgid "Error when sending the document to the printer " msgstr "Erreur lors de l'envoi du document à l'imprimante " @@ -139,12 +139,12 @@ msgid "No printer configured to print this report." msgstr "Pas d'imprimante configurée pour imprimer ce rapport." #. module: base_report_to_printer -#: view:res.users:base_report_to_printer.view_printing_users_form +#: view:res.users:base_report_to_printer.view_users_form msgid "Preferences" msgstr "Préférences" #. module: base_report_to_printer -#: view:ir.actions.report.xml:base_report_to_printer.action_report_xml_form +#: view:ir.actions.report.xml:base_report_to_printer.act_report_xml_view msgid "Print" msgstr "Imprimer" @@ -161,22 +161,22 @@ msgid "Printer" msgstr "Imprimante" #. module: base_report_to_printer -#: model:ir.ui.menu,name:base_report_to_printer.menu_printing_printer_form -#: view:printing.printer:base_report_to_printer.view_printing_printer_form -#: view:printing.printer:base_report_to_printer.view_printing_printer_search -#: view:printing.printer:base_report_to_printer.view_printing_printer_tree +#: model:ir.ui.menu,name:base_report_to_printer.printing_printer_menu +#: view:printing.printer:base_report_to_printer.printing_printer_view_form +#: view:printing.printer:base_report_to_printer.printing_printer_view_search +#: view:printing.printer:base_report_to_printer.printing_printer_view_tree msgid "Printers" msgstr "Imprimantes" #. module: base_report_to_printer -#: model:ir.ui.menu,name:base_report_to_printer.menu_printing_main +#: model:ir.ui.menu,name:base_report_to_printer.printing_menu #: selection:printing.printer,status:0 -#: view:res.users:base_report_to_printer.view_printing_users_prefs +#: view:res.users:base_report_to_printer.view_users_form_simple_modif msgid "Printing" msgstr "Impression en cours" #. module: base_report_to_printer -#: model:res.groups,name:base_report_to_printer.res_groups_printingprintoperator0 +#: model:res.groups,name:base_report_to_printer.printing_group_manager msgid "Printing / Print Operator" msgstr "Opérateur d'impression" @@ -187,8 +187,8 @@ msgstr "Action d'impression" #. module: base_report_to_printer #. openerp-web -#: code:addons/base_report_to_printer/static/src/js/qwebactionmanager.js:26 -#: code:addons/base_report_to_printer/static/src/js/qwebactionmanager.js:29 +#: code:addons/base_report_to_printer/static/src/js/qweb_action_manager.js:26 +#: code:addons/base_report_to_printer/static/src/js/qweb_action_manager.js:29 #: model:ir.model,name:base_report_to_printer.model_report #: field:printing.report.xml.action,report_id:0 #, python-format @@ -196,19 +196,19 @@ msgid "Report" msgstr "Rapport" #. module: base_report_to_printer -#: model:ir.model,name:base_report_to_printer.model_printing_report_xml_action -#: view:printing.report.xml.action:base_report_to_printer.printing_report_xml_action_form -#: view:printing.report.xml.action:base_report_to_printer.printing_report_xml_action_tree +#: model:ir.model,name:base_report_to_printer.model_printing_report_xml_action_view_form +#: view:printing.report.xml.action:base_report_to_printer.printing_report_xml_action_view_form +#: view:printing.report.xml.action:base_report_to_printer.printing_report_xml_action_view_tree msgid "Report Printing Actions" msgstr "Actions d'impression de rapports" #. module: base_report_to_printer -#: model:ir.ui.menu,name:base_report_to_printer.menu_printing_reports +#: model:ir.ui.menu,name:base_report_to_printer.printing_report_xml_action_menu msgid "Reports" msgstr "Rapport" #. module: base_report_to_printer -#: view:ir.actions.report.xml:base_report_to_printer.action_report_xml_form +#: view:ir.actions.report.xml:base_report_to_printer.act_report_xml_view msgid "Security" msgstr "Sécurité" @@ -218,17 +218,17 @@ msgid "Server Error" msgstr "Erreur serveur" #. module: base_report_to_printer -#: view:printing.printer:base_report_to_printer.view_printing_printer_form +#: view:printing.printer:base_report_to_printer.printing_printer_view_form msgid "Set Default" msgstr "Définir par défaut" #. module: base_report_to_printer -#: model:ir.actions.act_window,name:base_report_to_printer.action_printing_printer_form +#: model:ir.actions.act_window,name:base_report_to_printer.printing_printer_action msgid "Show Printers" msgstr "Afficher les imprimantes" #. module: base_report_to_printer -#: view:ir.actions.report.xml:base_report_to_printer.action_report_xml_form +#: view:ir.actions.report.xml:base_report_to_printer.act_report_xml_view msgid "Specific actions per user" msgstr "Action spécifique par utilisateur" diff --git a/base_report_to_printer/i18n/it.po b/base_report_to_printer/i18n/it.po index e6f25c6..08a99a9 100644 --- a/base_report_to_printer/i18n/it.po +++ b/base_report_to_printer/i18n/it.po @@ -44,8 +44,8 @@ msgid "Location" msgstr "Locazione" #. module: base_report_to_printer -#: model:ir.actions.act_window,name:base_report_to_printer.action_printing_printer_form -#: model:ir.ui.menu,name:base_report_to_printer.menu_printing_printer_form +#: model:ir.actions.act_window,name:base_report_to_printer.printing_printer_action +#: model:ir.ui.menu,name:base_report_to_printer.printing_printer_menu #: view:printing.printer:0 msgid "Printers" msgstr "Stampanti" @@ -88,7 +88,7 @@ msgid "Users" msgstr "" #. module: base_report_to_printer -#: model:ir.model,name:base_report_to_printer.model_printing_report_xml_action +#: model:ir.model,name:base_report_to_printer.model_printing_report_xml_action_view_form #: view:printing.report.xml.action:0 msgid "Report Printing Actions" msgstr "Azioni di stampa report" @@ -119,7 +119,7 @@ msgid "Status" msgstr "Stato" #. module: base_report_to_printer -#: model:ir.actions.act_window,name:base_report_to_printer.action_printing_printer_form +#: model:ir.actions.act_window,name:base_report_to_printer.printing_printer_action msgid "Show Printers" msgstr "" @@ -170,7 +170,7 @@ msgid "Send to Printer" msgstr "Invia alla stampante" #. module: base_report_to_printer -#: model:ir.ui.menu,name:base_report_to_printer.menu_printing_main +#: model:ir.ui.menu,name:base_report_to_printer.printing_menu #: selection:printing.printer,status:0 msgid "Printing" msgstr "Stampa" @@ -181,7 +181,7 @@ msgid "Error" msgstr "Errore" #. module: base_report_to_printer -#: field:ir.actions.report.xml,property_printing_action:0 +#: field:ir.actions.report.xml,property_printing_action_id:0 #: field:printing.report.xml.action,action:0 msgid "Action" msgstr "Azione" @@ -219,7 +219,7 @@ msgid "Cancel" msgstr "Annulla" #. module: base_report_to_printer -#: model:res.groups,name:base_report_to_printer.res_groups_printingprintoperator0 +#: model:res.groups,name:base_report_to_printer.printing_group_manager msgid "Printing / Print Operator" msgstr "" diff --git a/base_report_to_printer/models/__init__.py b/base_report_to_printer/models/__init__.py new file mode 100644 index 0000000..9ed6c15 --- /dev/null +++ b/base_report_to_printer/models/__init__.py @@ -0,0 +1,8 @@ +# -*- coding: utf-8 -*- + +from . import ir_actions_report_xml +from . import printing_action +from . import printing_printer +from . import printing_report_xml_action +from . import report +from . import res_users diff --git a/base_report_to_printer/ir_report.py b/base_report_to_printer/models/ir_actions_report_xml.py similarity index 66% rename from base_report_to_printer/ir_report.py rename to base_report_to_printer/models/ir_actions_report_xml.py index 7238277..511915d 100644 --- a/base_report_to_printer/ir_report.py +++ b/base_report_to_printer/models/ir_actions_report_xml.py @@ -1,41 +1,22 @@ # -*- coding: utf-8 -*- -############################################################################## -# -# Copyright (c) 2007 Ferran Pegueroles -# Copyright (c) 2009 Albert Cervera i Areny -# Copyright (C) 2011 Agile Business Group sagl () -# Copyright (C) 2011 Domsense srl () -# Copyright (C) 2013-2014 Camptocamp () -# -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU Affero General Public License as published -# by the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU Affero General Public License -# along with this program. If not, see . -# -############################################################################## -import logging +# Copyright (c) 2007 Ferran Pegueroles +# Copyright (c) 2009 Albert Cervera i Areny +# Copyright (C) 2011 Agile Business Group sagl () +# Copyright (C) 2011 Domsense srl () +# Copyright (C) 2013-2014 Camptocamp () +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). from openerp import models, fields, api -_logger = logging.getLogger('base_report_to_printer') - -class ReportXml(models.Model): +class IrActionsReportXml(models.Model): """ Reports """ _inherit = 'ir.actions.report.xml' - property_printing_action = fields.Many2one( + property_printing_action_id = fields.Many2one( comodel_name='printing.action', string='Action', company_dependent=True, @@ -91,7 +72,7 @@ class ReportXml(models.Model): printer = default_printer # Retrieve report default values - report_action = report.property_printing_action + report_action = report.property_printing_action_id if report_action and report_action.type != 'user_default': action = report_action.type if report.printing_printer_id: diff --git a/base_report_to_printer/models/printing_action.py b/base_report_to_printer/models/printing_action.py new file mode 100644 index 0000000..0781b99 --- /dev/null +++ b/base_report_to_printer/models/printing_action.py @@ -0,0 +1,28 @@ +# -*- coding: utf-8 -*- +# Copyright (c) 2007 Ferran Pegueroles +# Copyright (c) 2009 Albert Cervera i Areny +# Copyright (C) 2011 Agile Business Group sagl () +# Copyright (C) 2011 Domsense srl () +# Copyright (C) 2013-2014 Camptocamp () +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from openerp import models, fields, api + + +@api.model +def _available_action_types(self): + return [('server', 'Send to Printer'), + ('client', 'Send to Client'), + ('user_default', "Use user's defaults"), + ] + + +class PrintingAction(models.Model): + _name = 'printing.action' + _description = 'Print Job Action' + + name = fields.Char(required=True) + type = fields.Selection( + lambda s: _available_action_types(s), + required=True, + ) diff --git a/base_report_to_printer/printing.py b/base_report_to_printer/models/printing_printer.py similarity index 76% rename from base_report_to_printer/printing.py rename to base_report_to_printer/models/printing_printer.py index b4dd364..dba4382 100644 --- a/base_report_to_printer/printing.py +++ b/base_report_to_printer/models/printing_printer.py @@ -1,43 +1,30 @@ # -*- coding: utf-8 -*- -############################################################################## -# -# Copyright (c) 2007 Ferran Pegueroles -# Copyright (c) 2009 Albert Cervera i Areny -# Copyright (C) 2011 Agile Business Group sagl () -# Copyright (C) 2011 Domsense srl () -# Copyright (C) 2013-2014 Camptocamp () -# -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU Affero General Public License as published -# by the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU Affero General Public License -# along with this program. If not, see . -# -############################################################################## +# Copyright (c) 2007 Ferran Pegueroles +# Copyright (c) 2009 Albert Cervera i Areny +# Copyright (C) 2011 Agile Business Group sagl () +# Copyright (C) 2011 Domsense srl () +# Copyright (C) 2013-2014 Camptocamp () +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + import logging -_logger = logging.getLogger(__name__) import os from tempfile import mkstemp -try: - import cups -except ImportError: - _logger.debug('Cannot `import cups`.') - from openerp import models, fields, api, _ from openerp.exceptions import Warning from openerp.tools.config import config +try: + import cups +except ImportError: + _logger = logging.getLogger(__name__) + _logger.debug('Cannot `import cups`.') + + CUPS_HOST = config.get('cups_host', 'localhost') CUPS_PORT = int(config.get('cups_port', 631)) # config.get returns a string +_logger = logging.getLogger(__name__) class PrintingPrinter(models.Model): @@ -46,7 +33,7 @@ class PrintingPrinter(models.Model): """ _name = 'printing.printer' - _description = 'Printer' + _description = 'Printing Printers' _order = 'name' name = fields.Char(required=True, select=True) @@ -175,22 +162,3 @@ class PrintingPrinter(models.Model): @api.multi def get_default(self): return self.search([('default', '=', True)], limit=1) - -# -# Actions -# - - -def _available_action_types(self): - return [('server', 'Send to Printer'), - ('client', 'Send to Client'), - ('user_default', "Use user's defaults"), - ] - - -class PrintingAction(models.Model): - _name = 'printing.action' - _description = 'Print Job Action' - - name = fields.Char(required=True) - type = fields.Selection(_available_action_types, required=True) diff --git a/base_report_to_printer/models/printing_report_xml_action.py b/base_report_to_printer/models/printing_report_xml_action.py new file mode 100644 index 0000000..2a67c9b --- /dev/null +++ b/base_report_to_printer/models/printing_report_xml_action.py @@ -0,0 +1,39 @@ +# -*- coding: utf-8 -*- +# Copyright (c) 2007 Ferran Pegueroles +# Copyright (c) 2009 Albert Cervera i Areny +# Copyright (C) 2011 Agile Business Group sagl () +# Copyright (C) 2011 Domsense srl () +# Copyright (C) 2013-2014 Camptocamp () +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from openerp import models, fields, api + +from .printing_action import _available_action_types + + +class PrintingReportXmlAction(models.Model): + _name = 'printing.report.xml.action' + _description = 'Printing Report Printing Actions' + + report_id = fields.Many2one(comodel_name='ir.actions.report.xml', + string='Report', + required=True, + ondelete='cascade') + user_id = fields.Many2one(comodel_name='res.users', + string='User', + required=True, + ondelete='cascade') + action = fields.Selection( + lambda s: _available_action_types(s), + required=True, + ) + printer_id = fields.Many2one(comodel_name='printing.printer', + string='Printer') + + @api.multi + def behaviour(self): + if not self: + return {} + return {'action': self.action, + 'printer': self.printer_id, + } diff --git a/base_report_to_printer/report.py b/base_report_to_printer/models/report.py similarity index 77% rename from base_report_to_printer/report.py rename to base_report_to_printer/models/report.py index d63c388..a304e82 100644 --- a/base_report_to_printer/report.py +++ b/base_report_to_printer/models/report.py @@ -1,23 +1,6 @@ # -*- coding: utf-8 -*- -############################################################################## -# -# Author: Guewen Baconnier -# Copyright 2014 Camptocamp SA -# -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU Affero General Public License as -# published by the Free Software Foundation, either version 3 of the -# License, or (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU Affero General Public License for more details. -# -# You should have received a copy of the GNU Affero General Public License -# along with this program. If not, see . -# -############################################################################## +# Copyright (c) 2014 Camptocamp SA +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). from openerp import models, exceptions, _, api diff --git a/base_report_to_printer/models/res_users.py b/base_report_to_printer/models/res_users.py new file mode 100644 index 0000000..e5cf607 --- /dev/null +++ b/base_report_to_printer/models/res_users.py @@ -0,0 +1,27 @@ +# -*- coding: utf-8 -*- +# Copyright (c) 2007 Ferran Pegueroles +# Copyright (c) 2009 Albert Cervera i Areny +# Copyright (C) 2011 Agile Business Group sagl () +# Copyright (C) 2011 Domsense srl () +# Copyright (C) 2013-2014 Camptocamp () +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from openerp import models, fields, api + +from .printing_action import _available_action_types + + +class ResUsers(models.Model): + _inherit = 'res.users' + + printing_action = fields.Selection( + lambda s: s._user_available_action_types(), + ) + printing_printer_id = fields.Many2one(comodel_name='printing.printer', + string='Default Printer') + + @api.model + def _user_available_action_types(self): + return [(code, string) for code, string + in _available_action_types(self) + if code != 'user_default'] diff --git a/base_report_to_printer/printing_view.xml b/base_report_to_printer/printing_view.xml deleted file mode 100644 index 42f4be4..0000000 --- a/base_report_to_printer/printing_view.xml +++ /dev/null @@ -1,158 +0,0 @@ - - - - - - - - printing.printer.form - printing.printer - -
- -
-

-

-
- - - - - -