Create another action menuitem in Odoo

无人久伴 提交于 2021-02-08 08:45:43

问题


I'm trying to extend the funcionallity of the actions defined in a custom module view adding a new menuitem for it. I'm not sure how is defined the code for doing it.

The model used is: education.group

The module where is defined is: education.

<record id="education_group_mailing_action" model="ir.actions.server">
    <field name="name">Generate group lists</field>
    <field name="type">ir.actions.server</field>
    <field name="model_id" ref="model_education_group"/>
    <field name="binding_model_id" ref="model_education_group"/>
    <field name="state">code</field>
    <field name="code">action = records.generate_lists()</field>
</record>

<record id="education_group_mailing_action2" model="ir.default">
        <field name="model_id" ref="model_education_group" />
        <field name="field_id" eval="1" />
        <field name="json_value">False</field>
        <field name="name">Generate group lsts</field>
        <field name="key2">client_action_multi</field>
        <field name="key">action</field>
        <field name="model">education.group</field>
        <field name="value" eval="'ir.actions.server,' + str(ref('education_group_mailing_action'))" />
    </record>
class EducationGroup(models.Model):
    _inherit='education.group'

   def generate_lists(self):
        print("HELLO!")

Anyone knows how to to it? Thanks for reading!


回答1:


If you are using Odoo12.0 then you have to do like this.

    <record id="new_action1" model="ir.actions.server">
        <field name="name">New Action</field>
        <field name="model_id" ref="model_product_template" />
        <field name="binding_model_id" ref="model_product_template" />
        <field name="state">code</field>
        <field name="code">records.export_product()</field>
    </record>
    <record id="run_product_new_order_action2" model="ir.default">
        <field name="model_id" ref="model_product_template" />
        <field name="field_id" eval="1" />
        <field name="json_value">False</field>
        <field name="name">New Action</field>
        <field name="key2">client_action_multi</field>
        <field name="key">action</field>
        <field name="model">product.template</field>
        <field name="value" eval="'ir.actions.server,' + str(ref('new_action1'))" />
    </record>

If you are using Odoo13.0 then it will be like

       <record id="product_order_new_action1" model="ir.actions.server">
            <field name="name">New Action</field>
            <field name="type">ir.actions.server</field>
            <field name="model_id" ref="model_product_template" />
            <field name="binding_model_id" ref="model_product_template" />
            <field name="state">code</field>
            <field name="code">records.sync_product(False)</field>
        </record>



回答2:


Check this Code,

<record id="mail_mass_mailing_lists_action" model="ir.actions.server">
    <field name="name">Generate group lists</field>
    <field name="type">ir.actions.server</field>
    <field name="model_id" ref="mass_mailing.model_mail_mass_mailing_list"/>
    <field name="binding_model_id" ref="mass_mailing.model_mail_mass_mailing_list"/>
    <field name="state">code</field>
    <field name="code">action = records.generate_lists()</field>
</record>

Thanks



来源:https://stackoverflow.com/questions/60707862/create-another-action-menuitem-in-odoo

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