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.

1

How to send email and notification url?

By
Cpueyo
on 5/22/13, 1:46 PM 2,166 views

Hello!

I try to send a notification and e-mail to specified users, or groups, when i click a button. I've already gotten notifications work, but my e-mails are not sent, I do not know what I'm doing wrong. I've tried also send a URL for the user to directly access, but I can't get the browser URL, instead of leaving written manually.

This is my code.

# Send E-Mail
def enviar_email(self, cr, uid, user_ids, text=None, context=None):
    osv.logging.log(100, "[Alca] enviar_email:hr_expense:hr_expense_nervia")
    mail_compose = self.pool.get('mail.compose.message')

    for user in user_ids:
        compose_id = mail_compose.create(cr, user,
            {'subject': 'Asunto', 'body': 'Este es mi mensaje', 'partner_ids': user_ids},
            {'default_composition_mode': 'mass_mail', 'default_starred': True})
        mail_compose.send_mail(cr, user, [compose_id])

# Send Notification
def send_notificacion(self, cr, uid, ids, text=None, context=None):
    osv.logging.log(100, "[Alca] send_notificacion:hr_expense:hr_expense_nervia")

    if context == None:
        context = {}

    context.update({'default_starred': True})

    for record in self.browse(cr, uid, ids, context=context):
        notify_to = []
        notify_to = self._get_autorized_contables(cr, uid, context)
        notify_to.append(record.employee_id.user_id.id)
        notify_to.append(int(record.autorizador))

        text = text + (" <a href='http://192.168.10.227:7069/?db=desarrollo#id=%s&view_type=form&model=hr.expense.expense'>Procesar</a>" % (record.id))

        self.enviar_email(cr, uid, notify_to, text, context)

        # Loguea una nota en la nota de gastos
        self.message_post(cr, uid, [record.id], _(text), context=context)
        # Suscribe a los usuarios y les manda una notificacion a la bandeja de entrada
        self.message_subscribe_users(cr, uid, [record.id], user_ids=notify_to, context=context)

I resolve the question about how to send email. :)

    from openerp import tools
    # Send E-Mail
    def enviar_email(self, cr, uid, user_ids, asunto = None, text=None, context=None):
            mUsr = self.pool.get("res.users")
            for usr in user_ids:
                user = mUsr.browse(cr, uid, usr)
                if user.email:
                    subject = "[OpenERP] Notificacion: "+str(asunto)
                    body = text
                    <a href="mailto:tools.email_send('noreply@openerp.com'">tools.email_send('noreply@openerp.com'</a>, [user.email, ], subject, body)
Cpueyo
on 6/17/13, 8:03 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: 5/22/13, 1:46 PM
Seen: 2166 times
Last updated: 3/16/15, 8:10 AM