2017-07-11 68 views
1
<tbody> 
    <tr t-foreach="o.line_ids.filtered(lambda line: line.appears_on_payslip)" t-as="line"> 
    <t t-if="line.code in ('BASIC','OT','DED','GROSS','NET')"> 
     <td><span t-field="line.code"/></td> 
     <td><span t-field="line.name"/></td> 
     <td><span t-field="line.quantity"/></td> 
     <td><span t-field="line.amount" t-esc-options='{"widget": "monetary", "display_currency": o.company_id.currency_id}'/></td> 
     <td><span t-field="line.total" t-esc-options='{"widget": "monetary", "display_currency": o.company_id.currency_id}'/></td> 
    </t> 
    </tr> 
</tbody> 

上述代码是qweb报告中表的主体。而不是“line.quantity”,我想调用一个python函数“o.compute_overtime()”和写:Odoo - 从qweb报告中调用python函数

<t t-if="line.code=='OT'"> 
<td><span t-esc="i['ot_total']"/></td> 
</t> 

我怎么能调用的只有1场的功能?

回答

0

您需要创建一个解析器类,并且需要定义一个可从其报告中访问的函数。

from openerp import models 
from openerp.report import report_sxw 

class report_invoice_parser(report_sxw.rml_parse): 
    def __init__(self, cr, uid, name, context=None): 
     super(report_invoice_parser, self).__init__(cr,uid,name,context=context) 
     self.localcontext.update({ 
       'get_name':self._get_name, 
       }) 
     self.context=context 

    def _get_name(self,line): 

     if line.invoice_id.write_description == True: 
      return line.name 

     if line.product_id: 
      if line.product_id.default_code: 
       return "[%s] %s"%(line.product_id.default_code,line.product_id.name) 
      else: 
       return line.product_id.name 
     else: 
      line.name 

class report_invoice(models.TransientModel): 
    _name = "report.account.report_invoice" 
    _inherit ="report.abstract_report" 
    _template="account.report_invoice" 
    _wrapped_report_class =report_invoice_parser 

而在xml中,您需要将其称为如下。

<tr t-foreach="o.invoice_line" t-as="l"> 
    <td><span t-esc="get_name(l)"/></td> 
</tr> 

您需要设置您的业务逻辑功能,我只是在这里分享想法。通过这种方式,你可以调用你的方法而不是字段,你可以显示函数结果。