Skip to Content
Menu
This question has been flagged
1 Reply
1437 Views

In Odoo 12 I am trying to get a mail 90 days prior (before) to expiry of subscription and automatically I have created a email template and function for this but iam not receiving any mails even though i create any records

In py file: license_renewal_date = fields.Date ("Renewal Date", track_visibility = 'onchange')

    def exp_date1(self):
    before_90_days = datetime.datetime.now().date()- datetime.timedelta(days = 90)
    exp_90days = self.env['(crm.lead.extended)'].search([('(license_renewal_date)','=',before_90_days)])
    template = self.env.ref('crm_extended.create_crm_lead_mail_template')
    template.send_mail(self.id, force_send=True)   
Avatar
Discard
Best Answer

There are typos in the self.env part of the code. The model and field names should not have parentheses around them. Change it like so and see if your problem is fixed.

self.env['crm.lead.extended'].search([('license_renewal_date','=',before_90_days)])
Avatar
Discard
Author

still i am not getting any mails do i need to use @api multi for this ?

Author

check this :

@api.multi

def exp_date1(self):

testDateOnly = license_renewal_date.date;

before_90_days = testDateOnly - datetime.timedelta(days = 90)

#before_90_days = datetime.datetime.now().date()- datetime.timedelta(days = 90)

exp_90days = self.env['crm.lead.extended'].search([('license_renewal_date','=',before_90_days)])

template = self.env.ref('crm_extended.create_crm_lead_mail_template')

template.send_mail(self.id, force_send=True)

It's difficult to read the code without the proper indentation and formatting. Please update your question with the formatted code.