Call action via button with OdooV12

我们两清 提交于 2019-12-11 15:53:26

问题


I'm an Odoo developer and my issue is i wanna call an action from template into xml file. For Odoo docs/guide is so poor, so i need help to do something great.

Thanks

<!-- This is my action declaration into '''views/action_views.xml''' -->
<record model="ir.actions.act_window" id="action_show_something">
    <field name="name">Wanna show you something</field>
    <field name="res_model">product.template</field>
    <field name="type">ir.actions.act_window</field>
    <field name="view_type">tree</field>
    <field name="view_mode">tree</field>
     .........
    </field>
  </record>
</odoo>

<!-- Right now, this is my template file '''views/template.xml''' -->
<template id="my_template_button_view">
 <a role="button" type="object" name="action_show_something" string="Call the action !!!" />Call the action</a>
</template>

<!-- The button is visible but the action's not working ...... -->

Class ProductTemplate(models.Model):

  _inherit = '''product.template'''
  def action_show_something(self):
      view_id = self.env.ref('mymodule_to_show.action_show_something').read()[0]
      return {
       'name':      _(view_id.name) if view_id else '',
       'type':      view_id.type if view_id else '',
       'view_type': view_id.view_type if view_id else '',
       'view_mode': view_id.view_mode if view_id else '',
       'res_model': view_id.res_model if view_id else '',
       'target':    'new',
      }

来源:https://stackoverflow.com/questions/57391407/call-action-via-button-with-odoov12

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!