diff --git a/base_report_to_printer/__init__.py b/base_report_to_printer/__init__.py new file mode 100644 index 0000000..9f6441d --- /dev/null +++ b/base_report_to_printer/__init__.py @@ -0,0 +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 Camptocamp () +# All Rights Reserved +# +# 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_xml_action +from . import report_service +from . import users +from . import ir_report +from . import wizard diff --git a/base_report_to_printer/__openerp__.py b/base_report_to_printer/__openerp__.py index 52076ab..14b45d4 100644 --- a/base_report_to_printer/__openerp__.py +++ b/base_report_to_printer/__openerp__.py @@ -24,7 +24,11 @@ ############################################################################## { 'name': "Report to printer", +<<<<<<< HEAD 'version': '0.1', +======= + 'version': '0.1.1', +>>>>>>> Move base_report_to_printer to root from __unported__ 'category': 'Generic Modules/Base', 'description': """ Report to printer @@ -75,12 +79,20 @@ Contributors * Davide Corio * Lorenzo Battistini * Yannick Vaucher +<<<<<<< HEAD +======= +* Lionel Sausin +>>>>>>> Move base_report_to_printer to root from __unported__ """, 'author': 'Agile Business Group & Domsense, Pegueroles SCP, NaN', 'website': 'http://www.agilebg.com', 'license': 'AGPL-3', +<<<<<<< HEAD "depends" : ['base', 'base_calendar'], +======= + "depends": ['base', 'base_calendar'], +>>>>>>> Move base_report_to_printer to root from __unported__ 'data': [ 'security/security.xml', 'printing_data.xml', diff --git a/base_report_to_printer/i18n/base_report_to_printer.pot b/base_report_to_printer/i18n/base_report_to_printer.pot new file mode 100644 index 0000000..0d528d5 --- /dev/null +++ b/base_report_to_printer/i18n/base_report_to_printer.pot @@ -0,0 +1,225 @@ +# Translation of OpenERP Server. +# This file contains the translation of the following modules: +# * base_report_to_printer +# +msgid "" +msgstr "" +"Project-Id-Version: OpenERP Server 7.0\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2013-11-05 14:48+0000\n" +"PO-Revision-Date: 2013-11-05 14:48+0000\n" +"Last-Translator: <>\n" +"Language-Team: \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: \n" + +#. module: base_report_to_printer +#: selection:printing.printer,status:0 +msgid "Unavailable" +msgstr "" + +#. module: base_report_to_printer +#: view:printing.printer.update.wizard:0 +msgid "This process will create all missing printers from the current CUPS server." +msgstr "" + +#. module: base_report_to_printer +#: selection:printing.printer,status:0 +msgid "Unknown" +msgstr "" + +#. module: base_report_to_printer +#: field:printing.printer,system_name:0 +msgid "System Name" +msgstr "" + +#. module: base_report_to_printer +#: field:printing.printer,location:0 +msgid "Location" +msgstr "" + +#. module: base_report_to_printer +#: model:ir.ui.menu,name:base_report_to_printer.menu_printing_printer_form +#: view:printing.printer:0 +msgid "Printers" +msgstr "" + +#. module: base_report_to_printer +#: view:ir.actions.report.xml:0 +msgid "Print" +msgstr "" + +#. module: base_report_to_printer +#: field:res.users,printing_action:0 +msgid "Printing Action" +msgstr "" + +#. module: base_report_to_printer +#: field:printing.action,type:0 +msgid "Type" +msgstr "" + +#. module: base_report_to_printer +#: field:printing.printer,model:0 +msgid "Model" +msgstr "" + +#. module: base_report_to_printer +#: selection:printing.printer,status:0 +msgid "Available" +msgstr "" + +#. module: base_report_to_printer +#: field:ir.actions.report.xml,printing_printer_id:0 +#: model:ir.model,name:base_report_to_printer.model_printing_printer +#: field:printing.report.xml.action,printer_id:0 +msgid "Printer" +msgstr "" + +#. module: base_report_to_printer +#: model:ir.model,name:base_report_to_printer.model_res_users +msgid "Users" +msgstr "" + +#. module: base_report_to_printer +#: model:ir.model,name:base_report_to_printer.model_printing_report_xml_action +#: view:printing.report.xml.action:0 +msgid "Report Printing Actions" +msgstr "" + +#. module: base_report_to_printer +#: view:ir.actions.report.xml:0 +msgid "Specific actions per user" +msgstr "" + +#. module: base_report_to_printer +#: model:ir.model,name:base_report_to_printer.model_printing_action +msgid "Print Job Action" +msgstr "" + +#. module: base_report_to_printer +#: field:printing.report.xml.action,user_id:0 +msgid "User" +msgstr "" + +#. module: base_report_to_printer +#: field:printing.report.xml.action,report_id:0 +msgid "Report" +msgstr "" + +#. module: base_report_to_printer +#: field:printing.printer,status:0 +msgid "Status" +msgstr "" + +#. module: base_report_to_printer +#: model:ir.actions.act_window,name:base_report_to_printer.action_printing_printer_form +msgid "Show Printers" +msgstr "" + +#. module: base_report_to_printer +#: view:printing.printer.update.wizard:0 +msgid "Ok" +msgstr "" + +#. module: base_report_to_printer +#: field:printing.action,name:0 +#: field:printing.printer,name:0 +msgid "Name" +msgstr "" + +#. module: base_report_to_printer +#: view:printing.printer:0 +msgid "Set Default" +msgstr "" + +#. module: base_report_to_printer +#: field:printing.printer,default:0 +#: field:res.users,printing_printer_id:0 +msgid "Default Printer" +msgstr "" + +#. module: base_report_to_printer +#: code:addons/base_report_to_printer/printing.py:186 +#, python-format +msgid "Send to Client" +msgstr "" + +#. module: base_report_to_printer +#: field:printing.printer,uri:0 +msgid "URI" +msgstr "" + +#. module: base_report_to_printer +#: model:ir.actions.act_window,name:base_report_to_printer.action_printer_update_wizard +#: model:ir.ui.menu,name:base_report_to_printer.menu_printer_update_wizard +#: view:printing.printer.update.wizard:0 +msgid "Update Printers from CUPS" +msgstr "" + +#. module: base_report_to_printer +#: code:addons/base_report_to_printer/printing.py:185 +#, python-format +msgid "Send to Printer" +msgstr "" + +#. module: base_report_to_printer +#: model:ir.ui.menu,name:base_report_to_printer.menu_printing_main +#: selection:printing.printer,status:0 +msgid "Printing" +msgstr "" + +#. module: base_report_to_printer +#: selection:printing.printer,status:0 +msgid "Error" +msgstr "" + +#. module: base_report_to_printer +#: field:ir.actions.report.xml,property_printing_action:0 +#: field:printing.report.xml.action,action:0 +msgid "Action" +msgstr "" + +#. module: base_report_to_printer +#: view:ir.actions.report.xml:0 +msgid "Security" +msgstr "" + +#. module: base_report_to_printer +#: field:printing.printer,status_message:0 +msgid "Status Message" +msgstr "" + +#. module: base_report_to_printer +#: help:ir.actions.report.xml,printing_action_ids:0 +msgid "This field allows configuring action and printer on a per user basis" +msgstr "" + +#. module: base_report_to_printer +#: selection:printing.printer,status:0 +msgid "Server Error" +msgstr "" + +#. module: base_report_to_printer +#: field:ir.actions.report.xml,printing_action_ids:0 +msgid "Actions" +msgstr "" + +#. module: base_report_to_printer +#: view:printing.printer.update.wizard:0 +msgid "Cancel" +msgstr "" + +#. module: base_report_to_printer +#: model:res.groups,name:base_report_to_printer.res_groups_printingprintoperator0 +msgid "Printing / Print Operator" +msgstr "" + +#. module: base_report_to_printer +#: code:addons/base_report_to_printer/printing.py:187 +#, python-format +msgid "Use user's defaults" +msgstr "" + diff --git a/base_report_to_printer/i18n/fr.po b/base_report_to_printer/i18n/fr.po new file mode 100644 index 0000000..19e1039 --- /dev/null +++ b/base_report_to_printer/i18n/fr.po @@ -0,0 +1,230 @@ +# Translation of OpenERP Server. +# This file contains the translation of the following modules: +# * base_report_to_printer +# +msgid "" +msgstr "" +"Project-Id-Version: OpenERP Server 7.0\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2013-11-05 14:48+0000\n" +"PO-Revision-Date: 2014-02-25 15:06+0000\n" +"Last-Translator: Yannick Vaucher @ Camptocamp \n" +"Language-Team: \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: 8bit\n" +"X-Launchpad-Export-Date: 2014-05-06 07:28+0000\n" +"X-Generator: Launchpad (build 16996)\n" + +#. module: base_report_to_printer +#: selection:printing.printer,status:0 +msgid "Unavailable" +msgstr "Non disponible" + +#. module: base_report_to_printer +#: view:printing.printer.update.wizard:0 +msgid "" +"This process will create all missing printers from the current CUPS server." +msgstr "" +"Cette opération va créer les imprimantes manquantes à partir du server CUPS " +"courant." + +#. module: base_report_to_printer +#: selection:printing.printer,status:0 +msgid "Unknown" +msgstr "Inconnu" + +#. module: base_report_to_printer +#: field:printing.printer,system_name:0 +msgid "System Name" +msgstr "Nom sytème" + +#. module: base_report_to_printer +#: field:printing.printer,location:0 +msgid "Location" +msgstr "Emplacement" + +#. 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 +#: view:printing.printer:0 +msgid "Printers" +msgstr "Imprimantes" + +#. module: base_report_to_printer +#: view:ir.actions.report.xml:0 +msgid "Print" +msgstr "Imprimer" + +#. module: base_report_to_printer +#: field:res.users,printing_action:0 +msgid "Printing Action" +msgstr "Activité d'impression" + +#. module: base_report_to_printer +#: field:printing.action,type:0 +msgid "Type" +msgstr "Type" + +#. module: base_report_to_printer +#: field:printing.printer,model:0 +msgid "Model" +msgstr "Modèle" + +#. module: base_report_to_printer +#: selection:printing.printer,status:0 +msgid "Available" +msgstr "Disponible" + +#. module: base_report_to_printer +#: field:ir.actions.report.xml,printing_printer_id:0 +#: model:ir.model,name:base_report_to_printer.model_printing_printer +#: field:printing.report.xml.action,printer_id:0 +msgid "Printer" +msgstr "Imprimante" + +#. module: base_report_to_printer +#: model:ir.model,name:base_report_to_printer.model_res_users +msgid "Users" +msgstr "Utilisateurs" + +#. module: base_report_to_printer +#: model:ir.model,name:base_report_to_printer.model_printing_report_xml_action +#: view:printing.report.xml.action:0 +msgid "Report Printing Actions" +msgstr "Rapport d'activité d'impression" + +#. module: base_report_to_printer +#: view:ir.actions.report.xml:0 +msgid "Specific actions per user" +msgstr "Action spécifique par utilisateur" + +#. module: base_report_to_printer +#: model:ir.model,name:base_report_to_printer.model_printing_action +msgid "Print Job Action" +msgstr "Action de Job d'impression" + +#. module: base_report_to_printer +#: field:printing.report.xml.action,user_id:0 +msgid "User" +msgstr "Utilisateur" + +#. module: base_report_to_printer +#: field:printing.report.xml.action,report_id:0 +msgid "Report" +msgstr "Rapport" + +#. module: base_report_to_printer +#: field:printing.printer,status:0 +msgid "Status" +msgstr "Statut" + +#. module: base_report_to_printer +#: model:ir.actions.act_window,name:base_report_to_printer.action_printing_printer_form +msgid "Show Printers" +msgstr "Afficher les imprimantes" + +#. module: base_report_to_printer +#: view:printing.printer.update.wizard:0 +msgid "Ok" +msgstr "Ok" + +#. module: base_report_to_printer +#: field:printing.action,name:0 +#: field:printing.printer,name:0 +msgid "Name" +msgstr "Nom" + +#. module: base_report_to_printer +#: view:printing.printer:0 +msgid "Set Default" +msgstr "Définitir par défaut" + +#. module: base_report_to_printer +#: field:printing.printer,default:0 +#: field:res.users,printing_printer_id:0 +msgid "Default Printer" +msgstr "Imprimante par défaut" + +#. module: base_report_to_printer +#: code:addons/base_report_to_printer/printing.py:189 +#, python-format +msgid "Send to Client" +msgstr "Envoyer au client" + +#. module: base_report_to_printer +#: field:printing.printer,uri:0 +msgid "URI" +msgstr "URI" + +#. module: base_report_to_printer +#: model:ir.actions.act_window,name:base_report_to_printer.action_printer_update_wizard +#: model:ir.ui.menu,name:base_report_to_printer.menu_printer_update_wizard +#: view:printing.printer.update.wizard:0 +msgid "Update Printers from CUPS" +msgstr "Mettre à jour les imprimantes depuis CUPS" + +#. module: base_report_to_printer +#: code:addons/base_report_to_printer/printing.py:188 +#, python-format +msgid "Send to Printer" +msgstr "Envoyer à l'imprimante" + +#. module: base_report_to_printer +#: model:ir.ui.menu,name:base_report_to_printer.menu_printing_main +#: selection:printing.printer,status:0 +msgid "Printing" +msgstr "Impression en cours" + +#. module: base_report_to_printer +#: selection:printing.printer,status:0 +msgid "Error" +msgstr "Erreur" + +#. module: base_report_to_printer +#: field:ir.actions.report.xml,property_printing_action:0 +#: field:printing.report.xml.action,action:0 +msgid "Action" +msgstr "Action" + +#. module: base_report_to_printer +#: view:ir.actions.report.xml:0 +msgid "Security" +msgstr "Sécurité" + +#. module: base_report_to_printer +#: field:printing.printer,status_message:0 +msgid "Status Message" +msgstr "Message de Statut" + +#. module: base_report_to_printer +#: help:ir.actions.report.xml,printing_action_ids:0 +msgid "This field allows configuring action and printer on a per user basis" +msgstr "" +"Ce champs permet de configurer les action et les imprimante par utilisateur" + +#. module: base_report_to_printer +#: selection:printing.printer,status:0 +msgid "Server Error" +msgstr "Erreur serveur" + +#. module: base_report_to_printer +#: field:ir.actions.report.xml,printing_action_ids:0 +msgid "Actions" +msgstr "Actions" + +#. module: base_report_to_printer +#: view:printing.printer.update.wizard:0 +msgid "Cancel" +msgstr "Annuler" + +#. module: base_report_to_printer +#: model:res.groups,name:base_report_to_printer.res_groups_printingprintoperator0 +msgid "Printing / Print Operator" +msgstr "" + +#. module: base_report_to_printer +#: code:addons/base_report_to_printer/printing.py:190 +#, python-format +msgid "Use user's defaults" +msgstr "Utiliser la configuration par défaut de l'utilisateur" diff --git a/base_report_to_printer/i18n/it.po b/base_report_to_printer/i18n/it.po new file mode 100644 index 0000000..e6f25c6 --- /dev/null +++ b/base_report_to_printer/i18n/it.po @@ -0,0 +1,230 @@ +# Translation of OpenERP Server. +# This file contains the translation of the following modules: +# * base_report_to_printer +# +msgid "" +msgstr "" +"Project-Id-Version: OpenERP Server 7.0\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2013-11-05 14:48+0000\n" +"PO-Revision-Date: 2014-02-25 15:09+0000\n" +"Last-Translator: Yannick Vaucher @ Camptocamp \n" +"Language-Team: \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: 8bit\n" +"X-Launchpad-Export-Date: 2014-05-06 07:28+0000\n" +"X-Generator: Launchpad (build 16996)\n" + +#. module: base_report_to_printer +#: selection:printing.printer,status:0 +msgid "Unavailable" +msgstr "Non disponibile" + +#. module: base_report_to_printer +#: view:printing.printer.update.wizard:0 +msgid "" +"This process will create all missing printers from the current CUPS server." +msgstr "" +"Questo processo creerà tutte le stampante mancanti dal server CUPS corrente" + +#. module: base_report_to_printer +#: selection:printing.printer,status:0 +msgid "Unknown" +msgstr "Sconosciuto" + +#. module: base_report_to_printer +#: field:printing.printer,system_name:0 +msgid "System Name" +msgstr "Nome di sistema" + +#. module: base_report_to_printer +#: field:printing.printer,location:0 +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 +#: view:printing.printer:0 +msgid "Printers" +msgstr "Stampanti" + +#. module: base_report_to_printer +#: view:ir.actions.report.xml:0 +msgid "Print" +msgstr "" + +#. module: base_report_to_printer +#: field:res.users,printing_action:0 +msgid "Printing Action" +msgstr "Azione di stampa" + +#. module: base_report_to_printer +#: field:printing.action,type:0 +msgid "Type" +msgstr "Tipo" + +#. module: base_report_to_printer +#: field:printing.printer,model:0 +msgid "Model" +msgstr "Model" + +#. module: base_report_to_printer +#: selection:printing.printer,status:0 +msgid "Available" +msgstr "Disponibile" + +#. module: base_report_to_printer +#: field:ir.actions.report.xml,printing_printer_id:0 +#: model:ir.model,name:base_report_to_printer.model_printing_printer +#: field:printing.report.xml.action,printer_id:0 +msgid "Printer" +msgstr "Stampante" + +#. module: base_report_to_printer +#: model:ir.model,name:base_report_to_printer.model_res_users +msgid "Users" +msgstr "" + +#. module: base_report_to_printer +#: model:ir.model,name:base_report_to_printer.model_printing_report_xml_action +#: view:printing.report.xml.action:0 +msgid "Report Printing Actions" +msgstr "Azioni di stampa report" + +#. module: base_report_to_printer +#: view:ir.actions.report.xml:0 +msgid "Specific actions per user" +msgstr "" + +#. module: base_report_to_printer +#: model:ir.model,name:base_report_to_printer.model_printing_action +msgid "Print Job Action" +msgstr "Azione di stampa" + +#. module: base_report_to_printer +#: field:printing.report.xml.action,user_id:0 +msgid "User" +msgstr "Utente" + +#. module: base_report_to_printer +#: field:printing.report.xml.action,report_id:0 +msgid "Report" +msgstr "Report" + +#. module: base_report_to_printer +#: field:printing.printer,status:0 +msgid "Status" +msgstr "Stato" + +#. module: base_report_to_printer +#: model:ir.actions.act_window,name:base_report_to_printer.action_printing_printer_form +msgid "Show Printers" +msgstr "" + +#. module: base_report_to_printer +#: view:printing.printer.update.wizard:0 +msgid "Ok" +msgstr "Ok" + +#. module: base_report_to_printer +#: field:printing.action,name:0 +#: field:printing.printer,name:0 +msgid "Name" +msgstr "Nome" + +#. module: base_report_to_printer +#: view:printing.printer:0 +msgid "Set Default" +msgstr "Imposta default" + +#. module: base_report_to_printer +#: field:printing.printer,default:0 +#: field:res.users,printing_printer_id:0 +msgid "Default Printer" +msgstr "Stampante di default" + +#. module: base_report_to_printer +#: code:addons/base_report_to_printer/printing.py:189 +#, python-format +msgid "Send to Client" +msgstr "Invia al client" + +#. module: base_report_to_printer +#: field:printing.printer,uri:0 +msgid "URI" +msgstr "URI" + +#. module: base_report_to_printer +#: model:ir.actions.act_window,name:base_report_to_printer.action_printer_update_wizard +#: model:ir.ui.menu,name:base_report_to_printer.menu_printer_update_wizard +#: view:printing.printer.update.wizard:0 +msgid "Update Printers from CUPS" +msgstr "Aggiorna stampanti da CUPS" + +#. module: base_report_to_printer +#: code:addons/base_report_to_printer/printing.py:188 +#, python-format +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 +#: selection:printing.printer,status:0 +msgid "Printing" +msgstr "Stampa" + +#. module: base_report_to_printer +#: selection:printing.printer,status:0 +msgid "Error" +msgstr "Errore" + +#. module: base_report_to_printer +#: field:ir.actions.report.xml,property_printing_action:0 +#: field:printing.report.xml.action,action:0 +msgid "Action" +msgstr "Azione" + +#. module: base_report_to_printer +#: view:ir.actions.report.xml:0 +msgid "Security" +msgstr "" + +#. module: base_report_to_printer +#: field:printing.printer,status_message:0 +msgid "Status Message" +msgstr "Messaggio di stato" + +#. module: base_report_to_printer +#: help:ir.actions.report.xml,printing_action_ids:0 +msgid "This field allows configuring action and printer on a per user basis" +msgstr "" +"Questo campo permette di configurare azioni e stampanti sulla base degli " +"utenti" + +#. module: base_report_to_printer +#: selection:printing.printer,status:0 +msgid "Server Error" +msgstr "Errore server" + +#. module: base_report_to_printer +#: field:ir.actions.report.xml,printing_action_ids:0 +msgid "Actions" +msgstr "Azioni" + +#. module: base_report_to_printer +#: view:printing.printer.update.wizard:0 +msgid "Cancel" +msgstr "Annulla" + +#. module: base_report_to_printer +#: model:res.groups,name:base_report_to_printer.res_groups_printingprintoperator0 +msgid "Printing / Print Operator" +msgstr "" + +#. module: base_report_to_printer +#: code:addons/base_report_to_printer/printing.py:190 +#, python-format +msgid "Use user's defaults" +msgstr "Utilizza i default dell'utente" diff --git a/base_report_to_printer/ir_report.py b/base_report_to_printer/ir_report.py new file mode 100644 index 0000000..96cd1c1 --- /dev/null +++ b/base_report_to_printer/ir_report.py @@ -0,0 +1,132 @@ +# -*- 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 Camptocamp () +# All Rights Reserved +# +# 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 os +import base64 +from tempfile import mkstemp +import logging +import cups + +from openerp.osv import orm, fields + + +class report_xml(orm.Model): + """ + Reports + """ + + def set_print_options(self, cr, uid, report_id, format, context=None): + """ + Hook to set print options + """ + options = {} + if format == 'raw': + options['raw'] = True + return options + + def print_direct(self, cr, uid, report_id, result, format, printer, context=None): + fd, file_name = mkstemp() + try: + os.write(fd, base64.decodestring(result)) + finally: + os.close(fd) + printer_system_name = '' + if printer: + if isinstance(printer, (basestring)): + printer_system_name = printer + else: + printer_system_name = printer.system_name + connection = cups.Connection() + + options = self.set_print_options(cr, uid, report_id, format, context=context) + + connection.printFile(printer_system_name, file_name, file_name, options=options) + logger = logging.getLogger('base_report_to_printer') + logger.info("Printing job : '%s'" % file_name) + return True + + _inherit = 'ir.actions.report.xml' + _columns = { + 'property_printing_action': fields.property( + #'ir.actions.report.xml', + 'printing.action', + type='many2one', + relation='printing.action', + string='Action', + view_load=True, + method=True, + ), + 'printing_printer_id': fields.many2one('printing.printer', 'Printer'), + 'printing_action_ids': fields.one2many( + 'printing.report.xml.action', 'report_id', 'Actions', + help='This field allows configuring action and printer on a per ' + 'user basis'), + } + + def behaviour(self, cr, uid, ids, context=None): + result = {} + printer_obj = self.pool['printing.printer'] + printing_act_obj = self.pool['printing.report.xml.action'] + # Set hardcoded default action + default_action = 'client' + # Retrieve system wide printer + default_printer = printer_obj.get_default(cr, uid, context=context) + if default_printer: + default_printer = printer_obj.browse(cr, uid, default_printer, context=context) + + # Retrieve user default values + user = self.pool['res.users'].browse(cr, uid, uid, context=context) + if user.printing_action: + default_action = user.printing_action + if user.printing_printer_id: + default_printer = user.printing_printer_id + + for report in self.browse(cr, uid, ids, context): + action = default_action + printer = default_printer + + # Retrieve report default values + if (report.property_printing_action + and report.property_printing_action.type != 'user_default'): + action = report.property_printing_action.type + if report.printing_printer_id: + printer = report.printing_printer_id + + # Retrieve report-user specific values + act_ids = printing_act_obj.search( + cr, uid, + [('report_id', '=', report.id), + ('user_id', '=', uid), + ('action', '!=', 'user_default')], context=context) + if act_ids: + user_action = printing_act_obj.behaviour(cr, uid, act_ids[0], context) + action = user_action['action'] + if user_action['printer']: + printer = user_action['printer'] + + result[report.id] = { + 'action': action, + 'printer': printer, + } + return result diff --git a/base_report_to_printer/printing.py b/base_report_to_printer/printing.py new file mode 100644 index 0000000..2d0cc1b --- /dev/null +++ b/base_report_to_printer/printing.py @@ -0,0 +1,224 @@ +# -*- 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 Camptocamp () +# All Rights Reserved +# +# 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 time + +import cups +from threading import Thread +from threading import Lock + +from openerp import pooler +from openerp.osv import orm, fields +from openerp.tools.translate import _ + + +class printing_printer(orm.Model): + """ + Printers + """ + _name = "printing.printer" + _description = "Printer" + + _columns = { + 'name': fields.char( + 'Name', + size=64, + required=True, + select="1"), + 'system_name': fields.char( + 'System Name', + size=64, + required=True, + select="1"), + 'default': fields.boolean( + 'Default Printer', + readonly=True), + 'status': fields.selection( + [('unavailable', 'Unavailable'), + ('printing', 'Printing'), + ('unknown', 'Unknown'), + ('available', 'Available'), + ('error', 'Error'), + ('server-error', 'Server Error')], + 'Status', required=True, readonly=True), + 'status_message': fields.char( + 'Status Message', + size=500, + readonly=True), + 'model': fields.char( + 'Model', + size=500, + readonly=True), + 'location': fields.char( + 'Location', + size=500, + readonly=True), + 'uri': fields.char( + 'URI', + size=500, + readonly=True), + } + + _order = "name" + + _defaults = { + 'default': lambda *a: False, + 'status': lambda *a: 'unknown', + } + + def __init__(self, pool, cr): + super(printing_printer, self).__init__(pool, cr) + self.lock = Lock() + self.last_update = None + self.updating = False + + def update_printers_status(self, db_name, uid, context=None): + db, pool = pooler.get_db_and_pool(db_name) + cr = db.cursor() + + try: + connection = cups.Connection() + printers = connection.getPrinters() + server_error = False + except: + server_error = True + + mapping = { + 3: 'available', + 4: 'printing', + 5: 'error' + } + + if context is None: + context = {} + try: + # Skip update to avoid the thread being created again + ctx = context.copy() + ctx['skip_update'] = True + ids = self.search(cr, uid, [], context=ctx) + for printer in self.browse(cr, uid, ids, context=ctx): + vals = {} + if server_error: + status = 'server-error' + elif printer.system_name in printers: + info = printers[printer.system_name] + status = mapping.get(info['printer-state'], 'unknown') + vals = { + 'model': info.get('printer-make-and-model', False), + 'location': info.get('printer-location', False), + 'uri': info.get('device-uri', False), + } + else: + status = 'unavailable' + + vals['status'] = status + self.write(cr, uid, [printer.id], vals, context=context) + cr.commit() + except: + cr.rollback() + raise + finally: + cr.close() + with self.lock: + self.updating = False + self.last_update = time.time() + + def start_printer_update(self, cr, uid, context): + self.lock.acquire() + if self.updating: + self.lock.release() + return + self.updating = True + self.lock.release() + thread = Thread(target=self.update_printers_status, args=(cr.dbname, uid, context.copy())) + thread.start() + + def update(self, cr, uid, context=None): + """Update printer status if current status is more than 10s old.""" + # We won't acquire locks - we're only assigning from immutable data + if not context or 'skip_update' in context: + return True + last_update = self.last_update + now = time.time() + # Only update printer status if current status is more than 10 seconds old. + if not last_update or now - last_update > 10: + self.start_printer_update(cr, uid, context) + # Wait up to five seconds for printer status update + for _dummy in range(0, 5): + time.sleep(1) + if not self.updating: + break + return True + + def search(self, cr, uid, args, offset=0, limit=None, order=None, + context=None, count=False): + self.update(cr, uid, context) + return super(printing_printer, self + ).search(cr, uid, args, offset, + limit, order, context, count) + + def read(self, cr, uid, ids, fields=None, context=None, load='_classic_read'): + self.update(cr, uid, context) + return super(printing_printer, self + ).read(cr, uid, ids, fields, context, load) + + def browse(self, cr, uid, ids, context=None): + self.update(cr, uid, context) + return super(printing_printer, self).browse(cr, uid, ids, context) + + def set_default(self, cr, uid, ids, context): + if not ids: + return + default_ids = self.search(cr, uid, [('default', '=', True)]) + self.write(cr, uid, default_ids, {'default': False}, context) + self.write(cr, uid, ids[0], {'default': True}, context) + return True + + def get_default(self, cr, uid, context): + printer_ids = self.search(cr, uid, [('default', '=', True)]) + if printer_ids: + return printer_ids[0] + return False + + +# +# Actions +# + +def _available_action_types(self, cr, uid, context=None): + return [ + ('server', _('Send to Printer')), + ('client', _('Send to Client')), + ('user_default', _("Use user's defaults")), + ] + + +class printing_action(orm.Model): + _name = 'printing.action' + _description = 'Print Job Action' + + _columns = { + 'name': fields.char('Name', size=256, required=True), + 'type': fields.selection(_available_action_types, 'Type', required=True), + } diff --git a/base_report_to_printer/printing_data.xml b/base_report_to_printer/printing_data.xml new file mode 100644 index 0000000..8a95005 --- /dev/null +++ b/base_report_to_printer/printing_data.xml @@ -0,0 +1,20 @@ + + + + + + Send to Printer + server + + + Send to Client + client + + + + property_printing_action + + + + + diff --git a/base_report_to_printer/printing_view.xml b/base_report_to_printer/printing_view.xml new file mode 100644 index 0000000..d9c7986 --- /dev/null +++ b/base_report_to_printer/printing_view.xml @@ -0,0 +1,134 @@ + + + + + + + + printing.printer.form + printing.printer + +
+ + + + +