Do no longer returns a PDF when a report is printed

Instead, a notification is displayed to the user.
When report.get_pdf() is called on a report that must be printer,
it will print the report *and* returns the pdf, thus code that
calls directly report.get_pdf() will print the pdf on the printer
as expected.

Fixes #16
This commit is contained in:
Guewen Baconnier
2015-01-21 14:56:23 +01:00
committed by Carlos Roca
parent 74ce12bf3f
commit 79549a7bf4
8 changed files with 225 additions and 71 deletions

View File

@@ -5,7 +5,7 @@ This module allows users to send reports to a printer attached to the server.
It adds an optional behaviour on reports to send it directly to a printer.
* `Send to Client` is the default behavious providing you a downloadable PDF
* `Send to Client` is the default behaviour providing you a downloadable PDF
* `Send to Printer` prints the report on selected printer
Report behaviour is defined by settings.
@@ -23,13 +23,18 @@ After installing enable the "Printing / Print Operator" option under access
rights to give users the ability to view the print menu.
To show all available printers for your server, uses
To show all available printers for your server, use the
`Settings/Configuration/Printing/Update Printers from CUPS` wizard.
Then goto the user profile and set the users printing action and default
Then go to the user profile and set the users printing action and default
printer.
Caveat
------
The notification when a report is sent to a printer will not be
displayed for the deprecated report types (RML, Webkit, ...).
Dependencies
------------

View File

@@ -35,6 +35,7 @@
'security/security.xml',
'printing_data.xml',
'printing_view.xml',
'base_report_to_printer.xml',
'wizard/update_printers.xml',
],
'installable': True,

View File

@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<openerp>
<data>
<template id="assets_backend" name="base_report_to_printer assets" inherit_id="report.assets_backend">
<xpath expr="." position="inside">
<script type="text/javascript" src="/base_report_to_printer/static/src/js/qwebactionmanager.js"></script>
</xpath>
</template>
</data>
</openerp>

View File

