Odoo Help


How to generate an automatic mail alert to employee if an expirydate is reached, my code is not working?

on 6/3/15, 12:37 AM 731 views

I have a custom field visa_expiry,emirates_id_expiry, passport_expiry,insurance_id_expiry in hr.employee model .I want to notify the employee  and manager  by an automatic email before 5 days from the expiry_date of   regarding the expiry details .How its possible?need a help My current code is not working and scheduler also,

I am trying to implement the logic in def send_expiry_email(self, cr, uid, ids=None, context=None): this function

class hr_employee(osv.osv):


    _inherit = 'hr.employee'


    _columns = {

            'passport_expiry':fields.date('Passport expiry'),

                       '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'),



    def send_expiry_email(self, cr, uid, ids=None, context=None):

        print "Inside Cron Job @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@"


        today = datetime.date.today()







        timedelta = today-passport_data




        timedelta_visa = today-visa_data




        timedelta_emirates = today-emirates_data



        timedelta_insurance = today-insurance_data





        partner_obj = self.pool.get('hr.employee')

        mail_mail = self.pool.get('mail.mail')

        mail_ids = []

#         today = datetime.datetime.now()    

#         today_month_day = '%-' + today.strftime('%m') + '-' + today.strftime('%d')

        if diff_passport<=5 or diff_visa<=5 or diff_emirates<=5 or diff_insurance<=5:

            par_id = partner_obj.search(cr,uid,[('active','=',True)])

            if par_id!=[]:


                    for val in partner_obj.browse(cr, uid, par_id):

                        email_from = val.work_email

                        name = val.name                

                        subject = "Expiry Details Alert"

                        body = _("Hello %s,\n" %(name))                 

                        body += _("\tPlease Update Your Details \n")                     

                        footer = _("Kind regards.\n")         

                        footer += _("%s\n\n"%val.company_id.name)

                        mail_ids.append(mail_mail.create(cr, uid, {

                            'email_to': email_from,

                            'subject': subject,

                            'body_html': '<pre><span class="inner-pre" style="font-size: 15px">%s<br>%s</span></pre>' %(body, footer)

                         }, context=context))

                        mail_mail.send(cr, uid, mail_ids, context=context)            

                except Exception, e:

                    print "Exception", e    

        return True


<record forcecreate="True" 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">days</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"/>




Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This platform is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.


Odoo Training Center

Access to our E-learning platform and experience all Odoo Apps through learning videos, exercises and Quizz.

Test it now

Question tools

1 follower(s)


Asked: 6/3/15, 12:37 AM
Seen: 731 times
Last updated: 6/4/15, 8:32 AM