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

Hi everyone,

Iam facing some issues is sending automated mail..it has to go 15 days once .s i need to write the code in python .

Someone please help me with this.

Thanku in advance

Avatar
Discard
Best Answer

Hi,

You can define the cron job like this,

In XML

<record id="ir_cron_scheduler_demo_action" model="ir.cron">
<field name="name">Due Notification</field>
<field name="user_id" ref="base.user_root"/>
<field name="interval_number">15</field>
<field name="interval_type">days</field>

<field name="numbercall">-1</field>
<field eval="False" name="doall"/>
<field eval="'model_name'" name="model"/>
<field eval="'due_notification'" name="function"/>
</record>

This function will get triggered in an interval of 15 days.

You didn't mention the the problem that you are facing. Then you have to define  a python function in the name "due_notification" in the corresponding model.

Inside the python function you can write the code for sending the mail like this,

class DueNotification(models.Model):
_inherit = 'model_name'

@api.multi
def due_notification(self):
template_obj = self.env['mail.mail']
template_data = {
'subject': 'Due Notification : ',
'body_html': "Body....",
'email_from': "test@mail.com",
'email_to': "me@mail.com"
}
template_id = template_obj.create(template_data)
template_obj.send(template_id)


For getting the date after 7 days,

from time import gmtime, strftime
import datetime from dateutil.relativedelta
import relativedelta

current_date = strftime("%Y-%m-%d %H:%M:%S", gmtime())
date_1 = datetime.strptime(current_date, "%Y-%m-%d %H:%M:%S")
date_after_7_days = date_1 + relativedelta(days=7)


Thanks

Avatar
Discard
Author

Iam facing issue that mail not going for 1 min..when im testing for 1 min? and mail id should be accorging to login id?