@@ -1,16 +1,15 @@
# Translation of OpenERP Server.
# Translation of Odoo Server.
# This file contains the translation of the following modules:
# * base_report_to_printer
#
msgid ""
msgstr ""
"Project-Id-Version: OpenERP Server 7.0\n"
"Project-Id-Version: Odoo Server 8.0\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2013-11-05 14:48+0000\n"
"PO-Revision-Date: 2014-11-17 12:50+0000\n"
"POT-Creation-Date: 2015-01-21 14:44+0000\n"
"PO-Revision-Date: 2015-01-21 14:44+0000\n"
"Last-Translator: <>\n"
"Language-Team: \n"
"Language: \n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: \n"
@@ -38,16 +37,22 @@ msgid "Cancel"
msgstr ""
#. module: base_report_to_printer
#: field:printing.action,create_uid:0 field:printing.printer,create_uid:0
#: field:printing.printer.polling,create_uid:0
#: code:addons/base_report_to_printer/wizard/update_printers.py:50
#, python-format
msgid "Could not get the list of printers from the CUPS server (%s:%s)"
msgstr ""
#. module: base_report_to_printer
#: field:printing.action,create_uid:0
#: field:printing.printer,create_uid:0
#: field:printing.printer.update.wizard,create_uid:0
#: field:printing.report.xml.action,create_uid:0
msgid "Created by"
msgstr ""
#. module: base_report_to_printer
#: field:printing.action,create_date:0 field:printing.printer,create_date:0
#: field:printing.printer.polling,create_date:0
#: field:printing.action,create_date:0
#: field:printing.printer,create_date:0
#: field:printing.printer.update.wizard,create_date:0
#: field:printing.report.xml.action,create_date:0
msgid "Created on"
@@ -63,40 +68,55 @@ msgstr ""
msgid "Default Printer"
msgstr ""
#. module: base_report_to_printer
#. openerp-web
#: code:addons/base_report_to_printer/static/src/js/qwebactionmanager.js:27
#, python-format
msgid "Document sent to the printer "
msgstr ""
#. module: base_report_to_printer
#: selection:printing.printer,status:0
msgid "Error"
msgstr ""
#. module: base_report_to_printer
#: field:printing.action,id:0 field:printing.printer,id:0
#: field:printing.printer.polling,id:0
#. openerp-web
#: code:addons/base_report_to_printer/static/src/js/qwebactionmanager.js:30
#, python-format
msgid "Error when sending the document to the printer "
msgstr ""
#. module: base_report_to_printer
#: code:addons/base_report_to_printer/printing.py:140
#, python-format
msgid "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."
msgstr ""
#. module: base_report_to_printer
#: field:printing.action,id:0
#: field:printing.printer,id:0
#: field:printing.printer.update.wizard,id:0
#: field:printing.report.xml.action,id:0
msgid "ID"
msgstr ""
#. module: base_report_to_printer
#: field:printing.action,write_uid:0 field:printing.printer,write_uid:0
#: field:printing.printer.polling,write_uid:0
#: field:printing.action,write_uid:0
#: field:printing.printer,write_uid:0
#: field:printing.printer.update.wizard,write_uid:0
#: field:printing.report.xml.action,write_uid:0
msgid "Last Updated by"
msgstr ""
#. module: base_report_to_printer
#: field:printing.action,write_date:0 field:printing.printer,write_date:0
#: field:printing.printer.polling,write_date:0
#: field:printing.action,write_date:0
#: field:printing.printer,write_date:0
#: field:printing.printer.update.wizard,write_date:0
#: field:printing.report.xml.action,write_date:0
msgid "Last Updated on"
msgstr ""
#. module: base_report_to_printer
#: field:printing.printer.polling,last_update:0
msgid "Last update"
msgstr ""
#. module: base_report_to_printer
#: field:printing.printer,location:0
msgid "Location"
@@ -108,10 +128,17 @@ msgid "Model"
msgstr ""
#. module: base_report_to_printer
#: field:printing.action,name:0 field:printing.printer,name:0
#: field:printing.action,name:0
#: field:printing.printer,name:0
msgid "Name"
msgstr ""
#. module: base_report_to_printer
#: code:addons/base_report_to_printer/ir_report.py:114
#, python-format
msgid "No printer configured to print this report."
msgstr ""
#. module: base_report_to_printer
#: view:res.users:base_report_to_printer.view_printing_users_form
msgid "Preferences"
@@ -142,11 +169,6 @@ msgstr ""
msgid "Printers"
msgstr ""
#. module: base_report_to_printer
#: model:ir.model,name:base_report_to_printer.model_printing_printer_polling
msgid "Printers Polling"
msgstr ""
#. module: base_report_to_printer
#: model:ir.ui.menu,name:base_report_to_printer.menu_printing_main
#: selection:printing.printer,status:0
@@ -165,8 +187,12 @@ msgid "Printing action"
msgstr ""
#. 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
#: model:ir.model,name:base_report_to_printer.model_report
#: field:printing.report.xml.action,report_id:0
#, python-format
msgid "Report"
msgstr ""
@@ -229,9 +255,7 @@ msgstr ""
#. module: base_report_to_printer
#: view:printing.printer.update.wizard:base_report_to_printer.printer_update_wizard
msgid ""
"This process will create all the missing printers from the current CUPS "
"server."
msgid "This process will create all missing printers from the current CUPS server."
msgstr ""
#. module: base_report_to_printer
@@ -239,6 +263,11 @@ msgstr ""
msgid "Type"
msgstr ""
#. module: base_report_to_printer
#: field:printing.printer,uri:0
msgid "URI"
msgstr ""
#. module: base_report_to_printer
#: selection:printing.printer,status:0
msgid "Unavailable"
@@ -256,11 +285,6 @@ msgstr ""
msgid "Update Printers from CUPS"
msgstr ""
#. module: base_report_to_printer
#: field:printing.printer,uri:0
msgid "URI"
msgstr ""
#. module: base_report_to_printer
#: field:printing.report.xml.action,user_id:0
msgid "User"
@@ -270,3 +294,9 @@ msgstr ""
#: model:ir.model,name:base_report_to_printer.model_res_users
msgid "Users"
msgstr ""
#. module: base_report_to_printer
#: view:printing.printer.update.wizard:base_report_to_printer.printer_update_wizard
msgid "or"
msgstr ""

View File

