[FIX] base_report_to_printer: Minor fixes

* Migrate print_document method to v8 api exclusively
* Use api.multi on _can_print_report
* Simplify printing_printer description
* Simplify noupdate declaration
This commit is contained in:
Dave Lasley
2016-07-08 11:26:10 -07:00
committed by Rod Schouteden
parent 2215316605
commit 89a6d54e26
3 changed files with 50 additions and 55 deletions

View File

@@ -1,6 +1,6 @@
<?xml version="1.0"?> <?xml version="1.0"?>
<odoo> <odoo noupdate="1">
<data noupdate="1">
<!-- printing.action --> <!-- printing.action -->
<record model="printing.action" id="printing_action_1"> <record model="printing.action" id="printing_action_1">
<field name="name">Send to Printer</field> <field name="name">Send to Printer</field>
@@ -30,5 +30,4 @@
<field eval="'()'" name="args"/> <field eval="'()'" name="args"/>
</record> </record>
</data>
</odoo> </odoo>

View File

@@ -33,7 +33,7 @@ class PrintingPrinter(models.Model):
""" """
_name = 'printing.printer' _name = 'printing.printer'
_description = 'Printing Printers' _description = 'Printer'
_order = 'name' _order = 'name'
name = fields.Char(required=True, select=True) name = fields.Char(required=True, select=True)

View File

@@ -8,41 +8,37 @@ from openerp import models, exceptions, _, api
class Report(models.Model): class Report(models.Model):
_inherit = 'report' _inherit = 'report'
@api.v7 @api.multi
def print_document(self, cr, uid, ids, report_name, html=None, def print_document(self, report_name, html=None, data=None):
data=None, context=None):
""" Print a document, do not return the document file """ """ Print a document, do not return the document file """
res = []
context = self.env.context
if context is None: if context is None:
context = self.pool['res.users'].context_get(cr, uid) context = self.env['res.users'].context_get()
local_context = context.copy() local_context = context.copy()
local_context['must_skip_send_to_printer'] = True local_context['must_skip_send_to_printer'] = True
document = self.get_pdf(cr, uid, ids, report_name, for rec_id in self.with_context(local_context):
html=html, data=data, context=local_context) document = rec_id.get_pdf(report_name, html=html, data=data)
report = self._get_report_from_name(cr, uid, report_name) report = self._get_report_from_name(report_name)
behaviour = report.behaviour()[report.id] behaviour = report.behaviour()[report.id]
printer = behaviour['printer'] printer = behaviour['printer']
if not printer: if not printer:
raise exceptions.Warning( raise exceptions.Warning(
_('No printer configured to print this report.') _('No printer configured to print this report.')
) )
return printer.with_context(context).print_document( res.append(
report, document, report.report_type) printer.print_document(report, document, report.report_type)
)
return all(res)
@api.v8 @api.multi
def print_document(self, records, report_name, html=None, data=None): def _can_print_report(self, behaviour, printer, document):
return self._model.print_document(
self._cr, self._uid,
records.ids, report_name,
html=html, data=data, context=self._context)
def _can_print_report(self, cr, uid, ids, behaviour, printer, document,
context=None):
"""Predicate that decide if report can be sent to printer """Predicate that decide if report can be sent to printer
If you want to prevent `get_pdf` to send report you can set 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 the `must_skip_send_to_printer` key to True in the context
""" """
if context is not None and context.get('must_skip_send_to_printer'): if self.env.context.get('must_skip_send_to_printer'):
return False return False
if behaviour['action'] == 'server' and printer and document: if behaviour['action'] == 'server' and printer and document:
return True return True