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

How Can I send me a message when I create a user for a check?

By
wizardz
on 3/29/16, 4:42 AM 369 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.

0
wizardz
On 3/30/16, 2:52 AM

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/

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

Ankit H Gandhi(AHG)
on 3/30/16, 4:00 AM
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 3/29/16, 6:39 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

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.

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

wizardz
on 3/29/16, 7:59 AM

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

Ankit H Gandhi(AHG)
on 3/29/16, 8:31 AM

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

Ankit H Gandhi(AHG)
on 3/29/16, 8:36 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: 3/29/16, 4:42 AM
Seen: 369 times
Last updated: 3/30/16, 2:52 AM