Skip to Content
Menu
This question has been flagged
1 Reply
2948 Views

i have a custome module like project .i need to assiagn work to employee and that user need to get notification in his message .menu or anywhere this is my requirement.how can solve it?pls explain the solution

Avatar
Discard
Best Answer

You have first to set the outgoing mail server on your odoo settings and test it is working

You need also to create an email template to use when sending to employees

here is a code I used to send emails to employees when the status of a document is changed. Employees are assinged to users in the systme

    def mailing(self, cr, uid, ids,vals,context=None):
domain=[('name','=','MY_TEMPLATE_NAME')]
templates = self.pool.get('email.template').search(cr,uid,domain)
if not templates:
return
template = self.pool.get('email.template').browse(cr,uid,templates[0])
if template.email_to:
#template.body_html = 'this is a test for the x'
pr_id = self.browse(cr,uid,ids,context=context)[0].id
self.pool.get('email.template').send_mail(cr, uid, template.id, pr_id, True, context=context)
def write(self, cr, uid, ids, vals, context=None):
#for test only, comment when test succeeded
self.test = False
if self.test:
self.mailing(cr,uid,ids,vals,context)
return
#for test only, comment when test succeeded

it is triggered in the write method of a view after changing the status of the document

Here is the email_to field and the body_html fields

email_to
${object.next_resp.email}
body_html
Dear ${object.next_resp.name}, </p> <p> The document ${object.name} status has been changed to ${object.state}, pls check and take the appropriate action </p> 
this is the definition of next_resp field

        'next_resp':fields.many2one('res.users','Next responsible',),
and I'm using the email field in res.users.
I designed the code to save the user id in the 'next_resp' field that has to be notified when the document status is changed.

I posted my own solution, you have your own names and scenarios. I think this will be guide you for your similar case. You can add more specific questions in the comments until your solution work.


Avatar
Discard