我从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
报告视图
<?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)'
答案 0 :(得分:0)
我认为你必须把&#39; get_total&#39;方法进入&#39; report_saleorderqweb&#39;而不是&#39; sale_quotation_report&#39;。
答案 1 :(得分:0)
检查缩进,因为get_total
不属于sale_quotation_report
类,如果是,它将抛出以下错误消息:
QWebException: "get_total() takes exactly 3 arguments (2 given)" while evaluating
'get_total(o.order_line)'
您可以在QWEB中计算总数:
<tbody>
<!-- ** First line ** -->
<t t-set='total' t-value='0'/>
<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>
<!-- ** Second line ** -->
<t t-set='total' t-value='total + line.product_uom_qty'/>
</tr>
<tr>
<td/>
<td>
<!-- Print total of product uom qty -->
<strong>
<!-- ** Third line ** -->
<span t-esc="total"/>
</strong>
</td>
</tr>
</tbody>
我知道,现在回答已经太迟了,但我希望有人会觉得它有用。
答案 2 :(得分:0)
添加此内容
<record id="id_name"
string="STRING"
model="model_name"
name="module_name.template_id"/>
将其添加到xml文件中并调用清单