Odoo 11 add different action menu in two different area for the same model

非 Y 不嫁゛ 提交于 2019-12-24 02:56:08

问题


In Odoo 11 I want two different action menu with two different functionality.

In the hr payroll I wanted to add email payslip link thats why I used this code to add the email payslip action menu

<?xml version="1.0" encoding="utf-8"?>
<odoo>
    <data>
        <record id="action_email_payslip" model="ir.actions.server">
      <field name="name">Email Payslip</field>
            <field name="model_id" ref="hr_payroll.model_hr_payslip"/> 
            <field name="binding_model_id" ref="hr_payroll.model_hr_payslip"/>
            <field name="state">code</field> 
            <field name="code"> 
            action = records.action_email_payslip_send() 
            </field>
    </record>
    </data>
</odoo>

But this one is adding the action menu in the employees row as well. In the employee rows I want a different action menu. So can some one tell me how to achieve that?


回答1:


Ok, last change and I give up. I hope this is exactly what you want. Using the code of the answer I gave you in How to send an email from a button located in the action dropdown of an Odoo 11 form?, just replace the Python method by this one:

@api.multi
def action_email_payslip_send(self):
    template = self.env.ref(
        'your_module_name.email_template_payslip',
        False,
    )
    compose_form = self.env.ref(
        'mail.email_compose_message_wizard_form',
        False,
    )
    ctx = dict(
        default_model='hr.payslip',
        default_use_template=bool(template),
        default_template_id=template and template.id or False,
    )
    if len(self) == 1:
        ctx.update({
            'default_composition_mode': 'comment',
            'default_res_id': self.ensure_one().id,
        })
    else:
        ctx.update({
            'default_composition_mode': 'mass_mail',
            'active_ids': self.ids,
        })
    return {
        'name': _('Compose Email'),
        'type': 'ir.actions.act_window',
        'view_type': 'form',
        'view_mode': 'form',
        'res_model': 'mail.compose.message',
        'views': [(compose_form.id, 'form')],
        'view_id': compose_form.id,
        'target': 'new',
        'context': ctx,
    }

This will open you the email compose message pop-up you like even when you are selecting several payslips (in this case the preview will not replace the Mako variables).

I know it is difficult at the beginning, but as @EasyOdoo commented, you have to get ideas from the answers and investigate about it, that way you will be able to make smaller and more accurate questions and get good responses easily.



来源:https://stackoverflow.com/questions/56108578/odoo-11-add-different-action-menu-in-two-different-area-for-the-same-model

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