This question has been flagged
1 Reply
6732 Views

hello every one

I have design and build birthday template but how to send the birthday wish through email template in OpenERP ..??

pls can any one help me how to do this..??

Avatar
Discard
Author Best Answer

We need to create the sample email template for send the email to the specific person

demo for the customer (partner) email template

PARTNER EMAIL TEMPLATE ::

ADD  FOLLOWING LINE IN YOUR .XML  FILE

        <record id="email_template_birthday" model="email.template">
            <field name="name">Birthday Reminder Send by Chaitanya Dasadiya</field>
            <field name="email_from">${object.company_id.email or 'noreply@localhost'}</field>
            <field name="subject">Birthday Reminder</field>
            <field name="email_to">${object.email}</field>
            <field name="model_id" ref="base.model_res_partner"/>
            <field name="auto_delete" eval="False"/>
            <field name="lang">${object.lang}</field>
            <field name="body_html"><![CDATA[
<div style="font-family: 'Lucica Grande', Ubuntu, Arial, Verdana, sans-serif; font-size: 12px; color: rgb(34, 34, 34); background-color: #FFF; ">

    <p>Hello ${object.name},</p>
    <p style="border-left: 1px solid #8e0000; margin-left: 30px;">
       &nbsp;&nbsp;<strong> Happy Birthday !!!</strong><br />
    </p>  
    <br/><p style="border-left: 1px solid #8e0000; margin-left: 30px;">
 I hope your birthday is the beginning of Another Great Year full of happiness.
Have a wonderful day!</p>
    <br/>
    <br/>
</div>
            ]]></field>

        </record>

SET THE SCHEDULED ACTION (CRONE JOB)

        <record model="ir.cron" id="ir_cron_cust_birthday_reminder_every_week">
            <field name="name">Birthday Reminder</field>
            <field name="interval_number">1</field>
            <field name="interval_type">days</field>
            <field name="numbercall">-1</field>
            <field name="doall" eval="False"/>
            <field name="model" eval="'res.partner'"/>
            <field name="function" eval="'cron_customer_birthday_reminder'"/>
            <field name="args" eval="'()'"/>
        </record>

ADD THE FUNCTION IN .py File

import time
from datetime import datetime
from openerp.osv import fields, osv
from openerp.tools import DEFAULT_SERVER_DATETIME_FORMAT
from dateutil.relativedelta import relativedelta

class res_partner(osv.osv):
    _inherit ="res.partner"
    _columns = {
        'birth_date': fields.date('Birthday'),
    }

    def cron_customer_birthday_reminder(self, cr, uid, context=None):
        if context is None:
            context = {}
        birthday_date =False
        template_id = self.pool.get('ir.model.data').get_object_reference(cr, uid, 'customer_birthday_anniversary_reminder', 'email_template_birthday')[1]
        cron_id = self.pool.get('ir.model.data').get_object_reference(cr, uid, 'customer_birthday_anniversary_reminder', 'ir_cron_cust_birthday_reminder_every_week')[1]
        cron_data=self.pool.get('ir.cron').browse(cr, 1, [cron_id])[0]
        start = datetime.strptime(cron_data.nextcall,'%Y-%m-%d %H:%M:%S')
        cust_ids=self.search(cr,uid,[],context)
        if cust_ids:
            for cust in cust_ids:
                cust_id=self.browse(cr,uid,cust)
                birthday_date =cust_id.birth_date and datetime.strptime(cust_id.birth_date,'%Y-%m-%d')
                if birthday_date and birthday_date.month==start.month and  birthday_date.day == start.day:
                    self.pool.get('email.template').send_mail(cr, uid, template_id, cust_id.id, force_send=True, context=context)
        return True

same way we need to add the birthday field in customer form view as well

If you set the above file successfully then the the scheduled action function will be called based on your interval_type

which you are mentioned in your scheduled action.

Hear is the customer get the email template based on its day interval setted in scheduled action.


 

Avatar
Discard

Wat s dis

very good example..

Author

@aci aisha This sample demo for the customer to send email template when the customer receive email on his or her birthday @LIBU Thanks For Your Comment ..:)