@@ -6,7 +6,7 @@ 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"
"POT-Creation-Date: 2015-01-21 14:44+0000\n"
"PO-Revision-Date: 2014-02-25 15:06+0000\n"
"Last-Translator: Guewen Baconnier @ Camptocamp <Unknown>\n"
"Language-Team: \n"
@@ -38,9 +38,14 @@ msgstr "Disponible"
msgid "Cancel"
msgstr "Annuler"
#. module: base_report_to_printer
#: code:addons/base_report_to_printer/wizard/update_printers.py:50
#, python-format
msgid "Could not get the list of printers from the CUPS server (%s:%s)"
msgstr "Impossible d'obtenir la liste des imprimantes depuis le serveur CUPS (%s:%s)"
#. module: base_report_to_printer
#: field:printing.action,create_uid:0 field:printing.printer,create_uid:0
#: field:printing.printer.polling,create_uid:0
#: field:printing.printer.update.wizard,create_uid:0
#: field:printing.report.xml.action,create_uid:0
msgid "Created by"
@@ -48,7 +53,6 @@ msgstr ""
#. module: base_report_to_printer
#: field:printing.action,create_date:0 field:printing.printer,create_date:0
#: field:printing.printer.polling,create_date:0
#: field:printing.printer.update.wizard,create_date:0
#: field:printing.report.xml.action,create_date:0
msgid "Created on"
@@ -64,14 +68,36 @@ msgstr "Par défaut"
msgid "Default Printer"
msgstr "Imprimante par défaut"
#. module: base_report_to_printer
#. openerp-web
#: code:addons/base_report_to_printer/static/src/js/qwebactionmanager.js:27
#, python-format
msgid "Document sent to the printer "
msgstr "Document envoyé à l'imprimante "
#. module: base_report_to_printer
#: selection:printing.printer,status:0
msgid "Error"
msgstr "Erreur"
#. module: base_report_to_printer
#. openerp-web
#: code:addons/base_report_to_printer/static/src/js/qwebactionmanager.js:30
#, python-format
msgid "Error when sending the document to the printer "
msgstr "Erreur lors de l'envoi du document à l'imprimante "
#. module: base_report_to_printer
#: code:addons/base_report_to_printer/printing.py:140
#, python-format
msgid ""
"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."
msgstr "La connexion au serveur CUPS %s:%s a échoué. Veuillez contrôler que le "
"serveur soit démarré et qu'il soit atteignable depuis le serveur Odoo. "
#. module: base_report_to_printer
#: field:printing.action,id:0 field:printing.printer,id:0
#: field:printing.printer.polling,id:0
#: field:printing.printer.update.wizard,id:0
#: field:printing.report.xml.action,id:0
msgid "ID"
@@ -79,7 +105,6 @@ msgstr ""
#. module: base_report_to_printer
#: field:printing.action,write_uid:0 field:printing.printer,write_uid:0
#: field:printing.printer.polling,write_uid:0
#: field:printing.printer.update.wizard,write_uid:0
#: field:printing.report.xml.action,write_uid:0
msgid "Last Updated by"
@@ -87,17 +112,11 @@ msgstr ""
#. module: base_report_to_printer
#: field:printing.action,write_date:0 field:printing.printer,write_date:0
#: field:printing.printer.polling,write_date:0
#: field:printing.printer.update.wizard,write_date:0
#: field:printing.report.xml.action,write_date:0
msgid "Last Updated on"
msgstr ""
#. module: base_report_to_printer
#: field:printing.printer.polling,last_update:0
msgid "Last update"
msgstr ""
#. module: base_report_to_printer
#: field:printing.printer,location:0
msgid "Location"
@@ -113,6 +132,12 @@ msgstr "Modèle"
msgid "Name"
msgstr "Nom"
#. module: base_report_to_printer
#: code:addons/base_report_to_printer/ir_report.py:114
#, python-format
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
msgid "Preferences"
@@ -143,11 +168,6 @@ msgstr "Imprimante"
msgid "Printers"
msgstr "Imprimantes"
#. module: base_report_to_printer
#: model:ir.model,name:base_report_to_printer.model_printing_printer_polling
msgid "Printers Polling"
msgstr "Recherche d'imprimantes"
#. module: base_report_to_printer
#: model:ir.ui.menu,name:base_report_to_printer.menu_printing_main
#: selection:printing.printer,status:0
@@ -166,8 +186,12 @@ msgid "Printing action"
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
#: model:ir.model,name:base_report_to_printer.model_report
#: field:printing.report.xml.action,report_id:0
#, python-format
msgid "Report"
msgstr "Rapport"
@@ -232,8 +256,7 @@ msgstr ""
#. module: base_report_to_printer
#: view:printing.printer.update.wizard:base_report_to_printer.printer_update_wizard
msgid ""
"This process will create all the missing printers from the current CUPS "
"server."
"This process will create all missing printers from the current CUPS server."
msgstr ""
"Cette opération va créer les imprimantes manquantes à partir du serveur CUPS "
"courant."
@@ -243,6 +266,11 @@ msgstr ""
msgid "Type"
msgstr "Type"
#. module: base_report_to_printer
#: field:printing.printer,uri:0
msgid "URI"
msgstr ""
#. module: base_report_to_printer
#: selection:printing.printer,status:0
msgid "Unavailable"
@@ -260,11 +288,6 @@ msgstr "Inconnu"
msgid "Update Printers from CUPS"
msgstr "Mettre à jour les imprimantes depuis CUPS"
#. module: base_report_to_printer
#: field:printing.printer,uri:0
msgid "URI"
msgstr ""
#. module: base_report_to_printer
#: field:printing.report.xml.action,user_id:0
msgid "User"
@@ -274,3 +297,8 @@ msgstr "Utilisateur"
#: model:ir.model,name:base_report_to_printer.model_res_users
msgid "Users"
msgstr "Utilisateurs"
#. module: base_report_to_printer
#: view:printing.printer.update.wizard:base_report_to_printer.printer_update_wizard
msgid "or"
msgstr "ou"

