2017-07-11 71 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> 

您需要設置您的業務邏輯功能,我只是在這裏分享想法。通過這種方式,你可以調用你的方法而不是字段,你可以顯示函數結果。