Reputation: 13
I'm trying to use report parser, but it always pop an error
ValueError The _name attribute report.test_module.report_test_doc is not valid
I searched that your report name is use for the parser _template and _name in order to be used by Odoo. It doesn't show the error if I remove the test_module, but the hello() is not callable.
report.xml
<?xml version="1.0" encoding="utf-8"?>
<openerp>
<data>
<report
id="eport_monthly_pdc"
string="Monthly report of PDC"
model="account.voucher"
report_type="qweb-pdf"
name="test_module.report_test_doc"
file="test_module.report_test_doc"
/>
</data>
</openerp>
report_parser.py
from openerp import api, models
from openerp.report import report_sxw
import time
class report_parser(report_sxw.rml_parse):
def __init__(self, cr, uid, name, context):
super(report_parser, self).__init__(cr, uid, name, context=context)
self.localcontext.update({
'time': time,
'hello_world': self._hello,
})
def _hello(self):
return "Hello World!"
class report_parser_test(models.AbstractModel):
_name = 'report.test_module.report_test_doc'
_inherit = 'report.abstract_report'
_template = 'test_module.report_test_doc'
_wrapped_report_class = report_parser
report_test_doc.xml
<openerp>
<data>
<template id="report_test_doc">
<t t-call="report.html_container">
<t t-foreach="docs" t-as="o">
<t t-call="test_module.report_test_layout">
<div class="page">
<div class="text-center">
<span t-esc="hello_world()"/>
</div>
</div>
</t>
</t>
</t>
</template>
</data>
</openerp>
Upvotes: 0
Views: 3599
Reputation: 1
Module name (i.e directory) in UPPERCASE raise this error in Odoo11. Example:
_name = 'report.Name_Module.report_name'
Upvotes: 0
Reputation: 2892
In Your case basically,
Qweb report is mainly used to call using models.AbstractModel
model of your every class entry for each report type and inherit it in your class for parser class entry.
class report_parser_test(models.AbstractModel):
_name = 'report.test_module.report_test_doc'
_inherit = 'report.abstract_report'
_template = 'test_module.report_test_doc'
_wrapped_report_class = report_parser
Attributes of Each Qweb Report parser class Entry :
_name attribute which is always start with report.<your report template id>
_inherit = 'report.abstract_report' It's default inheritance of report.abstract_report which is located in report module (Base class of Every Report)
_template = 'test_module.report_test_doc'
Which is basically <your module name>.<your report template id>
_wrapped_report_class = report_parser
Which is part of the entry of your parser class which is contain your report logic and computed logic for your report.
**And another things about to call your hello() call :
In your case You function is declare and added your report parser class is good but we must need to call that function on Qweb Template file
likes..
<span t-esc="hello()"/>
Then and then you will calling that function from your end.
I hope my answer may helpful for you :)
Upvotes: 2