gpt4 book ai didi

python - 无法访问 Odoo 8 Qweb 报告模板中的自定义方法

转载 作者:行者123 更新时间:2023-11-28 19:19:51 25 4
gpt4 key购买 nike

我从 Odoo Qweb 报告开始。我按照本教程创建了我的第一个自定义报告 http://blog.emiprotechnologies.com/create-qweb-report-odoo/

解析器类

import time
from openerp.osv import osv
from openerp.report import report_sxw

class sale_quotation_report(report_sxw.rml_parse):

def __init__(self, cr, uid, name, context):
super(sale_quotation_report, self).__init__(cr, uid, name, context=context)
self.localcontext.update({
'time': time,
'get_total': self.get_total,
})

def get_total(self, lines, field):
total = 0.0
for line in lines:
total += line.product_uom_qty or 0.0
return total

class report_saleorderqweb(osv.AbstractModel):
_name = 'sale_report.sale_custom_report_qweb'
_inherit = 'report.abstract_report'
_template = 'sale_report.sale_custom_report_qweb'
_wrapped_report_class = sale_quotation_report

报 TableView

<?xml version="1.0" encoding="utf-8"?>
<openerp>
<data>
<template id="sale_custom_report_qweb">
<t t-call="report.html_container">
<t t-foreach="docs" t-as="o">
<div class="page">
<div class="oe_structure"/>
<div class="row">
<table style="font-name: 'Helvetica';width:100%;">
<tr colspan="4" style="font-size: 24px;font-weight: bold;">
<td align="center">
<strong> <p t-field="o.partner_id.name"/> </strong>
</td>
</tr>
<tr colspan="4" style="font-size: 12px;">
<td align="center">
QUOTE NO :
<strong>
<span t-field="o.name"/>
</strong>

QUOTE DATE :
<strong>
<span t-field="o.date_order"/>
</strong>

SALES PERSON :
<span t-field="o.user_id.partner_id.name"/>
</td>
</tr>
</table>
</div>
<br/>
<table class="table-condensed" style="font-size: 12px;">
<thead>
<tr style="border-bottom: 1px solid black;">
<th>
<strong>Name</strong>
</th>
<th>
<strong>Qty</strong>
</th>
</tr>
</thead>
<tbody>
<tr t-foreach="o.order_line" t-as="line" style="border-bottom: 1px solid black;">
<td>
<span t-field="line.product_id.name"/>
</td>
<td>
<span t-field="line.product_uom_qty"/>
</td>
</tr>
<tr>
<td/>
<td>
<!-- Print total of product uom qty -->
<strong>
<span t-esc="get_total(o.order_line)"/>
</strong>
</td>
</tr>
</tbody>
</table>

</div>
</t>
</t>
</template>
</data>
</openerp>

当我打印报告时,它抛出这个错误:

File "/home/user/workspace/lcdv/trunk/server/openerp/tools/safe_eval.py", line 313, in safe_eval
return eval(c, globals_dict, locals_dict)
File "", line 1, in <module>

QWebException: "'NoneType' object is not callable" while evaluating
'get_total(o.order_line)'

最佳答案

我认为您必须将“get_total”方法放入“report_saleorderqweb”类而不是“sale_quotation_report”。

关于python - 无法访问 Odoo 8 Qweb 报告模板中的自定义方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28048817/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com