Skip to Content
เมนู
คุณต้องลงทะเบียนเพื่อโต้ตอบกับคอมมูนิตี้
คำถามนี้ถูกตั้งค่าสถานะ
3 ตอบกลับ
10314 มุมมอง

In a Menu When selecting records in tree view, on action menu I want to hide particular options only for that Menu. How?

อวตาร
ละทิ้ง
คำตอบที่ดีที่สุด

To hide Action in the Action Menu, override fields_view_get() method.

fields_view_get() load before record loading, so get record's field data is not ideal and not recommended.

For the purpose of your comment in Ravi Gadhia's reply,

You are hiding action based on different window actions.

Assuming

  1. "Publish" and "Mail" both have their own menuitem with corresponding window action to each of its own view.

  2. They resides on the same Model.

Give each window action a context value, and when overriding fields_view_get(), match the action 'xml_id' and context you specified, then remove the action from menu.

Below I created a module to display sale orders that have back order quantity for example,

Window action to the tree view I want to hide action within

<record id="action_back_orders" model="ir.actions.act_window">
    <field name="name">Back Orders</field>
    <field name="res_model">sale.order</field>
    <field name="view_id" ref="view_backorder_tree"/>
    <field name="view_mode">tree,kanban,form,calendar,pivot,graph,activity</field>
    <field name="search_view_id" ref="sale_order_view_search_inherit_backorder"/>

    <!-- act_window_id used for fields_view_get() to distinguish
         SaleOrder and BackOrder tree views on the same model
         the key or value of 'act_window_id' could be whatever you want -->
    <field name="context">{'act_window_id': 'sale_back_order.action_back_orders'}</field>

    <field name="domain">[('state', 'not in', ('draft', 'sent', 'cancel')), ('backed_amount_total', '&gt;', 0)]</field>
    <field name="help" type="html">
        <p class="o_view_nocontent_smiling_face">
            Create a new quotation, the first step of a new sale!
        </p><p>
            Once the quotation is confirmed, it becomes a sales order.<br/>
            You will be able to create an invoice and collect the payment.
        </p>
    </field>
</record>

fields_view_get() in sale.order model

@api.model
def fields_view_get(self, view_id=None, view_type='form', toolbar=False, submenu=False):
    res = super(SaleOrder, self).fields_view_get(
                                    view_id=view_id,
                                    view_type=view_type,
                                    toolbar=toolbar,
                                    submenu=submenu)
    if toolbar:
        actions_in_toolbar = res['toolbar'].get('action')
        if actions_in_toolbar:
            for action in actions_in_toolbar:
                if action.get('xml_id'):
                    action_match = action['xml_id'] == 'sale.model_sale_order_action_quotation_sent'
                    view_match = self._context.get('act_window_id') == 'sale_back_order.action_back_orders'
                    if action_match and view_match:
                        res['toolbar']['action'].remove(action)
    return res

You will need to understand how 'window action' and 'view' work to play with fields_view_get()

อวตาร
ละทิ้ง
คำตอบที่ดีที่สุด

I wrote a module 'web_menu_action_if' to accomplish this task in Odoo 9.0.
See my answer to:

https://www.odoo.com/forum/help-1/question/assign-action-menu-item-to-specific-tree-view-112007

อวตาร
ละทิ้ง
คำตอบที่ดีที่สุด

for the default option like export, delete you need js customization there are no configuration options. I think in apps store some modules available to achieve it.
other options are added by either server action or act_window.
for server action remove/delete those server actions for the related model 
for act_window remove "multi" key or set it to false for actions

อวตาร
ละทิ้ง
ผู้เขียน

Thanks Ravi for your answer, but here actually my doubt is :- Suppose I have two menu named "Publish Menu", "Mail Menu" and this two menu from one model. But I want to show "PUBLISH" in action when I select some records under ""Publish Menu". But this "PUBLISH" option will not show in action when I select some records under "Mail Menu". Similar for "Mail Menu".

How To Do That?