How To Create Menu and Actions In Odoo16

How To Create Menu and Actions In Odoo16

 

How To Create Menu In Odoo16

Create a new XML file in the views directory of your module. Name the file menu.xml (replace module_name with the name of your module).


In the XML file, add a new record tag with the following attributes:


<?xml version=”1.0″ encoding=”utf-8″?>

<odoo>



        


       <menuitem id=”menu_hospital_root”

                 name= “hospital”

                 sequence=”0″/>


        <menuitem id=”menu_hospital_master”

                 name= “Patient_details”

                 parent=”menu_hospital_root”

                 sequence=”0″/>  


                        


</odoo>


Replace menu_id with a unique ID for the menu, Menu Name with the name you want to give the menu, hospital.patient.action_name with the ID of the action that will be executed when the menu is clicked, and 10 with the sequence number of the menu


Create a new action in the actions directory of your module. Name the file patient_view.xml

In the action file, add a new record tag with the following attributes:



<?xml version=”1.0″ encoding=”utf-8″?>

<odoo>


<record id=”action_hospital_patient” model=”ir.actions.act_window”>

        <field name=”name”>Hospital</field>

        <field name=”type”>ir.actions.act_window</field>

        <field name=”res_model”>hospital.patient</field>

        <field name=”view_mode”>tree,form</field>

        <field name=”context”>{}</field>

        <field name=”help” type=”html”>

            <p class=”o_view_nocontent_smiling_face”>

            Create a patient details

            </p>

        </field>

    </record> 


    <menuitem id=”menu_hospital”

                 name= “Patient”

                 action=’action_hospital_patient’

                 parent=”menu_hospital_master”

                 sequence=”0″/>            


</odoo>


Replace action_name with a unique ID for the action, Action Name with the name you want to give the action, and model.name with the name of the model that the action will be executed on.


  1. Update the __manifest__.py file of your module to include the new XML files in the data list.
  2. Upgrade your module and check if the menu has been created in the Odoo user interface

Comments

No comments yet. Why don’t you start the discussion?

Leave a Reply

Your email address will not be published. Required fields are marked *