Python 无法访问Odoo 8 Qweb报表模板中的自定义方法

Python 无法访问Odoo 8 Qweb报表模板中的自定义方法,python,openerp,qweb,Python,Openerp,Qweb,我从奥多Qweb报告开始。我按照本教程创建了第一个自定义报告 解析器类 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

我从奥多Qweb报告开始。我按照本教程创建了第一个自定义报告

解析器类

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)'
文件“/home/user/workspace/lcdv/trunk/server/openerp/tools/safe_eval.py”,第313行,在safe_eval中
返回值(c、全局值、局部值)
文件“”,第1行,在
QWebException求值时:“'NoneType'对象不可调用”
'获取总计(订单行)'

我认为您必须将“get\u total”方法放入“report\u saleorderqweb”类中,而不是“sale\u quote\u report”。

您需要将
report\u saleorderqweb
类中的
name
属性更改为
report.sale\u report.sale\u custom\u report\u qweb
get\u total
不是
sale\u quote\u 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>



我知道,现在回答这个问题已经太晚了,但我希望有人会觉得它有帮助。

再加上这个

<record id="id_name" 
string="STRING" 
model="model_name" 
name="module_name.template_id"/>


将其添加到xml文件中并调用清单

我认为这不是问题所在,在Odoo文件account/report/account_balance.py中,抽象模型上没有定义任何方法,所有方法都在_wrapped_report_类中。@user3129344您应该升级模块并再次检查它是否反映了来自终端的相同结果。