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/data/printing_data.xml b/base_report_to_printer/data/printing_data.xml new file mode 100644 index 0000000..e6ded50 --- /dev/null +++ b/base_report_to_printer/data/printing_data.xml @@ -0,0 +1,33 @@ + + + + + + Send to Printer + server + + + Send to Client + client + + + + property_printing_action_id + + + + + + Update Printers Status + + + 1 + minutes + -1 + + + + + + + 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 74% rename from base_report_to_printer/printing.py rename to base_report_to_printer/models/printing_printer.py index b4dd364..9a6b8fb 100644 --- a/base_report_to_printer/printing.py +++ b/base_report_to_printer/models/printing_printer.py @@ -1,40 +1,29 @@ # -*- 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 +from openerp import models, fields, api, _ +from openerp.exceptions import UserError +from openerp.tools.config import config + + +_logger = logging.getLogger(__name__) + + 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 CUPS_HOST = config.get('cups_host', 'localhost') CUPS_PORT = int(config.get('cups_port', 631)) # config.get returns a string @@ -67,8 +56,10 @@ class PrintingPrinter(models.Model): uri = fields.Char(string='URI', readonly=True) @api.model - def update_printers_status(self): - printer_recs = self.search([]) + def update_printers_status(self, domain=None): + if domain is None: + domain = [] + printer_recs = self.search(domain) try: connection = cups.Connection(CUPS_HOST, CUPS_PORT) printers = connection.getPrinters() @@ -144,7 +135,7 @@ class PrintingPrinter(models.Model): connection = cups.Connection(CUPS_HOST, CUPS_PORT) _logger.debug('Connection to CUPS successfull') except: - raise Warning( + raise UserError( _("Failed to connect to the CUPS server on %s:%s. " "Check that the CUPS server is running and that " "you can reach it from the Odoo server.") @@ -175,22 +166,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/models/report.py b/base_report_to_printer/models/report.py new file mode 100644 index 0000000..3ff064a --- /dev/null +++ b/base_report_to_printer/models/report.py @@ -0,0 +1,72 @@ +# -*- coding: utf-8 -*- +# Copyright (c) 2014 Camptocamp SA +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from openerp import models, exceptions, _, api + + +class Report(models.Model): + _inherit = 'report' + + @api.multi + def print_document(self, report_name, html=None, data=None): + """ Print a document, do not return the document file """ + res = [] + context = self.env.context + if context is None: + context = self.env['res.users'].context_get() + local_context = context.copy() + local_context['must_skip_send_to_printer'] = True + for rec_id in self.with_context(local_context): + document = rec_id.get_pdf(report_name, html=html, data=data) + report = self._get_report_from_name(report_name) + behaviour = report.behaviour()[report.id] + printer = behaviour['printer'] + if not printer: + raise exceptions.Warning( + _('No printer configured to print this report.') + ) + res.append( + printer.print_document(report, document, report.report_type) + ) + return all(res) + + @api.multi + def _can_print_report(self, behaviour, printer, document): + """Predicate that decide if report can be sent to printer + + If you want to prevent `get_pdf` to send report you can set + the `must_skip_send_to_printer` key to True in the context + """ + if self.env.context.get('must_skip_send_to_printer'): + return False + if behaviour['action'] == 'server' and printer and document: + return True + return False + + @api.v7 + def get_pdf(self, cr, uid, ids, report_name, html=None, + data=None, context=None): + """ Generate a PDF and returns it. + + If the action configured on the report is server, it prints the + generated document as well. + """ + document = super(Report, self).get_pdf(cr, uid, ids, report_name, + html=html, data=data, + context=context) + report = self._get_report_from_name(cr, uid, report_name) + behaviour = report.behaviour()[report.id] + printer = behaviour['printer'] + can_print_report = self._can_print_report(cr, uid, ids, + behaviour, printer, document, + context=context) + if can_print_report: + printer.print_document(report, document, report.report_type) + return document + + @api.v8 + def get_pdf(self, records, report_name, html=None, data=None): + return self._model.get_pdf(self._cr, self._uid, + records.ids, report_name, + html=html, data=data, context=self._context) 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..1787e81 --- /dev/null +++ b/base_report_to_printer/models/res_users.py @@ -0,0 +1,31 @@ +# -*- 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 _available_action_types(self): + return _available_action_types(self) + + @api.model + def _user_available_action_types(self): + return [(code, string) for code, string + in self._available_action_types() + if code != 'user_default'] diff --git a/base_report_to_printer/printing_data.xml b/base_report_to_printer/printing_data.xml deleted file mode 100644 index 5998d14..0000000 --- a/base_report_to_printer/printing_data.xml +++ /dev/null @@ -1,34 +0,0 @@ - - - - - - Send to Printer - server - - - Send to Client - client - - - - property_printing_action - - - - - - Update Printers Status - - - 1 - minutes - -1 - - - - - - - - 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 - -
- -
-

-

-
- - - - - -