【问题标题】:How do I show custom search results in odoo?如何在 odoo 中显示自定义搜索结果?
【发布时间】:2019-12-04 14:28:05
【问题描述】:

我在我的程序模型中创建了这个方法:

@api.multi
def get_results(self):

    q = "select * from program_program where id_year = 1"
    self.env.cr.execute(q)
    res = self.env.cr.dictfetchall()
    result = self.env['program.program'].browse([row['id_viti'] for row in res])
    print(result)
    return result

我已经创建了一个动作服务器:

    <record id="program" model="ir.actions.server">

<field name="name">First year program</field>

<field name="condition">True</field>

<field name="type">ir.actions.server</field>

<field name="model_id" ref="model_program_program" />

<field name="state">code</field>

<field name="code">action = model.get_results()</field>

</record>

还有一个 menuItem:

  <menuitem id="year_1"
          name="First year"
          action="program"
/>

所以get_results 方法在菜单项点击时被调用。我希望能够在我的页面上显示该方法的结果。我收到此错误: AttributeError: 'program.program' object has no attribute 'setdefault'

【问题讨论】:

    标签: python odoo odoo-11


    【解决方案1】:

    您的方法应该返回一个窗口操作而不是记录集(搜索结果),并使用域来过滤记录:

       @api.multi
       def get_results(self):
           # just to simplify the code using Odoo APIs
           ids = self.env['program.program'].search([('id_year','=', 1)]).mapped('id_viti.id')
           return {
            'name':_("Programs of year 1"),
            'view_mode': 'tree,form',
            'view_type': 'form',
            'res_model': 'program.program',
            'type': 'ir.actions.act_window',
            'domain': [('id', 'in', ids)],
            'context': self._context,
        }
    

    抱歉,有任何语法错误。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-07-12
      • 1970-01-01
      • 2020-05-16
      • 1970-01-01
      • 2012-02-29
      • 2019-02-25
      • 1970-01-01
      相关资源
      最近更新 更多