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
Odoo is the world's easiest all-in-one management software.
It includes hundreds of business apps:
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
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?
You can call this method from write/create method.
Do you want to send mail when particular field is updated?
yes sudhir
where is this section "write/create method" ?? in settings ?
thank you but can you explain in detail? plz
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.
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)
thx sudhir but where to put this code? and how to call this method ? thx