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 to send notification/internal message from code

By
Dr Obx
on 2/2/16, 6:13 AM 682 views

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


you can use the mail.message model.

Atul Arvind
on 2/2/16, 6:43 AM
0
Logicious
On 2/9/16, 7:51 AM

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)

0
Dr Obx
On 2/2/16, 11:37 AM

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)

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/2/16, 6:13 AM
Seen: 682 times
Last updated: 2/9/16, 7:51 AM