OpenERP email Sent confirmation message display

空扰寡人 提交于 2019-12-11 12:05:57

问题


Please help me to update below given send email method so as to pop up depending upon email delivery.

  • "Email has been sent"

  • "Sorry, Email has not been sent at this point of time

    ------------------------------------------------------

    Wizard validation and send

    ------------------------------------------------------

    def send_mail(self, cr, uid, ids, context=None):
    """ Process the wizard content and proceed with sending the related
        email(s), rendering any template patterns on the fly if needed. """
    if context is None:
        context = {}
    ir_attachment_obj = self.pool.get('ir.attachment')
    active_ids = context.get('active_ids')
    is_log = context.get('mail_compose_log', False)
    
    for wizard in self.browse(cr, uid, ids, context=context):
        mass_mail_mode = wizard.composition_mode == 'mass_mail'
        active_model_pool_name = wizard.model if wizard.model else 'mail.thread'
        active_model_pool = self.pool.get(active_model_pool_name)
    
        # wizard works in batch mode: [res_id] or active_ids
        res_ids = active_ids if mass_mail_mode and wizard.model and active_ids else [wizard.res_id]
        for res_id in res_ids:
            # mail.message values, according to the wizard options
            post_values = {
                'subject': wizard.subject,
                'body': wizard.body,
                'parent_id': wizard.parent_id and wizard.parent_id.id,
                'partner_ids': [partner.id for partner in wizard.partner_ids],
                'attachment_ids': [attach.id for attach in wizard.attachment_ids],
            }
            # mass mailing: render and override default values
            if mass_mail_mode and wizard.model:
                email_dict = self.render_message(cr, uid, wizard, res_id, context=context)
                post_values['partner_ids'] += email_dict.pop('partner_ids', [])
                post_values['attachments'] = email_dict.pop('attachments', [])
                attachment_ids = []
                for attach_id in post_values.pop('attachment_ids'):
                    new_attach_id = ir_attachment_obj.copy(cr, uid, attach_id, {'res_model': self._name, 'res_id': wizard.id}, context=context)
                    attachment_ids.append(new_attach_id)
                post_values['attachment_ids'] = attachment_ids
                post_values.update(email_dict)
            # post the message
            subtype = 'mail.mt_comment'
            if is_log:  # log a note: subtype is False
                subtype = False
            elif mass_mail_mode:  # mass mail: is a log pushed to recipients, author not added
                subtype = False
                context = dict(context, mail_create_nosubscribe=True)  # add context key to avoid subscribing the author
            msg_id = active_model_pool.message_post(cr, uid, [res_id], type='comment', subtype=subtype, context=context, **post_values)
            # mass_mailing: notify specific partners, because subtype was False, and no-one was notified
            if mass_mail_mode and post_values['partner_ids']:
                self.pool.get('mail.notification')._notify(cr, uid, msg_id, post_values['partner_ids'], context=context)
    
    return {'type': 'ir.actions.act_window_close'}
    

来源:https://stackoverflow.com/questions/22015410/openerp-email-sent-confirmation-message-display

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