Bỏ qua để đến Nội dung
Menu
Câu hỏi này đã bị gắn cờ
2 Trả lời
6025 Lượt xem

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

Is there any simple way?

Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhất

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.


Ảnh đại diện
Huỷ bỏ
Tác giả

where should I put this code?

inherit res_users model and keep inside my code.

Câu trả lời hay nhất

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.

Ảnh đại diện
Huỷ bỏ
Tác giả

where should I put this code?

Bài viết liên quan Trả lời Lượt xem Hoạt động
5
thg 3 16
4263
0
thg 8 16
2859
1
thg 3 15
5276
2
thg 11 20
9256
1
thg 5 23
2007