我从 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)'