So I wrote a custom module that defines a custom report:
<odoo>
<report
id="report_product_test_zebra"
string="Product zebra test"
model="product.template"
report_type="qweb-pdf"
name="test_wizard.report_product_test_zebra"
file="report_producttestzebra"
print_report_name="TestZebra print"
/>
</odoo>
<odoo>
<template id="report_producttestzebra">
<t t-foreach="docs" t-as="template">
<t t-foreach="template.product_variant_ids" t-as="product">
<div class="page" style="page-break-after: always; margin-left:4px">
<div style="text-align: center">
<strong style="font-size:14px;" t-field="product.name"/>
<t t-if="product.barcode">
<img alt="Barcode" t-att-src="'/report/barcode/?type=%s&value=%s&width=%s&height=%s' % ('Code128', product.barcode, 700, 200)" style="width:100%;height:20mm;"/>
<span style="font-size: 14px;" t-field="product.barcode"/>
</t>
</div>
</div>
</t>
</t>
</template>
</odoo>
Then I defined a model for a wizard:
class PrintMultipleWizard(models.TransientModel):
_name = 'print.multiple_wizard'
_description: 'Multiple labels'
prod_ids = fields.Many2many('product.template', string='products')
#aantal = fields.Int(help="aantal dat moet afgedrukt worden")
@api.model
def default_get(self, field_names):
defaults = super(PrintMultipleWizard, self).default_get(field_names)
defaults['prod_ids'] = self.env.context['active_ids']
prod_ids = self.env.context.get('active_ids', [])
return defaults
@api.multi
def do_mass_print(self):
self.ensure_one()
actieve_ids = self._context.get('active_ids')
products_to_print = self.env['product.template'].browse(actieve_ids)
datas = {'ids': self.env.context.get('active_ids', [])}
res = self.read(['prod_ids'])
datas['form'] = res
return self.env.ref('test_wizard.report_product_test_zebra').report_action([], data=datas)
I also defined the wizard itself:
<odoo>
<record id="TestPrintModel" model="ir.ui.view">
<field name="name">Test print aantal labels</field>
<field name="model">print.multiple_wizard</field>
<field name="arch" type="xml">
<form>
<field name="prod_ids">
<tree>
<field name="name"/>
</tree>
</field>
<footer>
<button type="object" name="do_mass_print"
string="Do it" class="oe_highlight"
/>
<button special="cancel" string="Cancel"/>
</footer>
</form>
</field>
</record>
<!--More button Action-->
<act_window id="action_test_print_multiple"
name="print multiple labels"
src_model="product.template"
res_model="print.multiple_wizard"
view_mode="form"
target="new"
multi="True"
/>
</odoo>
Now, after I press the button to print, I get the following error:
Odoo Server Error
Traceback (most recent call last): File "/opt/odoo/odoo/odoo/addons/base/models/qweb.py", line 346, in _compiled_fn return compiled(self, append, new, options, log) File "<template>", line 1, in template_portal_frontend_layout_302 File "<template>", line 2, in body_call_content_301 AttributeError: 'NoneType' object has no attribute 'id' During handling of the above exception, another exception occurred: Traceback (most recent call last): File "/opt/odoo/odoo/addons/web/controllers/main.py", line 1675, in report_download response = self.report_routes(reportname, converter=converter, **dict(data)) File "/opt/odoo/odoo/odoo/http.py", line 517, in response_wrap response = f(*args, **kw) File "/opt/odoo/odoo/addons/web/controllers/main.py", line 1612, in report_routes pdf = report.with_context(context).render_qweb_pdf(docids, data=data)[0] File "/opt/odoo/odoo/custom_addons/base_report_to_printer/models/ir_actions_report.py", line 146, in render_qweb_pdf res_ids=res_ids, data=data) File "/opt/odoo/odoo/odoo/addons/base/models/ir_actions_report.py", line 682, in render_qweb_pdf html = self.with_context(context).render_qweb_html(res_ids, data=data)[0] File "/opt/odoo/odoo/enterprise/web_studio/models/ir_actions_report.py", line 15, in render_qweb_html return super(IrActionsReport, self).render_qweb_html(docids, data) File "/opt/odoo/odoo/odoo/addons/base/models/ir_actions_report.py", line 722, in render_qweb_html return self.render_template(self.report_name, data), 'html' File "/opt/odoo/odoo/odoo/addons/base/models/ir_actions_report.py", line 505, in render_template return view_obj.render_template(template, values) File "/opt/odoo/odoo/odoo/addons/base/models/ir_ui_view.py", line 1284, in render_template return self.browse(self.get_view_id(template)).render(values, engine) File "/opt/odoo/odoo/addons/website/models/ir_ui_view.py", line 318, in render return super(View, self).render(values, engine=engine, minimal_qcontext=minimal_qcontext) File "/opt/odoo/odoo/addons/web_editor/models/ir_ui_view.py", line 27, in render return super(IrUiView, self).render(values=values, engine=engine, minimal_qcontext=minimal_qcontext) File "/opt/odoo/odoo/odoo/addons/base/models/ir_ui_view.py", line 1293, in render return self.env[engine].render(self.id, qcontext) File "/opt/odoo/odoo/enterprise/web_studio/models/ir_qweb.py", line 43, in render return super(IrQWeb, self).render(template, values=values, **options) File "/opt/odoo/odoo/odoo/addons/base/models/ir_qweb.py", line 59, in render result = super(IrQWeb, self).render(id_or_xml_id, values=values, **context) File "/opt/odoo/odoo/odoo/addons/base/models/qweb.py", line 274, in render self.compile(template, options)(self, body.append, values or {}) File "/opt/odoo/odoo/odoo/addons/base/models/qweb.py", line 348, in _compiled_fn raise e File "/opt/odoo/odoo/odoo/addons/base/models/qweb.py", line 346, in _compiled_fn return compiled(self, append, new, options, log) File "<template>", line 1, in template_772_254 File "/opt/odoo/odoo/odoo/addons/base/models/qweb.py", line 353, in _compiled_fn raise QWebException("Error to render compiling AST", e, path, node and etree.tostring(node[0], encoding='unicode'), name) odoo.addons.base.models.qweb.QWebException: 'NoneType' object has no attribute 'id' Traceback (most recent call last): File "/opt/odoo/odoo/odoo/addons/base/models/qweb.py", line 346, in _compiled_fn return compiled(self, append, new, options, log) File "<template>", line 1, in template_portal_frontend_layout_302 File "<template>", line 2, in body_call_content_301 AttributeError: 'NoneType' object has no attribute 'id' Error to render compiling AST AttributeError: 'NoneType' object has no attribute 'id' Template: portal.frontend_layout Path: /templates/t/t/t[4] Node: <t t-set="x_icon" t-value="'/web/image/website/%s/favicon/' % website.id"/>
Anybody have any idea what exactly is going wrong here? Thanks in advance!