3

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

4 回答 4

0

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

于 2015-01-20T15:58:09.847 回答
0

您需要将类中的_name属性更改为.report_saleorderqwebreport.sale_report.sale_custom_report_qweb

于 2015-04-22T15:01:44.343 回答
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>

我知道,现在回答为时已晚,但我希望有人会觉得它有帮助。

于 2016-09-15T11:40:17.617 回答
0

也加这个

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

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

于 2016-12-09T04:13:48.483 回答