[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 Sylvain GARANCHER
parent 3dae8510f3
commit bd6f63e969
3 changed files with 50 additions and 55 deletions

View File

@@ -1,34 +1,33 @@
<?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>
<field name="type">server</field> <field name="type">server</field>
</record> </record>
<record model="printing.action" id="printing_action_2"> <record model="printing.action" id="printing_action_2">
<field name="name">Send to Client</field> <field name="name">Send to Client</field>
<field name="type">client</field> <field name="type">client</field>
</record> </record>
<!-- properties --> <!-- properties -->
<record forcecreate="True" id="property_printing_action_id" model="ir.property"> <record forcecreate="True" id="property_printing_action_id" model="ir.property">
<field name="name">property_printing_action_id</field> <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="fields_id" search="[('model','=','ir.actions.report.xml'),('name','=','property_printing_action_id')]"/>
<field name="value" eval="'printing.action,'+str(printing_action_2)"/> <field name="value" eval="'printing.action,'+str(printing_action_2)"/>
</record> </record>
<record forcecreate="True" id="ir_cron_update_printers" model="ir.cron"> <record forcecreate="True" id="ir_cron_update_printers" model="ir.cron">
<field name="name">Update Printers Status</field> <field name="name">Update Printers Status</field>
<field eval="True" name="active"/> <field eval="True" name="active"/>
<field name="user_id" ref="base.user_root"/> <field name="user_id" ref="base.user_root"/>
<field name="interval_number">1</field> <field name="interval_number">1</field>
<field name="interval_type">minutes</field> <field name="interval_type">minutes</field>
<field name="numbercall">-1</field> <field name="numbercall">-1</field>
<field eval="False" name="doall"/> <field eval="False" name="doall"/>
<field eval="'printing.printer'" name="model"/> <field eval="'printing.printer'" name="model"/>
<field eval="'update_printers_status'" name="function"/> <field eval="'update_printers_status'" name="function"/>
<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.')
)
res.append(
printer.print_document(report, document, report.report_type)
) )
return printer.with_context(context).print_document( return all(res)
report, document, report.report_type)
@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