大佬教程收集整理的这篇文章主要介绍了如何在qweb report odoo 12中通过Python获取xml中模型的字段值?,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
我想在 xml qweb 报告中获取模型的值。但在 xml 模型中,模型被视为字符串,因此不会对其进行迭代。 我的代码:
def print_report_status(self):
active_IDs=self.env.context.get('active_IDs',[])
prd_categ= self.env['product.category'].search([])
datas={
'IDs':active_IDs,'model':'report.model','form' : self.read()[0],'categ':prd_categ,}
return self.env.ref('product_report.action_report_pr').report_action(self,data=datas)
并在 xml 中:
<t t-foreach="categ" t-as="c">
<tr style="border:1px solID black; text-align:left;">
<td wIDth="20%" style="text-align:left;"><span t-fIEld="c.name"/></td>
</tr>
</t>
它正在考虑将“c”作为字符串而不是模型。 有什么建议请
user10810227
您必须访问 data['categ']
而不仅仅是 categ
XML
中的 for-loop
。
我的回答特别不是关于为什么模型作为字符串返回,而是关于如何使这个报告工作。
<t t-foreach="request.env['product.category'].search([])" t-as="c">
<tr style="border:1px solid black; text-align:left;">
<td width="20%" style="text-align:left;"><span t-field="c.name"/>/td>
</tr>
</t>
def print_report_status(self):
active_ids=self.env.context.get('active_ids',[])
prd_categ= self.env['product.category'].search([])
datas={
'ids':active_ids,'model':'report.model','form' : self.read()[0],'categ': [{'name': I['name']} for i in prd_categ]
}
return self.env.ref('product_report.action_report_pr').report_action(self,data=datas)
然后像以前一样在 XML 中循环数据。
,我想你可以在你的 xml 模板中试试这个
<t t-set="categs" t-value="categ"/>
<t t-foreach="categs" t-as="c">
*something here*
</t>
以上是大佬教程为你收集整理的如何在qweb report odoo 12中通过Python获取xml中模型的字段值?全部内容,希望文章能够帮你解决如何在qweb report odoo 12中通过Python获取xml中模型的字段值?所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。