xmlodooodoo-12odoo-view

Show the share button to a specific group in Odoo 12


I'm trying to display a Share Button if the user has a specific group, the button seems like it's an action that launches an ir.actions.act_window

I tried to locate it with XPath using the name but seems like due to the button nature the name changes depending on the environment (names can vary to be like 123 or 124 and so on in other environments)

the button launches a window action with the following action external ID portal.portal_share_action

I tried to use a group attribute referencing action ID in an XML file that is part of the custom project module I built, the code is the following:

<record model="ir.actions.act_window" id="portal.portal_share_action">
    <field name="groups" eval="[(6,0,[ref('rw_project.group_project_rw_base_user')])]"/>
</record>

The button still show even if the user doesn't have the group assigned

Edit:

The button is located in the project form and the xml is the following:

<header>
    <button name="132" string="Share" type="action" class="oe_highlight oe_read_only"/>
</header>

share button on project module


Solution

  • Because you said:

    names can vary to be like 123 or 124 and so on

    I suppose you try to override a button like the Add credit note in customer invoice:

    <button name="%(action_account_invoice_refund)d" type='action' string='Add Credit Note' groups="account.group_account_invoice" attrs="{'invisible': ['|',('type', '=', 'out_refund'), ('state', 'not in', ('open','in_payment','paid'))]}"/>
    

    Which is a button of type action and to override it you can use its name but use the external id (add the module name).

    Example:

    <record id="invoice_form" model="ir.ui.view">
        <field name="name">account.invoice.form</field>
        <field name="model">account.invoice</field>
        <field name="inherit_id" ref="account.invoice_form"/>
        <field name="arch" type="xml">
            <button name='%(account.action_account_invoice_refund)d' position="attributes">
                <attribute name="groups"></attribute>
            </button>
        </field>
    </record>  
    

    If you try to set the groups allowed to view/use the share document action, you need to use the groups_id field. They used the groups_id field in the purchase module to restrict access to purchase users like the following:

    <field name="groups_id" eval="[(4, ref('purchase.group_purchase_user'))]"/>
    

    If the share button you try to override is a drop-down button like in sale order, purchase order, or invoice which are all server actions, there is no available option to restrict access to groups, but you can add the groups_id field in ir.actions.server model then use it the XML definition.

    To implement that you can check my previous answer, How to give user groups(XML) in the model ir.actions.server Odoo 12?

    Edit: override share button action in project form header

    <record id="edit_project" model="ir.ui.view">
        <field name="name">project.project.form</field>
        <field name="model">project.project</field>
        <field name="inherit_id" ref="project.edit_project"/>
        <field name="arch" type="xml">
            <button name="%(portal.portal_share_action)d" position="attributes">
                <attribute name="groups">[Group external identifier]</attribute>
            </button>
        </field>
    </record>