How do I send an email notification when creating a Project Issue? Odoo 9

Hi, I created a new problem, but I can’t get an email notification.

How do you do this?

Edited

I am adding the code below, but I cannot receive message_follower_ids from myself to send emails.

class project_issue(osv.osv):
_inherit = 'project.issue'
_columns = {}

def create(self, cr, uid, vals, context=None):
    res = super(project_issue, self).create(cr, uid, vals, context=context)
    return res

Update

I updated the code to get subscribers email address and sent emails successfully, but they are sent to one email.

And His object.name is the name of the partner, but I want it to be the name of the problem.

def create(self, cr, uid, vals, context=None):
    res = super(project_issue, self).create(cr, uid, vals, context=context)
    issue = self.pool.get('project.issue').browse(cr, uid, res, context=context)

    template = self.pool.get('ir.model.data').get_object(cr, uid, 'customized_project', 'email_template_customer_auto')

    for follower in issue.message_partner_ids:
        self.pool.get('mail.template').send_mail(cr, uid, template.id, follower.id, force_send=True, raise_exception=True, context=context)

here is the email template

<?xml version="1.0" encoding="utf-8"?>
<openerp>
  <data noupdate="1">
      <!--Email template-->
      <record id="email_template_customer_auto" model="mail.template">
          <field name="name">Send email notification for issue creation</field>
          <field name="email_from">${object.company_id and object.company_id.email or ''}</field>
          <field name="subject">New Issue created ${object.name}</field>
          <field name="email_to">${object.email|safe}</field>
          <field name="model_id" ref="model_project_issue"/>
          <field name="auto_delete" eval="True"/>
          <field name="lang">${object.lang}</field>
          <field name="body_html"><![CDATA[
            """
            Write here a body of email using HTML tag.....
            """
            ]]>
          </field>
      </record>
   </data>
</openerp>
+4
source share
1 answer

from openerp.osv import osv, fields
import logging

class project_issue(osv.osv):
    _inherit = 'project.issue'
    _columns = {}

    issue = ''
    templtate = ''

    def create(self, cr, uid, vals, context=None):
        res = super(project_issue, self).create(cr, uid, vals, context=context)

        self.issue = self.pool.get('project.issue').browse(cr, uid, res, context=context)

        manager = self.issue.project_id.user_id.partner_id.id

        assignTo = self.issue.user_id.partner_id.id

        post_vars = {
            'subject': ("Issue {} has been created".format(self.issue.name)),
            'body': ("Issue {} has been created".format(self.issue.name)),
            'partner_ids': [(4, manager)],
        }
        thread_pool = self.pool.get('mail.thread')
        thread_pool.message_post(cr, uid, False,
                                 context=context,
                                 **post_vars)
        return res
+1

Source: https://habr.com/ru/post/1680613/


All Articles