skip to Main Content

I have a button in the first red frame, I want to put it in the saw wheel icon, how do I write js to do that?

I am in the treeview of model hr.employee.

2

Answers


  1. To add a custom button inside the action menu (chatter) of a form view in Odoo 17, you can follow these steps:

    1. Define the Action:
      First, ensure that you have defined an action in your model. For example:

      <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
    hr.employee

    Implement Button Action:

    from odoo import models, api

    class 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,
        }
    

    Apply Changes:
    Update your Odoo module, refresh the interface, and navigate to the form view of your model

    Login or Signup to reply.
  2. You need to define an action menu item and add it to the cogMenu

    Action Item

    /** @odoo-module **/
    
    import { Component } from "@odoo/owl";
    import { DropdownItem } from "@web/core/dropdown/dropdown_item";
    import { registry } from "@web/core/registry";
    import { STATIC_ACTIONS_GROUP_NUMBER } from "@web/search/action_menus/action_menus";
    
    const cogMenuRegistry = registry.category("cogMenu");
    
    export class CustomAction extends Component {
        static template = "web.CustomAction";
        static components = { DropdownItem };
    
        async onClick() {
            
        }
    }
    
    export const CustomActionItem = {
       Component: CustomAction,
       groupNumber: STATIC_ACTIONS_GROUP_NUMBER,
       isDisplayed: async (env) =>
           env.config.viewType === "list" &&
           !env.model.root.selection.length
    };
    
    cogMenuRegistry.add("custom-action-menu", CustomActionItem, { sequence: 19 });
    

    Action template

    <?xml version="1.0" encoding="UTF-8"?>
    <templates xml:space="preserve">
    
        <t t-name="web.CustomAction">
            <DropdownItem class="'o_custom_action_menu'" onSelected.bind="onClick">
                <i class="fa fa-fw fa-bars me-1"/>Custom Action
            </DropdownItem>
        </t>
    
    </templates>
    

    Add the files the backend assets bundle

    'assets': {
            'web.assets_backend': [
                'MODULE_NAME/static/src/components/*.js',
                'MODULE_NAME/static/src/components/*.xml',
            ],
        },
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search