This question has been flagged
3 Replies
12126 Views

Can anyone guide me how to auto send a birthday email for every customer on his/her birthday. My idea is to use a scheduler which checks if today is someone's birthdate and sends an email. I am a novice in this and detailed help would be much appreciated....

Avatar
Discard
Best Answer

You can create scheduler and in the method search the record with the domin condition dob is equal to current date month and day. If record find then send mail using mai.mail object.

Example,

To create the method in custom module:-

from openerp.osv import fields,osv
import datetime

class res_partner(osv.osv):
    _inherit = 'res.partner'

def send_birthday_email(self, cr, uid, ids=None, context=None):
        partner_obj = self.pool.get('res.partner')
        mail_mail = self.pool.get('mail.mail')
        mail_ids = []
        today = datetime.datetime.now()    
        today_month_day = '%-' + today.strftime('%m') + '-' + today.strftime('%d')    
        par_id = partner_obj.search(cr, uid, [ ('customer','=',True),('birthdate','like',today_month_day)])
        if par_id:
            try:
                for val in partner_obj.browse(cr, uid, par_id):
                    email_from = val.email
                    name = val.name                
                    subject = "Birthday Wishes"
                    body = _("Hello %s,\n" %(name))                 
                    body += _("\tWish you Happy Birthday\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 None

In the xml File Create Scheduler

 <record forcecreate="True" id="ir_cron_employee_birth" model="ir.cron">
            <field name="name">Employee Birthday 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="'res.partner'" name="model"/>
            <field eval="'send_birthday_email'" name="function"/>
            <field eval="'()'" name="args"/>
        </record>

Or

In Openerp using Menu Setting - > Configuration -> Scheduler -> Scheduler Action Create scheduler.

 

 

 

Avatar
Discard
Best Answer

Just create a scheduler to check dob of customers if date is today create an email. you do not need to send email. there is other scheduler to send email. It will send created email automatically at scheduled interval of time but if you want you can send email too by same scheduler like you said. All depends on you, do it how you want. Let me know if any help is needed.

Avatar
Discard
Best Answer

Hi all ,

I have similar type of tasks to do . i want to send auto E-mail to all customers after a week?

procedure?anyone? 

Avatar
Discard