Skip to Content
Menu
This question has been flagged
4 Replies
21724 Views

Hi everybody,


Is there any way to add a new button to existing module form?

For example, I want to add a new button to Recruitment Applicant form. The new button will link to my custom menu item (such as: Recruitment/Applications/New Menu).

Now, looking at the form view of Applicant form, I saw button which link to applicant's document:

<button name="action_get_attachment_tree_view" class="oe_stat_button" icon="fa-book" type="object">

       <field name="attachment_number" widget="statinfo" string="Documents"/>

</button>

So, I'd like to add a new button link to my menu, I created the action for my custom menu item.


I refer everything on using Odoo app, I did not implement anything with code.


Thank you all

Avatar
Discard
Best Answer

Add button on header inside form view

like eg:-

<header>

<button name="action_get_attachment_tree_view" class="oe_stat_button" icon="fa-book" type="object">

       <field name="attachment_number" widget="statinfo" string="Documents"/>

</button>


</header>
if you are inheriting any parent form view then add through xpath or using position="inside" arrtibute
Avatar
Discard
Author

Hi,

Can you explain more about xpath and where should I put it?

I can see that button by select "Edit form view" from debug menu, I didn't change any xml file.

I created the new menu item with Odoo UI (Create the menu item, create window action, create the view for new object model)

Thank you.

<xpath expr="//header" position="inside"><-- code for button --></xpath> // this only needs if you are inheriting any view

Best Answer

how can i make it runnable or how can i perform some function on click of this button????

i have tried this :

 <record id="hr_payslip_form" model="ir.ui.view">

            <field name="name">hr.payslip.form</field>

            <field name="model">hr.payslip</field>

            <field name="type">form</field>

            <field name="inherit_id" ref="hr_payroll.view_hr_payslip_form"/>

            <field name="arch" type="xml">

                    <xpath expr="//header" position="inside">

                        <button name="my_button" string="Print2" class="oe_highlight"/>

                    </xpath>

            </field>

        </record>


models.py


class custom_hr_payslip(models.Model):

    _name = 'custom.hr.payslip'

    _inherit = 'hr.payslip'


    @api.one

    def my_button(self):

        print("##########################################")


Avatar
Discard