如何在 Odoo 17 中的动作锯齿内添加按钮

问题描述 投票:0回答:1

我在第一个红框中有一个按钮,我想把它放在锯轮图标中,我该如何编写js来做到这一点?

我在模型 hr.employee 的树视图中。

javascript python xml odoo
1个回答
0
投票

要在 Odoo 17 中表单视图的操作菜单(chatter)内添加自定义按钮,您可以按照以下步骤操作:

  1. 定义操作: 首先,确保您已在模型中定义了操作。例如:

    <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>
    
    
    
my.model.form.view 人力资源雇员

实现按钮操作:

从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 模块,刷新界面,然后导航到模型的表单视图

© www.soinside.com 2019 - 2024. All rights reserved.