Hello,
I'm encountering an issue while trying to render a custom QWeb report for the sale.order model in Odoo. I created a custom report template and linked it to an action in my custom module. However, when I attempt to generate the report, I get the following error:
Error:
File "<1659>", line 1398, in template_1659
odoo.addons.base.models.ir_qweb.QWebException: Error while render the template
KeyError: 'doc'
Template: zra_smart_invoice.zra_custom_report_saleorder
Path: /t/t/t[2]
Node: <t t-set="forced_vat" t-value="doc.fiscal_position_id.foreign_vat"/>
What I Have Done:
- Custom Template: Below is a snippet from my template file:
<template id="zra_custom_report_saleorder">
<t t-call="web.external_layout">
<t t-set="doc" t-value="doc.with_context(lang=lang)"/>
<t t-set="forced_vat" t-value="doc.fiscal_position_id.foreign_vat"/>
<!-- Other content here -->
</t>
</template> - Report Action: I defined the report action as follows:
<record id="zra_action_print_custom_report" model="ir.actions.report">
<field name="name">Sale Order Report</field>
<field name="model">sale.order</field>
<field name="report_type">qweb-pdf</field>
<field name="report_name">zra_smart_invoice.zra_custom_report_saleorder</field>
<field name="binding_model_id" ref="model_sale_order"/>
</record>
3. Issue: It seems like the doc variable is not being initialized or passed to the template properly, resulting in the KeyError when accessing doc.fiscal_position_id.foreign_vat.
My Questions:
- How can I ensure that the doc variable is properly initialized in the report template?
- Is there a specific way to pass the current record to the QWeb template for reports in Odoo?
- Are there any debugging tips or best practices for handling similar issues with custom QWeb templates?
Any help or guidance would be greatly appreciated! Thank you.