0

I am trying to create a wizard, launched from a button in res.partner's form view, which has two buttons on its footer (besides the 'cancel' one): the first one launches a method that does stuff inside the related res.partner record (but it's not important to the main problem); the second one opens the email form with precompiled values (again, from the related res.partner's recordset values).

My question is: how do I prevent the wizard from closing when I click on the "Send email" button which opens the email form, so that (after I've finished with email itself) I can go back to the wizard and click the "Execute action" button?

I am using Odoo 8 with Python 2.7.14. I already read the similar thread "Odoo - prevent button from closing wizard", but I don't think those solutions can help: most of them just open a new wizard (with the old one's values), but that's not what I need. I need the old wizard to stay there, after the email is done.

My code:

1- the button that launches the wizard (from res.partner):

<button string="Execute action" type="action"
    name="%(execute_action_wizard)d"
    attrs="{'invisible': [('action_required', '=', False)]}"
    class="oe_highlight"/>

2- the action that launches the wizard:

<record id="execute_action_wizard" 
    model="ir.actions.act_window">
    <field name="name">Execute action</field>
    <field name="res_model">
        account.payment.action.wizard</field>
    <field name="view_type">form</field>
    <field name="view_mode">form</field>
    <field name="view_id" 
        ref="execute_action_wizard_form_view"/>
    <field name="target">new</field>
</record>

3- the buttons within the wizard itself:

<button name="compute_execute_action"
    string="Execute action"
    class="oe_highlight"
    type="object"/>
<button name="open_form_send_mail"
    string="Send email"
    class="oe_highlight"
    type="object"
    attrs="{'invisible':[('send_mail', '=', False)]}"/>

4- email form method:

@api.multi
def open_form_send_mail(self):
    self.ensure_one()
    template_id = self.email_template_id.id
    partner_id = self._context['active_ids'][0]
    compose_form_id = self.env.ref(
        'mail.email_compose_message_wizard_form', False).id
    ctx = dict(
        default_res_id=partner_id,
        default_use_template=True,
        default_template_id=template_id or False,
        default_composition_mode='comment',
        default_model='res.partner',
        default_partner_ids=[(6, 0, [partner_id])],
        default_subject=_(u"Client email")
        )
    return {
        'name': _('Compose Email'),
        'context': ctx,
        'type': 'ir.actions.act_window',
        'target': 'new',
        'res_model': 'mail.compose.message',
        'views': [(compose_form_id, 'form')],
        'view_id': compose_form_id,
        'view_mode': 'form',
        'view_type': 'form',
        'flags': {'action_buttons': True},
    }

Please help me out. This is driving me crazy.

SlyK
  • 175
  • 2
  • 14
  • 1
    Possible duplicate of [Odoo - prevent button from closing wizard](https://stackoverflow.com/questions/31963214/odoo-prevent-button-from-closing-wizard) – ChesuCR Nov 20 '17 at 16:53
  • @ChesuCR I found that thread while searching for an answer a few hours ago, but I don't think it works out for me. I don't need a new wizard to open when the mail is done (though with the old one's values); I need the old wizard to stay there. I think it can be achieved, for many other Odoo standard wizards do the same (if I'm correct). – SlyK Nov 20 '17 at 17:11
  • So If I understood well, you mean that from a wizard you open the email wizard and when the email wizard is closed the first wizard is closed as well at the same time? – ChesuCR Nov 20 '17 at 17:52
  • @ChesuCR exactly. The steps are: 1- from a client's form view, you open the first wizard by clicking the related button; 2- inside this wizard, you can find both the "Execute action" and the "Send email" buttons; 3- if you click the latter, the email wizard is opened; 4- when you close that, you may wanna go back to the first wizard... but it's gone as well! :( – SlyK Nov 20 '17 at 17:56
  • How do you close the email wizard? I think you should override the method of the send button inside the email wizard. If you press cancel in the email wizard the previous wizard is also closed? – ChesuCR Nov 20 '17 at 18:37
  • @ChesuCR yes, when you close the email wizard (whether by sending the mail or cancelling it), the previous wizard is always closed. Nighttime, I overrode the send_mail method as you suggested, and it seems to work; although it doesn't get me back to the previous wizard, I arranged to use the python's super() function to send the mail, and then execute the actions that were set in the wizard (and the button "Send mail" is now named "Execute action and send mail"). Not exactly what I needed, but it will have to do in the meanwhile... – SlyK Nov 21 '17 at 08:23

0 Answers0