Odoo Help

Welcome!

This community 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.

0

how to send the wishes for birthday via email template ..??

By
Dasadiya Chaitanya
on 2/19/14, 2:36 AM 2,537 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..??

0
Dasadiya Chaitanya
On 2/2/15, 4:40 AM

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.


 

Wat s dis

aci aisha
on 2/2/15, 4:44 AM

very good example..

Odoo
on 2/2/15, 5:18 AM

@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 ..:)

Dasadiya Chaitanya
on 2/23/15, 2:17 AM

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 community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

0 follower(s)

Stats

Asked: 2/19/14, 2:36 AM
Seen: 2537 times
Last updated: 3/16/15, 8:10 AM