Is there a way to add an extra action to the action menu in tree view in Odoo 12?

假如想象 提交于 2021-01-28 19:53:04

问题


i am searchin to add a new button that displays my wizard to the action button display in the tree view

My wizard works because i tested it individually, but i need to add it to the action button on the top and i do not know how

I tried to use the action.server but did not find any example that helped me

Thanks

Also i know that from Odoo 10 to Odoo 12 changed, thats why i have not found any clue.

Next are the examples i tried but not succed

<record model="ir.actions.act_window" id="enviar_evaluacion">
        <field name="name">enviar_evaluacion</field>
        <field name="view_id" ref="vista_formulario_riesgo_para_evaluacion"/>
        <field name="domain">[]</field>
        <field name="context">{}</field>
        <field name="res_model">pdi.riesgo</field>
        <field name="view_type">form</field>
        <field name="view_mode">form</field>
        <field name="target">new</field>
</record>

<record model="ir.actions.server" id="accion_servidor_evaluacion">
    <field name="name">Enviar a evaluacion</field>
    <field name="model_id" ref="model_pdi_riesgo_wizard_evaluacion"/>
    <field name="state">code</field>
    <field name="code">
        object.enviar_a_evaluar(context.get('active_ids'))
    </field>
</record>

next try

<record model="ir.actions.server" id="menu_action_evaluacion">
    <field name="name">Enviar a evaluacion</field>
    <field name="model_id" ref="model_pdi_riesgo"/>
    <field name="state">code</field>
    <field name="code">
        action=pdi.riesgo.wizard.evaluacion.enviar_a_evaluar()
    </field>
</record>




<menuitem id="menu_enviar_a_evaluacion" 
          name="Enviar a evaluacion" 
          parent="pdi_Riesgo.menu_riesgo_evaluaciones" 
          action="menu_action_evaluacion"/>

回答1:


The "new" way is to set some new fields on actions. Following is an example from Odoo's app crm:

        <!--
            'Mark as Lost' in action dropdown
        -->
        <record id="action_mark_as_lost" model="ir.actions.server">
            <field name="name">Mark as lost</field>
            <field name="model_id" ref="model_crm_lead"/>
            <field name="binding_model_id" ref="crm.model_crm_lead"/>
            <field name="binding_view_types">list</field>
            <field name="state">code</field>
            <field name="code">
if record:
    action_values = env.ref('crm.crm_lead_lost_action').read()[0]
    action_values.update({'context': env.context})
    action = action_values
            </field>
        </record>

So there are three fields on model ir.actions (which is inherited by ir.actions.server) all beginning with binding_

  • binding_model_id: set a ref to an existing model, is enough to show the action in the action menu
  • binding_type: report for the report menu and action for the action menu (default)
  • binding_view_types: list,form is default, list and form should also work, i didn't look into that field, so maybe there are way more combinations/values



回答2:


[Odoo 7,8,9 and 10] to add an action to the action menu, you must also create a record for the "ir.values" model. Here an example:

<record model="ir.values" id="ir_values_my_action">
      <field name="model_id" ref="model_my_model" />
      <field name="name">Name Of Action</field>
      <field name="key2">client_action_multi</field>
      <field
        name="value"
        eval=
          "'ir.actions.server,' + str(ref('action_name_reference'))"/>
      <field name="key">action</field>
      <field name="model">my.model</field>
    </record>


来源:https://stackoverflow.com/questions/62876816/is-there-a-way-to-add-an-extra-action-to-the-action-menu-in-tree-view-in-odoo-12

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!