【问题标题】:Calling Python function in XML report (odoo 10)在 XML 报告中调用 Python 函数 (odoo 10)
【发布时间】:2017-10-31 08:37:39
【问题描述】:

我正在尝试调用返回值的方法。我想获取这些值并在我的报告中使用它们。

@api.one
    def check_month(self,record,res):        
        fd = datetime.strptime(str(record.from_date), "%Y-%m-%d")   
        for rec in record.sales_record_ids:
            res.append(rec.jan_month)

    @api.one
    def get_sales_rec(self):
        result=[]
        target_records = self.env['sales.target'].search([('sales_team','=', self.sales_team_ids.id)])         
        for rec in target_records:
            self.check_month(rec,result)
        return result     

像这样在 xml 中:

   <tbody>
        <tr t-foreach="get_sales_rec()" t-as="data">                                        
            <tr>
                <td>
                    <span t-esc="data[0]" />
                </td>
            </tr>                                       
        </tr>
    </tbody>

【问题讨论】:

  • 首先检查您的 xml 报告是否正在获取您的任何 python 函数的值。因为如果它没有从任何函数中获取任何值,那么这可能是您提供给 xml 的 id 和您的特定 pyhton 文件的模型名称的问题。
  • 我找到了@Heroic的帮助并解决了。
  • @ArsalanSherwani 如果您认为这是解决问题的方法,请将其标记为已接受

标签: python xml openerp odoo-10


【解决方案1】:

将您的 xml 代码更改为:

<tbody>
    <tr t-foreach="o.get_sales_rec()" t-as="data">                                        
        <tr>
            <td>
                <span t-esc="data[0]" />
            </td>
        </tr>                                       
    </tr>
</tbody>

这里o代表报表模型对象,所以请确保你在同一个对象中添加了一个python方法。

【讨论】:

  • sales.target 中添加python 方法的地方?对象
  • @Heroic,犯了一个错误。谢谢
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多