View File

@@ -52,6 +52,23 @@ class ReportXml(models.Model):
'user basis'
)
@api.model
def print_action_for_report_name(self, report_name):
""" Returns if the action is a direct print or pdf
Called from js
"""
report_obj = self.env['report']
report = report_obj._get_report_from_name(report_name)
if not report:
return {}
result = report.behaviour()[report.id]
serializable_result = {
'action': result['action'],
'printer_name': result['printer'].name,
}
return serializable_result
@api.multi
def behaviour(self):
result = {}

View File

@@ -19,21 +19,40 @@
#
##############################################################################
from openerp import models
from openerp import models, exceptions, _
class Report(models.Model):
_inherit = 'report'
def get_pdf(self, cr, uid, ids, report_name, html=None,
def print_document(self, cr, uid, ids, report_name, html=None,
data=None, context=None):
result = super(Report, self).get_pdf(cr, uid, ids, report_name,
""" Print a document, do not return the document file """
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)
data = report.behaviour()[report.id]
action = data['action']
printer = data['printer']
if action != 'client' and result:
printer.print_document(report, result, report.report_type)
return result
behaviour = report.behaviour()[report.id]
printer = behaviour['printer']
if not printer:
raise exceptions.Warning(
_('No printer configured to print this report.')
)
return printer.print_document(report, document, report.report_type)
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']
if behaviour['action'] == 'server' and printer and document:
printer.print_document(report, document, report.report_type)
return document

View File

@@ -0,0 +1,43 @@
openerp.base_report_to_printer = function(instance) {
instance.web.ActionManager.include({
ir_actions_report_xml: function(action, options) {
instance.web.blockUI();
action = _.clone(action);
var _t = instance.web._t;
var self = this;
var _super = this._super;
if ('report_type' in action && action.report_type === 'qweb-pdf') {
new instance.web.Model('ir.actions.report.xml')
.call('print_action_for_report_name', [action.report_name])
.then(function(print_action){
if (print_action && print_action['action'] === 'server') {
instance.web.unblockUI();
new instance.web.Model('report')
.call('print_document',
[action.context.active_ids,
action.report_name,
],
{data: action.data || {},
context: action.context || {},
})
.then(function(result){
self.do_notify(_t('Report'),
_t('Document sent to the printer ') + print_action.printer_name);
}).fail(function() {
self.do_notify(_t('Report'),
_t('Error when sending the document to the printer ') + print_action.printer_name);
});
} else {
return _super.apply(self, [action, options]);
}
});
} else {
return _super.apply(self, [action, options]);
}
}
});
};