Skip to Content
Menu
This question has been flagged
5 Replies
41257 Views

Hello,

I am trying to display form fields in report but following error occur.

Error:​

odoo.addons.base.ir.ir_qweb.qweb.QWebException: 'NoneType' object is not subscriptable
Traceback (most recent call last):
File "/usr/local/sampada/eclipse-workspace/odoo11/odoo/addons/base/ir/ir_qweb/qweb.py", line 343, in _compiled_fn
return compiled(self, append, new, options, log)
File "<template>", line 1, in template_1018_120
File "<template>", line 2, in body_call_content_119
File "<template>", line 3, in body_call_content_118
TypeError: 'NoneType' object is not subscriptable

Error to render compiling AST
TypeError: 'NoneType' object is not subscriptable
Template: 1018
Path: /templates/t/t/t/div/t[1]
Node: <t t-if="data['form_date']"><span t-esc="data['from_date']">From Date:</span></t>

.py file

from odoo import models, fields, api

class DataForReport(models.AbstractModel):

_name = 'report.survey_client.pl_report_template'#for report name must be 'report.module_name.template_id_of_report'

@api.multi
def get_Form_data(self, docid, data):
model_data = data['form']
return self.report_calculations(model_data)


@api.model
def report_calculations(self,data):

from_date = data['from_date']
to_date = data['to_date']
product_id = data['product_id']


template file:

<?xml version="1.0" encoding="utf-8"?>
<odoo>
<data>
<template id="pl_report_template_struct">
<t t-call="web.html_container">
<t t-call="web.external_layout">
<div class="page">

<center><span><strong><h2>Product Profit Loss</h2></strong></span></center>

<t t-if="data['form_date']"><span t-esc="data['from_date']">From Date:</span></t>
<t t-if="data['to_date']"><span t-esc="data['from_date']">To Date:</span></t>
<t t-if="data['product_id']"><span t-esc="data['product_id']">Product:</span></t>

</div>
</t>
</t>
</template>
</data>
</odoo>


Report File

<?xml version="1.0" encoding="utf-8"?>
<odoo>
<data>
<report
id="pl_report_def"
string="Product Profit Loss"
model="form.data"
report_type="qweb-html"
file="survey_client.pl_report_template_struct"
name="survey_client.pl_report_template_struct"
/>

</data>
</odoo>

I have try all solution from internet but same error will occur.any  Please help.


Avatar
Discard

Better to the report development from odoo documentation. https://www.odoo.com/documentation/10.0/reference/reports.html

Thanks @Hilar AK  for your help it's working.

On 13/08/19 8:00 PM, Hilar AK wrote:

*learn


Sent by Odoo S.A. using Odoo.

Best Answer

Visit to know more details for above topic:  https://360digitmg.com/python-typeerror-nonetype-object-is-not-subsriptable

Avatar
Discard
Best Answer

In general, the error means that you attempted to index an object that doesn't have that functionality. You are trying to subscript an object which you think is a list or dict, but actually is None. NoneType is the type of the None object which represents a lack of value, for example, a function that does not explicitly return a value will return None. 'NoneType' object is not subscriptable is the one thrown by python when you use the square bracket notation object[key] where an object doesn't define the __getitem__ method .  

More: http://net-informations.com/python/err/nonetype.htm





Avatar
Discard