问题
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