콘텐츠로 건너뛰기
메뉴
커뮤니티에 참여하려면 회원 가입을 하시기 바랍니다.
신고된 질문입니다
3 답글
3191 화면

Hi,

I have a custom module that sends Approved email to leave applicant.
The issue when I click Approve button, it sends the default and custom approved email to the applicant. 
Is there a way I can send only custom email template to the applicant using python code?

Somebody help!

아바타
취소
작성자 베스트 답변

Thank you for your response. I forgot to mention that the issue is on odoo 12 leave management. I know how to crate and send custom emails. I the issue is when I click the approve button, the system sends both the original(default) and custom(new) approve email to the applicant. I only want to send the custom approved email without the default(disable or stop default from sending).

아바타
취소
작성자

I solved it by adding my custom email template in def _track_subtype function using super and finally added return False. I don't know if it's the best approach but it worked for me.

베스트 답변

Hi,

Refer the blog for creating a custom mail template and to send it through send_mail method.

https://www.cybrosys.com/blog/how-to-send-email-from-code-in-odoo-15

Regards

아바타
취소
베스트 답변

Yes, you can send only the custom email template to the leave applicant by using the send_mail method from the mail.template model.

Here is an example of how you can do this in your module:

from odoo import api, models

class LeaveRequest(models.Model):
    _name = 'leave.request'

    @api.multi
    def approve_leave(self):
        for leave in self:
            # Send custom email template to leave applicant
            template = self.env.ref('your_module.your_custom_email_template_id')
            template.send_mail(leave.id, force_send=True)

            # Set leave status to Approved
            leave.write({'state': 'approved'})

In the above code, we are first getting the reference to the custom email template using its id, then we use the send_mail method of the mail.template model to send the email to the leave applicant.

After sending the email, we update the leave request status to "Approved".

You can adjust the code according to your needs and requirements.

I hope this helps.

아바타
취소