Skip to Content
Menu
This question has been flagged
5 Replies
3407 Views

I need a way to send me an notification when a user is getting created.

Is there any way to easly do that?

For example:

When a user is created, it should send me to my email (test@test.com) an email that says: user ***** is created.


Thanks for the help.

Avatar
Discard
Author Best Answer

When I make a modul with your code, I'm getting this error :

Traceback (most recent call last):
  File "/usr/lib/python2.7/dist-packages/openerp/http.py", line 537, in _handle_exception
    return super(JsonRequest, self)._handle_exception(exception)
  File "/usr/lib/python2.7/dist-packages/openerp/http.py", line 574, in dispatch
    result = self._call_function(**self.params)
  File "/usr/lib/python2.7/dist-packages/openerp/http.py", line 310, in _call_function
    return checked_call(self.db, *args, **kwargs)
  File "/usr/lib/python2.7/dist-packages/openerp/service/model.py", line 118, in wrapper
    return f(dbname, *args, **kwargs)
  File "/usr/lib/python2.7/dist-packages/openerp/http.py", line 307, in checked_call
    return self.endpoint(*a, **kw)
  File "/usr/lib/python2.7/dist-packages/openerp/http.py", line 803, in __call__
    return self.method(*args, **kw)
  File "/usr/lib/python2.7/dist-packages/openerp/http.py", line 403, in response_wrap
    response = f(*args, **kw)
  File "/usr/lib/python2.7/dist-packages/openerp/addons/web/controllers/main.py", line 948, in call_button
    action = self._call_kw(model, method, args, {})
  File "/usr/lib/python2.7/dist-packages/openerp/addons/web/controllers/main.py", line 936, in _call_kw
    return getattr(request.registry.get(model), method)(request.cr, request.uid, *args, **kwargs)
  File "/usr/lib/python2.7/dist-packages/openerp/api.py", line 268, in wrapper
    return old_api(self, *args, **kwargs)
  File "/usr/lib/python2.7/dist-packages/openerp/addons/base/module/module.py", line 447, in button_immediate_install
    return self._button_immediate_function(cr, uid, ids, self.button_install, context=context)
  File "/usr/lib/python2.7/dist-packages/openerp/api.py", line 268, in wrapper
    return old_api(self, *args, **kwargs)
  File "/usr/lib/python2.7/dist-packages/openerp/addons/base/module/module.py", line 495, in _button_immediate_function
    registry = openerp.modules.registry.RegistryManager.new(cr.dbname, update_module=True)
  File "/usr/lib/python2.7/dist-packages/openerp/modules/registry.py", line 370, in new
    openerp.modules.load_modules(registry._db, force_demo, status, update_module)
  File "/usr/lib/python2.7/dist-packages/openerp/modules/loading.py", line 355, in load_modules
    loaded_modules, update_module)
  File "/usr/lib/python2.7/dist-packages/openerp/modules/loading.py", line 255, in load_marked_modules
    loaded, processed = load_module_graph(cr, graph, progressdict, report=report, skip_modules=loaded_modules, perform_checks=perform_checks)
  File "/usr/lib/python2.7/dist-packages/openerp/modules/loading.py", line 176, in load_module_graph
    _load_data(cr, module_name, idref, mode, kind='data')
  File "/usr/lib/python2.7/dist-packages/openerp/modules/loading.py", line 118, in _load_data
    tools.convert_file(cr, module_name, filename, idref, mode, noupdate, kind, report)
  File "/usr/lib/python2.7/dist-packages/openerp/tools/convert.py", line 890, in convert_file
    fp = misc.file_open(pathname)
  File "/usr/lib/python2.7/dist-packages/openerp/tools/misc.py", line 202, in file_open
    return _fileopen(name, mode=mode, basedir=rtp, pathinfo=pathinfo, basename=basename)
  File "/usr/lib/python2.7/dist-packages/openerp/tools/misc.py", line 249, in _fileopen
    raise IOError('File not found: %s' % basename)
IOError: File not found: user_mail/
Avatar
Discard

Hello wizardz, I just created module as per your requirement, can you give me your email ID So, I will forward you my module.

Best Answer

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

Updated Code

class res_users(osv.Model):

_inherit = 'res.users'

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 = """<html><head><title>Confirmation</title></head><body><h1>Welcome to board </h1><p>Hello ${object.name},</p></body></html>"""

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.

Avatar
Discard
Author

second write below? Where I need to write this code ? In a new module? or where?????

You need to inherit res_users model and paste my above code.

Please check my update code, Hope that code help for you.

Related Posts Replies Views Activity
2
Feb 16
4933
0
Aug 16
2154
1
Mar 15
4503
2
Nov 20
7984
1
May 23
973