New button to existing module

  • Step 1:
    Task is to add new button at the top


    1. _mainfest.py

    1. add depends module

    2. add view xml

    
    
                    'depends' : ['hr', 'account'],
                    'data': [
                        'views/hr_employee_views.xml'
                    ],
    
                    

    2. model

    1. add '_inherit'

    2. add new field

    
    
                    class HrEmployee(models.Model):
                         _inherit = 'hr.employee'
     
                        attachment_ids = fields.One2many('ir.attachment', 'id')
       
                  

    3. view

    
    
                    <header position="inside">
                        <button name="action_create_invoice" type="object" class="btn btn-primary" string="Pay the Salary"/>
                    </header>
    
    
    
                  
    Complete code of view
    
                  <odoo>
                        <data>
                            <record id="custom_hr_employee_form" model="ir.ui.view">
                                <field name="name">custom.employee.form.view</field>
                                <field name="model">hr.employee</field>
                                <field name="inherit_id" ref="hr.view_employee_form"/>
                                <field name="arch" type="xml">
                                    <field name="work_email" position="after">
                                        <field name="joining_date"/>
                                        <field name="salary_amount"/>
                                    </field>
                                    <xpath expr="//page[@name='personal_information']" position="after">
                                        <page name="employ_documents" string="Employee Documents">
                                            <group>
                                                <field name="attachment_ids"/>
                                            </group>
                                        </page>
                                    </xpath>
                                    <header position="inside">
                                        <button name="action_create_invoice" type="object" class="btn btn-primary" string="Pay the Salary"/>
                                    </header>
                                </field>
                        </record>
                        </data>
                    </odoo>
    
                

    Add action_create_invoice() in model

    
    
                def action_create_invoice(self):
    
                
    Complete code of model
    
    
                from odoo import models, fields, _
                from odoo.exceptions import UserError
    
    
                class HrEmployee(models.Model):
                    _inherit = 'hr.employee'
    
                    joining_date = fields.Date('Joining Date')
                    attachment_ids = fields.One2many('ir.attachment', 'id')
                    salary_amount = fields.Float('Salary')
    
                    def action_create_invoice(self):