xmlodooodoo-12odoo-view

How to remove print and share action from a form odoo 12


Hi I'm using odoo 12 I'd like to remove an action button from a form

print action

and also the share inside the action menu:

remove share menu

I did the following in the inherited view without results:

 <record model="ir.ui.view" id="sale_order_log_notes">
    <field name="name">sale.order.log.notes</field>
    <field name="model">sale.order</field>
    <field name="inherit_id" ref="sale.view_order_form"/>
    <field name="arch" type="xml">

    <xpath expr="//form" position="attributes">    
        <attribute name="share">0</attribute>
        <attribute name="print">0</attribute>
    </xpath>
    </field>
</record>

Solution

  • The Quotation / Order action was added using the report shortcut to ir.action.report and the Share button was added using a server action.

    There are already two buttons in the corresponding form views to unlink the actions (as mentioned by mingtwo_h9), a button named Remove from the 'print' menu to remove the action from the print dropdown menu and Remove Contextual Action button to remove an action from the dropdown action menu, both buttons call the unlink_action method, which is implemented separately for ir.actions.report and ir.actions.server and when called sets the binding_model_id field to False which hides the action.

    It is possible to make a call to a method on a model using the function tag.

    It has two mandatory parameters model and name specifying respectively the model and the name of the method to call.

    Parameters can be provided using eval (should evaluate to a sequence of parameters to call the method with) or value elements (see list values).

    We need to call the unlink_action method and pass the action record as a parameter

    <function model="ir.actions.report" name="unlink_action"
              eval="[ref('sale.action_report_saleorder')]"/>
    
    <function model="ir.actions.server" name="unlink_action" 
              eval="[ref('sale.model_sale_order_action_share')]"/>
    

    You can also pass parameters using the value tag (there is an example in l10n_generic_coa)

    <function model="ir.actions.report" name="unlink_action">
        <value eval="[ref('sale.action_report_saleorder')]"/>
    </function>
    
    <function model="ir.actions.server" name="unlink_action">
        <value eval="[ref('sale.model_sale_order_action_share')]"/>
    </function>