要在 Odoo 17 中表单视图的操作菜单(chatter)内添加自定义按钮,您可以按照以下步骤操作:
定义操作: 首先,确保您已在模型中定义了操作。例如:
<record id="action_my_model_form" model="ir.actions.act_window">
<field name="name">My Model Form</field>
<field name="res_model">hr.employee</field>
<field name="view_mode">form</field>
<field name="target">current</field>
</record>
实现按钮操作:
从odoo导入模型,api
类 YourModel(models.Model): _name = 'hr.employee'
@api.multi
def custom_button_action(self):
# Perform desired actions here
return {
'type': 'ir.actions.act_window',
'res_model': 'hr.employee',
'view_mode': 'form',
'target': 'current',
'context': self.env.context,
}
应用更改: 更新您的 Odoo 模块,刷新界面,然后导航到模型的表单视图