Reputation: 441
I am trying to create a custom report under Odoo 12 to be added to the print option under Orders View. So far, so good, I include the XML in the manifest and create the XML under the sale_management/report folder. I update the module upon editing and it is compiled right. Nevertheless, once I hit the print button, I get this error:
Error:
Odoo Server Error
Traceback (most recent call last):
File "/usr/lib/python3/dist-packages/odoo/addons/base/models/qweb.py", line 347, in _compiled_fn
return compiled(self, append, new, options, log)
File "<template>", line 1, in template_829_149
File "<template>", line 2, in body_call_content_148
AttributeError: 'NoneType' object has no attribute 'with_context'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/usr/lib/python3/dist-packages/odoo/addons/web/controllers/main.py", line 1671, in report_download
response = self.report_routes(reportname, docids=docids, converter=converter)
File "/usr/lib/python3/dist-packages/odoo/http.py", line 519, in response_wrap
response = f(*args, **kw)
File "/usr/lib/python3/dist-packages/odoo/addons/web/controllers/main.py", line 1612, in report_routes
pdf = report.with_context(context).render_qweb_pdf(docids, data=data)[0]
File "/usr/lib/python3/dist-packages/odoo/addons/base/models/ir_actions_report.py", line 712, in render_qweb_pdf
html = self.with_context(context).render_qweb_html(res_ids, data=data)[0]
File "/usr/lib/python3/dist-packages/odoo/addons/base/models/ir_actions_report.py", line 752, in render_qweb_html
return self.render_template(self.report_name, data), 'html'
File "/usr/lib/python3/dist-packages/odoo/addons/base/models/ir_actions_report.py", line 534, in render_template
return view_obj.render_template(template, values)
File "/usr/lib/python3/dist-packages/odoo/addons/base/models/ir_ui_view.py", line 1304, in render_template
return self.browse(self.get_view_id(template)).render(values, engine)
File "/usr/lib/python3/dist-packages/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 "/usr/lib/python3/dist-packages/odoo/addons/base/models/ir_ui_view.py", line 1313, in render
return self.env[engine].render(self.id, qcontext)
File "/usr/lib/python3/dist-packages/odoo/addons/base/models/ir_qweb.py", line 59, in render
result = super(IrQWeb, self).render(id_or_xml_id, values=values, **context)
File "/usr/lib/python3/dist-packages/odoo/addons/base/models/qweb.py", line 275, in render
self.compile(template, options)(self, body.append, values or {})
File "/usr/lib/python3/dist-packages/odoo/addons/base/models/qweb.py", line 354, 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 'with_context'
Traceback (most recent call last):
File "/usr/lib/python3/dist-packages/odoo/addons/base/models/qweb.py", line 347, in _compiled_fn
return compiled(self, append, new, options, log)
File "<template>", line 1, in template_829_149
File "<template>", line 2, in body_call_content_148
AttributeError: 'NoneType' object has no attribute 'with_context'
Error to render compiling AST
AttributeError: 'NoneType' object has no attribute 'with_context'
Template: 829
Path: /templates/t/t/t[1]
Node: <t t-set="doc" t-value="doc.with_context(lang=doc.partner_id.lang)"/>
For testing purposes, the XML is almost verbatim of the already included template in the same directory named sale_report_templates.xml and my whole file is:
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<report
id="albaran_sin_valorar"
string="Documento sin valorar"
model="sale.order"
report_type="qweb-pdf"
name="sale_management.report_albaran_sin_valorar"
/>
<template id="report_albaran_sin_valorar" inherit_id="sale.report_saleorder_document">
<xpath expr="//div[hasclass('page')]/p[@id='fiscal_position_remark']" position="after">
<div t-if="doc.sale_order_option_ids and doc.state in ['draft', 'sent']">
<t t-set="has_option_discount" t-value="any(doc.sale_order_option_ids.filtered(lambda o: o.discount$
<h4>
<span>Optional Products</span>
</h4>
<table class="table table-sm">
<thead>
<tr>
<th class="text-left">Description</th>
<th t-if="has_option_discount" groups="sale.group_discount_per_so_line" class="text-lef$
<th class="text-right">Unit Price</th>
</tr>
</thead>
<tbody class="sale_tbody">
<tr t-foreach="doc.sale_order_option_ids" t-as="option">
<td>
<span t-field="option.name"/>
</td>
<td t-if="has_option_discount" groups="sale.group_discount_per_so_line">
...
</template>
</odoo>
My questions are: - Of course, what is the problem. - What are the inners of Odoo involved in the problem so I can fully understand it
Thanks in advance Jose
Upvotes: 3
Views: 962
Reputation: 2444
You are trying to inheriting
Default Odoo Sale Report but your report action
is calling is different. On your customized report that object it not detaching['sale.order'] So instead of an object, you got none.
Simply go through the link with how to work with report inheritance Sale-inheriting-and-modifying-qweb-reports/.
On XML File for Sale Report Customisation,
<template id="report_saleorder_document_customise" inherit_id="sale.report_saleorder_document">
<!-- Give the xpath according to your requirement -->
<xpath expr="//table[hasclass('o_main_table')]//tr/th[@name='th_subtotal']" position="before">
<!-- Add your customise with give the xpath -->
</xpath>
</template>
Add the Xml file in __manifest__
file.
Thanks
Upvotes: 4