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.

1

send mail updated field

By
Yaha
on 6/5/13, 6:49 AM 1,257 views

how to send mail if a field is updated ?

for example in project.task, i want to send mail if assigned to is updated ?

You can help me plzzz ?

Thx

4

Sudhir Arya (SA)

--Sudhir Arya (SA)--
10150
| 6 8 8
Ahmedabad, India
--Sudhir Arya (SA)--

Working as an OpenERP/Odoo developer and a Team Leader 

Top 5 Odoo contributor On Stackoverflow

LinkedIn

Blog

Stackoverflow

Sudhir Arya (SA)
On 6/5/13, 7:25 AM

First create Email Template for object project.task and then call following method either from create or write by overwriting them.

def send_mail(self, cr, uid, ids, context=None):
    template_ids = email_template_obj.search(cr, uid, [('model_id.model', '=', 'project.task')])
    if template_ids:
        values = email_template_obj.generate_email(cr, uid, template_ids[0], id, context=context)
        values['subject'] = "your_subject"
        values['email_to'] = "email_to_address"
        values['email_cc'] = "email_cc_address"
        values['body_html'] = "your_html_message"
        values['body'] = "your_html_message"
        mail_mail_obj = self.pool.get('mail.mail')
        msg_id = mail_mail_obj.create(cr, uid, values, context=context)
        mail_mail_obj.send(cr, uid, [msg_id], context=context)
    return True

Overwrite write method in project_task class:

def write(self, cr, uid, ids, vals, context=None):
    if vals.get('user_id', False):
        self.send_mail(cr, uid, ids, context=context)
    return super(project_task, self).write(cr, uid, ids, vals, context=context)

Mail will be sent when you will change Assigned to in Project Task and click on Save.

thx sudhir but where to put this code?

Yaha
on 6/5/13, 7:48 AM

You can call this method from write/create method.

Sudhir Arya (SA)
on 6/5/13, 7:52 AM

Do you want to send mail when particular field is updated?

Sudhir Arya (SA)
on 6/5/13, 7:57 AM

yes sudhir

Yaha
on 6/5/13, 3:27 PM

where is this section "write/create method" ?? in settings ?

Yaha
on 6/5/13, 3:32 PM

thank you but can you explain in detail? plz

Yaha
on 6/6/13, 9:28 AM

You have to put this code in your custom module if you are creating any custom module or you can put it in project/project.py file under class project_task. Then once restart your server.

Sudhir Arya (SA)
on 6/6/13, 5:51 PM
0
Yaha
On 6/5/13, 7:48 AM

thx sudhir but where to put this code? and how to call this method ? thx

0
Yaha
On 6/6/13, 3:00 PM

i put this code in setting ==> action server ==> python code ==> project.task ==> and i copy this code and nothing ...

def write(self, cr, uid, ids, vals, context=None): if vals.get('user_id', False): self.send_mail(cr, uid, ids, context=context) return super(project_task, self).write(cr, uid, ids, vals, context=context)

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

2 follower(s)

Stats

Asked: 6/5/13, 6:49 AM
Seen: 1257 times
Last updated: 3/16/15, 8:10 AM