I hr.employee ,create 3 date field for notification to employee to expire his document details.In my scheduler function call is invoked only three steps after that its not working any thing ,and functionality is stuck ,if I use a button for this action then mail alert is working perfectly.issue is in my scheduled action below is my code....
.py
-------------------------------------------------------------------------------------
class hr_employee(osv.osv):
_inherit = 'hr.employee'
_columns = {
'passport_expiry':fields.date('Passport expiry'),
'visa_issue':fields.date('Visa issue Date'),
'visa_expiry':fields.date('Visa Expiry'),
'emirates_id_expiry':fields.date('Emirates ID Expiry'),
'join_date':fields.date('Join Date'),
'insurance_id_expiry':fields.date('Insurance Expiry'),
'departmnet_id':fields.many2one('hr.department','Department'),
'division':fields.many2one('hr.division','Division'),
'expiry_day_limit':fields.integer('Limit(Alert before/Days?)'),
'last_working_date_employee':fields.date('Last Working Date')
#'limit_days':fields.integer('Limint')
}
def send_expiry_email(self, cr, uid, ids=None, context=None):
print 'o'*200
today = datetime.datetime.today()
today = datetime.datetime.strptime(datetime.datetime.strftime(today, DF), DF)
print "DF -->> ", DF #################DF -->> %Y-%m-%d )after this line code is not excecuting.............
for partner in self.browse(cr, uid, ids, context=context): #From Here Scheduler is not working
passport_expiry_days = 0
visa_expiry_days=0
emirates_id_expiry_days=0
insuarance_id_expiry_days=0
if partner.passport_expiry:
passport_expiry = datetime.datetime.strptime(partner.passport_expiry, DF) - today
if int(passport_expiry.days) <= partner.expiry_day_limit:
passport_expiry_days = passport_expiry.days
if partner.visa_expiry:
visa_expiry = datetime.datetime.strptime(partner.visa_expiry, DF) - today
if int(visa_expiry.days) <= partner.expiry_day_limit:
visa_expiry_days = visa_expiry.days
if partner.emirates_id_expiry:
emirates_id_expiry = datetime.datetime.strptime(partner.emirates_id_expiry, DF) - today
if int(emirates_id_expiry.days) <= partner.expiry_day_limit:
emirates_id_expiry_days = emirates_id_expiry.days
if partner.insurance_id_expiry:
insuarance_id_expiry = datetime.datetime.strptime(partner.insurance_id_expiry, DF) - today
if int(insuarance_id_expiry.days) <= partner.expiry_day_limit:
insuarance_id_expiry_days = insuarance_id_expiry.days
partner_email=partner.work_email
passport_expiry=partner.passport_expiry
visa_expiry=partner.visa_expiry
emirates_expiry=partner.emirates_id_expiry
insurance_expiry=partner.insurance_id_expiry
body = "Employee %s has Expired" %( partner.name)
footer="Please Update Your details"
if passport_expiry_days:
body = "%s passport on %s day," % (body,passport_expiry)
if visa_expiry_days:
body = "%s Visa %s on day," % (body,visa_expiry)
if emirates_id_expiry_days:
body = "%s Emirates %s on day," %( body,emirates_expiry)
if insuarance_id_expiry_days:
body = "%s Insurance %s on day," % (body,insurance_expiry)
mail_values= {
'body_html' :'<pre><span class="inner-pre" style="font-size: 15px">%s</br>%s</span></pre>' %(body,footer),
'record_name': 'dsdds',
'email_from': 'test@yahoo.in',
'email_to': partner_email,
'subject': 'Employee Expiry Details'
}
mail_id = self.pool.get('mail.mail').create(cr, uid, mail_values, context=context)
self.pool.get('mail.mail').send(cr, uid, [mail_id])
return True
.xml file
----------------------------------------------------------
<record id="ir_cron_employee_expiry_info" model="ir.cron">
<field name="name">Employee Document Expiry scheduler</field>
<field eval="True" name="active"/>
<field name="interval_number">1</field>
<field name="interval_type">minutes</field>
<field name="numbercall">-1</field>
<field eval="False" name="doall"/>
<field eval="'hr.employee'" name="model"/>
<field eval="'send_expiry_email'" name="function"/>
<field eval="'()'" name="args"/>
</record>