Skip to Content
Menu
This question has been flagged
3 Replies
13273 Views

Looking for answer for this question. How can I send notification/message directly to the selected user from code ?


Avatar
Discard

you can use the mail.message model.

Best Answer

make one button in .xml file and add the funtion definition in you .py file.

i just pasted my code here, you can refer this.

ir_mail_server = self.pool.get('ir.mail_server')

if not ir_mail_server.browse(cr,uid,2).smtp_user:

raise osv.except_osv(_('Warning!'), _("Please Configure Email from IR MAIL SERVER!"))

if not data.partner_id.email:

raise osv.except_osv(_('Warning!'), _("Please Configure Email for Customer!"))

if data.partner_id.email:

signature_company = self.pool.get('res.users').browse(cr,uid,uid).signature

email_msg = msg_config_obj.search(cr,uid,[('message_seq','=','Seq_9')])

if len(email_msg):

get_msg_data=msg_config_obj.browse(cr,uid,email_msg).tmp_dsn

email_get_subject_msg_data = msg_config_obj.browse(cr,uid,email_msg).name

if email_get_subject_msg_data.find('%Customer_Name%')!=-1:

email_subject_data = email_get_subject_msg_data.replace('%Customer_Name%',partner)

else:

email_subject_data = email_get_subject_msg_data

if email_subject_data.find('%Name%')!=-1:

email_subject_data = email_subject_data.replace('%Name%',smae)

else:

email_subject_data = email_subject_data

if get_msg_data.find('%Client_name%')!=-1:

msg_data=get_msg_data.replace('%Client_name%',partner)

else:

msg_data =get_msg_data

email_ids = []

msg = ir_mail_server.build_email(

email_from=ir_mail_server.browse(cr,uid,2).smtp_user,

email_to=[data.partner_id.email],

subject='**'+email_subject_data,

body='++'+msg_data+'<div>'+signature_company+'</div>' ,

body_alternative='++'+msg_data +'<div>'+signature_company+'</div>' ,

reply_to=[data.partner_id.email],

attachments=[],

object_id=[],

subtype='html'

)

res = ir_mail_server.send_email(cr, uid,msg,mail_server_id=2,context=context)

Avatar
Discard
Author Best Answer

recipient_ids = [1, 2, 3]

recipient_links = [(4, partner_id) for partner_id in recipient_ids]

model_data_obj = self.pool.get('ir.model.data')

ref = model_data_obj.get_object_reference(cr, uid, 'mail', 'mt_comment')

message_data = {

'type': 'notification',

'subject': "Product request",

'body': email',

'partner_ids': recipient_links,

'subtype_id': res,

}

msg_obj = self.pool.get('mail.message')

msg_obj.create(cr, uid, message_data)

Avatar
Discard
Related Posts Replies Views Activity
1
Aug 23
12544
1
Aug 23
11037
1
Jul 23
7218
4
Apr 23
8675
2
Feb 23
17588