Bỏ qua để đến Nội dung
Menu
Câu hỏi này đã bị gắn cờ
1 Trả lời
7062 Lượt xem

I have created a custom email template and also I have created a send email button for the action. When I click that button email is send automatically. But before sending email automatically, I want my email template pop up like in sale system for some editing. Is it possible to make custom email pop up in my own module?

Thanks in Regards.

Ảnh đại diện
Huỷ bỏ
Tác giả

Dear Sehrish I have tried this method, the email is sent automatically without popping out like that in sale.

Câu trả lời hay nhất

Hello

You have do code like..

XML: add button for send the mail 

         <button name="btn_send_mail" string="Send Mail" type="object"/>

Python: 

    @api.multi
    def btn_send_mail(self):
        template_id = self.env.ref('module_name.email_template_xml_id').id
        compose_form_id = self.env.ref('mail.email_compose_message_wizard_form').id
        ctx = {
            'default_model': 'your_object',
            'default_res_id': self.id,
            'default_use_template': bool(template_id),
            'default_template_id': template_id,
            'default_composition_mode': 'comment',
            'custom_layout': "mail.mail_notification_paynow",
            'force_email': True
        }
        return {
            '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,
        }
Ảnh đại diện
Huỷ bỏ
Tác giả

Thank You very much, It is working fine with me.

Tác giả

The pop work fine but it cann't be sent.

Yes,But the email is not send...

what the issue are you facing ? can you please paste here.

Tác giả

I have corrected my code, now I can send email too.

Here is the code.

'depends' :['base', 'sale']

@api.multi

def send_mail_template(self):

self.ensure_one()

ir_model_data = self.env['ir.model.data']

try:

template_id = ir_model_data.get_object_reference('your_module_name', 'Your Template Name')[1]

except ValueError:

template_id = False

try:

compose_form_id = ir_model_data.get_object_reference('mail', 'email_compose_message_wizard_form')[1]

except ValueError:

compose_form_id = False

ctx = {

'default_model': 'bhuwan.khadka',

'default_res_id': self.ids[0],

'default_use_template': bool(template_id),

'default_template_id': template_id,

'default_composition_mode': 'comment',

'mark_so_as_sent': True,

'force_email': True

}

return{

'type': 'ir.actions.act_window',

'view_type': 'form',

'view_mode': 'form',

'res_model': 'mail.compose.message',

'views': [(compose_form_id, 'form')],

'views_id': compose_form_id,

'target': 'new',

'context': ctx,

}

Thank you for your help. I learned a lot from your code.

Bài viết liên quan Trả lời Lượt xem Hoạt động
0
thg 4 23
91
1
thg 11 22
2302
2
thg 8 19
7124
1
thg 10 23
4100
1
thg 6 22
6533