Python Odoo 11 Qweb自定义报告:呈现编译AST类型时出错错误:';非类型';对象不可调用
我第一次在这里发表一些东西,希望它能起作用 我试图在Odoo11中创建一个自定义报告,在我创建的自定义模块中,我跟踪了我可以收集的数据,但我无法克服以下问题Python Odoo 11 Qweb自定义报告:呈现编译AST类型时出错错误:';非类型';对象不可调用,python,odoo-11,qweb,Python,Odoo 11,Qweb,我第一次在这里发表一些东西,希望它能起作用 我试图在Odoo11中创建一个自定义报告,在我创建的自定义模块中,我跟踪了我可以收集的数据,但我无法克服以下问题 因此,我创建了如下报告: 我的错误是: 然而,我仍然有相同的错误信息。有什么想法吗 ===编辑2==== 因此,现在我根据@WaKo建议用get\u report\u values而不是render\u html更改了我的类,所以看起来像这样: 因此,现在我将xml更改如下: > <?xml version="1.0"?
- 因此,我创建了如下报告:
- 我的错误是:
get\u report\u values
而不是render\u html
更改了我的类,所以看起来像这样:
因此,现在我将xml更改如下:
> <?xml version="1.0"?> <t
> t-name="probespokeq.production_order_report_en2_template"> <t
> t-call="web.html_container">
> <t t-foreach="docs" t-as="o">
> <t t-call="web.internal_layout">
> <div class="page">
> <h2>Report title</h2>
> <p>This object's name is probespokeq</p>
> <t t-esc="o.testing()"/>
> </div>
> </t>
> </t>
> </t> </t>
>t-name=“probespokeq.production\u order\u report\u en2\u template”>t-call=“web.html\u container”>
>
>
>
>报告标题
>此对象的名称是probespokeq
>
>
>
>
>
我得到:
> Error to render compiling AST AttributeError: 'pb.orders.products'
> object has no attribute 'testing' Template: 1455 Path:
> /templates/t/t/t/t/div/t Node: <t t-esc="o.testing()"/>
>呈现AST AttributeError时出错:“pb.orders.products”
>对象没有属性“测试”模板:1455路径:
>/templates/t/t/t/t/div/t节点:
要像以前一样在报告模板中使用测试
,您应该在中定义它,并将它添加到文档中
from odoo import api, models
class ParticularReport(models.AbstractModel):
_name = 'report.module.report_name'
def _testing(self):
result = 0
return result
@api.model
def render_html(self, docids, data=None):
report_obj = self.env['report']
report = report_obj._get_report_from_name('module.report_name')
docargs = {
'doc_ids': docids,
'doc_model': report.model,
'docs': self,
'testing': self._testing, # You need to add this line
}
return report_obj.render('module.report_name', docargs)
您还可以在pb.orders.products
中定义testing
方法,并在模板中使用o.testing()
您可以找到覆盖函数的自定义报告示例:
@api.multi
def get_report_values(self, docids, data=None):
docs = self.env['pb.orders.products'].browse(docids)
return {
'doc_ids': docs.ids,
'doc_model': 'pb.orders.products',
'docs': docs,
'testing': self._testing, # You need to add this line
}
例子
要使用模型中的方法,请执行以下操作:
class PBOrdersProducts(models.Model):
_name = "pb.orders.products"
name = fields.Char()
def testing(self):
result = 0
return result
和使用:
<t t-esc="o.testing()"/>
在这种情况下,您需要使用:
<t t-esc="testing()"/>
我根据你的建议编辑了我的帖子。我还可以询问您的帮助吗?请使用获取报告值
而不是呈现html
并告诉我发生了什么。您是否使用了第二个函数
并添加到模板文件
中来使用它?是的(我重新编辑了帖子)。我试过了,很抱歉打扰你,谢谢你的帮助!没关系,在示例之后检查我的编辑。我测试了这两种方法,它们都有效。
class OrderProductsFunctions(models.AbstractModel):
_name = 'report.probespokeq.production_order_report_en2_template'
def _testing(self):
result = 0
return result
@api.model
def render_html(self, docids, data=None):
report_obj = self.env['report']
report = report_obj._get_report_from_name('probespokeq.production_order_report_en2_template')
docargs = {
'doc_ids': docids,
'doc_model': report.pb.orders.products,
'docs': self,
'testing': self._testing, # You need to add this line
}
return report_obj.render('probespokeq.production_order_report_en2_template', docargs)
class OrderProductsFunctions(models.AbstractModel):
_name = 'report.probespokeq.production_order_report_en2_template'
def _testing(self):
result = 0
return result
@api.multi
def get_report_values(self, docids, data=None):
docs = self.env['pb.orders.products'].browse(docids)
return {
'doc_ids': docs.ids,
'doc_model': 'pb.orders.products',
'docs': docs,
'testing': self._testing, # You need to add this line
}
> <?xml version="1.0"?> <t
> t-name="probespokeq.production_order_report_en2_template"> <t
> t-call="web.html_container">
> <t t-foreach="docs" t-as="o">
> <t t-call="web.internal_layout">
> <div class="page">
> <h2>Report title</h2>
> <p>This object's name is probespokeq</p>
> <t t-esc="o.testing()"/>
> </div>
> </t>
> </t>
> </t> </t>
> Error to render compiling AST AttributeError: 'pb.orders.products'
> object has no attribute 'testing' Template: 1455 Path:
> /templates/t/t/t/t/div/t Node: <t t-esc="o.testing()"/>
from odoo import api, models
class ParticularReport(models.AbstractModel):
_name = 'report.module.report_name'
def _testing(self):
result = 0
return result
@api.model
def render_html(self, docids, data=None):
report_obj = self.env['report']
report = report_obj._get_report_from_name('module.report_name')
docargs = {
'doc_ids': docids,
'doc_model': report.model,
'docs': self,
'testing': self._testing, # You need to add this line
}
return report_obj.render('module.report_name', docargs)
@api.multi
def get_report_values(self, docids, data=None):
docs = self.env['pb.orders.products'].browse(docids)
return {
'doc_ids': docs.ids,
'doc_model': 'pb.orders.products',
'docs': docs,
'testing': self._testing, # You need to add this line
}
class PBOrdersProducts(models.Model):
_name = "pb.orders.products"
name = fields.Char()
def testing(self):
result = 0
return result
<t t-esc="o.testing()"/>
class ParticularReport(models.AbstractModel):
_name = 'report.test.production_order_report'
def _testing(self):
result = 0
return result
@api.multi
def get_report_values(self, docids, data=None):
docs = self.env['pb.orders.products'].browse(docids)
return {
'doc_ids': docs.ids,
'doc_model': 'pb.orders.products',
'docs': docs,
'testing': self._testing, # You need to add this line
}
<t t-esc="testing()"/>