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

Email Notification when creating user

By
wizardz
on 2/11/16, 9:15 AM 513 views

It is possible to make a email notification or to send an email when I create a new user?

Is there any simple way?

0

Ankit H Gandhi(AHG)

--Ankit H Gandhi(AHG)--
996
| 5 3 6
Rajkot, India
--Ankit H Gandhi(AHG)--

Learning Python..

Ankit H Gandhi(AHG)
On 2/14/16, 8:52 AM

Dear Wizardz,


First you need to set Outgoing Mail Server from settings menu.

Settings > Technical > Email > Outgoing Mail Server.

or

refer below link for outgoing mail configration

http://www.odoo.yenthevg.com/configure-outgoing-mailservers/

Second write below.

def create(self, cr, uid, vals, context=None):

result = super(res_users, self).create(cr, uid, vals, context=context)

template_obj = self.pool.get('email.template')

group_model_id = self.pool.get('ir.model').search(cr, uid, [('model', '=', 'res.users')])[0]

body_html = '''Message whatever you want to send'''

template_data = {

'model_id': group_model_id,

'name': 'Template Name',

'subject' : 'Subject for your email',

'body_html': body_html,

'email_from' : 'from email id',

'email_to' : 'to email id',

}

template_id = template_obj.create(cr, uid, template_data, context=context)

template_obj.send_mail(cr, uid, template_id, result, force_send=True, context=context)

return result

Hope above code help for you.

Note: please manage proper indention in method.

Cheers,

Ankit H Gandhi.


where should I put this code?

wizardz
on 2/16/16, 2:25 AM

inherit res_users model and keep inside my code.

Ankit H Gandhi(AHG)
on 2/16/16, 5:58 AM
0
Jo
On 2/12/16, 4:47 AM

Hi Wizardz,

Try to inherit 'res.users' object and override create method.

class res_users(models.Model):

_inherit = 'res.users'

def create(self, cr, uid, vals, context=None):

user_id = super(res_users, self).create(cr, uid, vals, context=context)

user = self.browse(cr, uid, user_id, context=context)

if user.partner_id.company_id:

user.partner_id.write({'company_id': user.company_id.id})

# The below code to send invitation mail

self.action_reset_password(cr, uid, [user_id], context=context)

return user_id

I hope this will help you.

where should I put this code?

wizardz
on 2/16/16, 2:25 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

1 follower(s)

Stats

Asked: 2/11/16, 9:15 AM
Seen: 513 times
Last updated: 2/16/16, 2:24 AM