mirror of
https://github.com/OCA/report-print-send.git
synced 2025-02-16 07:11:31 +02:00
[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:
committed by
Sylvain GARANCHER
parent
3dae8510f3
commit
bd6f63e969
@@ -1,34 +1,33 @@
|
||||
<?xml version="1.0"?>
|
||||
<odoo>
|
||||
<data noupdate="1">
|
||||
<!-- printing.action -->
|
||||
<record model="printing.action" id="printing_action_1">
|
||||
<field name="name">Send to Printer</field>
|
||||
<field name="type">server</field>
|
||||
</record>
|
||||
<record model="printing.action" id="printing_action_2">
|
||||
<field name="name">Send to Client</field>
|
||||
<field name="type">client</field>
|
||||
</record>
|
||||
<!-- properties -->
|
||||
<record forcecreate="True" id="property_printing_action_id" model="ir.property">
|
||||
<field name="name">property_printing_action_id</field>
|
||||
<field name="fields_id" search="[('model','=','ir.actions.report.xml'),('name','=','property_printing_action_id')]"/>
|
||||
<field name="value" eval="'printing.action,'+str(printing_action_2)"/>
|
||||
</record>
|
||||
<odoo noupdate="1">
|
||||
|
||||
<!-- printing.action -->
|
||||
<record model="printing.action" id="printing_action_1">
|
||||
<field name="name">Send to Printer</field>
|
||||
<field name="type">server</field>
|
||||
</record>
|
||||
<record model="printing.action" id="printing_action_2">
|
||||
<field name="name">Send to Client</field>
|
||||
<field name="type">client</field>
|
||||
</record>
|
||||
<!-- properties -->
|
||||
<record forcecreate="True" id="property_printing_action_id" model="ir.property">
|
||||
<field name="name">property_printing_action_id</field>
|
||||
<field name="fields_id" search="[('model','=','ir.actions.report.xml'),('name','=','property_printing_action_id')]"/>
|
||||
<field name="value" eval="'printing.action,'+str(printing_action_2)"/>
|
||||
</record>
|
||||
|
||||
<record forcecreate="True" id="ir_cron_update_printers" model="ir.cron">
|
||||
<field name="name">Update Printers Status</field>
|
||||
<field eval="True" name="active"/>
|
||||
<field name="user_id" ref="base.user_root"/>
|
||||
<field name="interval_number">1</field>
|
||||
<field name="interval_type">minutes</field>
|
||||
<field name="numbercall">-1</field>
|
||||
<field eval="False" name="doall"/>
|
||||
<field eval="'printing.printer'" name="model"/>
|
||||
<field eval="'update_printers_status'" name="function"/>
|
||||
<field eval="'()'" name="args"/>
|
||||
</record>
|
||||
<record forcecreate="True" id="ir_cron_update_printers" model="ir.cron">
|
||||
<field name="name">Update Printers Status</field>
|
||||
<field eval="True" name="active"/>
|
||||
<field name="user_id" ref="base.user_root"/>
|
||||
<field name="interval_number">1</field>
|
||||
<field name="interval_type">minutes</field>
|
||||
<field name="numbercall">-1</field>
|
||||
<field eval="False" name="doall"/>
|
||||
<field eval="'printing.printer'" name="model"/>
|
||||
<field eval="'update_printers_status'" name="function"/>
|
||||
<field eval="'()'" name="args"/>
|
||||
</record>
|
||||
|
||||
</data>
|
||||
</odoo>
|
||||
|
||||
@@ -33,7 +33,7 @@ class PrintingPrinter(models.Model):
|
||||
"""
|
||||
|
||||
_name = 'printing.printer'
|
||||
_description = 'Printing Printers'
|
||||
_description = 'Printer'
|
||||
_order = 'name'
|
||||
|
||||
name = fields.Char(required=True, select=True)
|
||||
|
||||
@@ -8,41 +8,37 @@ from openerp import models, exceptions, _, api
|
||||
class Report(models.Model):
|
||||
_inherit = 'report'
|
||||
|
||||
@api.v7
|
||||
def print_document(self, cr, uid, ids, report_name, html=None,
|
||||
data=None, context=None):
|
||||
@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.pool['res.users'].context_get(cr, uid)
|
||||
context = self.env['res.users'].context_get()
|
||||
local_context = context.copy()
|
||||
local_context['must_skip_send_to_printer'] = True
|
||||
document = self.get_pdf(cr, uid, ids, report_name,
|
||||
html=html, data=data, context=local_context)
|
||||
report = self._get_report_from_name(cr, uid, report_name)
|
||||
behaviour = report.behaviour()[report.id]
|
||||
printer = behaviour['printer']
|
||||
if not printer:
|
||||
raise exceptions.Warning(
|
||||
_('No printer configured to print this report.')
|
||||
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 printer.with_context(context).print_document(
|
||||
report, document, report.report_type)
|
||||
return all(res)
|
||||
|
||||
@api.v8
|
||||
def print_document(self, records, report_name, html=None, data=None):
|
||||
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):
|
||||
@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 context is not None and context.get('must_skip_send_to_printer'):
|
||||
if self.env.context.get('must_skip_send_to_printer'):
|
||||
return False
|
||||
if behaviour['action'] == 'server' and printer and document:
|
||||
return True
|
||||
|
||||
Reference in New Issue
Block a user