Odoo Help

1

create a module for automatic send email when customer has been created ?

By
Ahmed elbarbary
on 8/12/14, 6:24 AM 5,425 views

hi, i want to send automatic email when customer has been created. 

these are the modules files:

__init__.py

import res_partner

------------------------------------------------------------------------------------------------------------------------------------------------------------

__openerp.py

# -*- coding: utf-8 -*-
{
    "name" : "Automatical email to customer",
    "version" : "1.0",
    "author" : "Author name",
    "description": """
        Sends automatic when customer created
    """,
    "website" : "Author website name",
    "category" : "",
    'depends': ['base'],
    "data" : ['email_template_customer_auto.xml',],
    'js': [], 
    'css': [

    ],
    'qweb': [
    ],
    "active": False,
    "installable": True,

}

------------------------------------------------------------------------------------------------------------------------------------------------------------

res_partner.py

from osv import osv, fields

class res_partner(osv.osv):
    _inherit = 'res.partner'
    _columns = {}

    def create(self, cr, uid, vals, context=None):
        res = super(res_partner, self).create(cr, uid, vals, context=context)
        if vals:
            template = self.pool.get('ir.model.data').get_object(cr, uid, 'customer_auto_email', 'email_template_customer_auto')
            mail_id = self.pool.get('email.template').send_mail(cr, uid, template.id, res , force_send=True)

        return res

res_partner()

--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

 

email_template_customer_auto.xml

<?xml version="1.0" encoding="utf-8"?>
<openerp>
  <data noupdate="1">

        <!--Email template-->
        <record id="email_template_customer_auto" model="email.template">
            <field name="name">Send auto email</field>
            <field name="email_from">${object.company_id and object.company_id.email or ''}</field>
            <field name="subject">New Customer created ${object.name}</field>
            <field name="email_to">${object.company_id and object.company_id.email or ''}</field>
            <field name="model_id" ref="base.model_res_partner"/>
            <field name="auto_delete" eval="True"/>
            <field name="lang">${object.lang}</field>
            <field name="body_html"><![CDATA[
             
                THIS IS AN AUTOMATED EMAIL. DO NOT REPLY.

Hello,

We are here to inform you that the request [[object.name]] you submitted on [[object.request_date]] with the following data:

        | Request - Details
        |=========================
        | Number: [[object.id]]
        |=========================
        | Responsible Person: [[object.responsible_name.name]]
        | Request description: [[object.request_description]]
        | Stating reasons: [[object.stating_reasons]]
        |=========================
        | Notes: [[object.notes]]


Has not been confirmed and is closed.

If you have any question, do not hesitate to contact your supervisor.

Thank you!           
            ]]></field>
        </record>
  
  </data>
</openerp>

------------------------------------------------------------------------------------------------------------------------------------------------------------

i istall the module but when i create a new customer that error appears :

OpenERP Server Error

Client Traceback (most recent call last): File "/opt/openerp/server/openerp/addons/web/http.py", line 204, in dispatch response["result"] = method(self, **self.params) File "/opt/openerp/server/openerp/addons/web/controllers/main.py", line 1128, in call_kw return self._call_kw(req, model, method, args, kwargs) File "/opt/openerp/server/openerp/addons/web/controllers/main.py", line 1120, in _call_kw return getattr(req.session.model(model), method)(*args, **kwargs) File "/opt/openerp/server/openerp/addons/web/session.py", line 42, in proxy result = self.proxy.execute_kw(self.session._db, self.session._uid, self.session._password, self.model, method, args, kw) File "/opt/openerp/server/openerp/addons/web/session.py", line 30, in proxy_method result = self.session.send(self.service_name, method, *args) File "/opt/openerp/server/openerp/addons/web/session.py", line 103, in send raise xmlrpclib.Fault(openerp.tools.ustr(e), formatted_info) Server Traceback (most recent call last): File "/opt/openerp/server/openerp/addons/web/session.py", line 89, in send return openerp.netsvc.dispatch_rpc(service_name, method, args) File "/opt/openerp/server/openerp/netsvc.py", line 296, in dispatch_rpc result = ExportService.getService(service_name).dispatch(method, params) File "/opt/openerp/server/openerp/service/web_services.py", line 626, in dispatch res = fn(db, uid, *params) File "/opt/openerp/server/openerp/osv/osv.py", line 190, in execute_kw return self.execute(db, uid, obj, method, *args, **kw or {}) File "/opt/openerp/server/openerp/osv/osv.py", line 132, in wrapper return f(self, dbname, *args, **kwargs) File "/opt/openerp/server/openerp/osv/osv.py", line 199, in execute res = self.execute_cr(cr, uid, obj, method, *args, **kw) File "/opt/openerp/server/openerp/osv/osv.py", line 187, in execute_cr return getattr(object, method)(cr, uid, *args, **kw) File "/opt/openerp/server/openerp/addons/customer_auto_email/res_partner.py", line 10, in create template = self.pool.get('ir.model.data').get_object(cr, uid, 'customer_auto_email', 'email_template_customer_auto') File "/opt/openerp/server/openerp/addons/base/ir/ir_model.py", line 884, in get_object res_model, res_id = self.get_object_reference(cr, uid, module, xml_id) File "/opt/openerp/server/openerp/tools/cache.py", line 18, in lookup r = self.lookup(self2, cr, *args) File "/opt/openerp/server/openerp/tools/cache.py", line 46, in lookup value = d[key] = self.method(self2, cr, *args) File "/opt/openerp/server/openerp/addons/base/ir/ir_model.py", line 876, in get_object_reference data_id = self._get_id(cr, uid, module, xml_id) File "/opt/openerp/server/openerp/tools/cache.py", line 18, in lookup r = self.lookup(self2, cr, *args) File "/opt/openerp/server/openerp/tools/cache.py", line 46, in lookup value = d[key] = self.method(self2, cr, *args) File "/opt/openerp/server/openerp/addons/base/ir/ir_model.py", line 869, in _get_id raise ValueError('No such external ID currently defined in the system: %s.%s' % (module, xml_id)) ValueError: No such external ID currently defined in the system: customer_auto_email.email_template_customer_auto

----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

4

Hi,

Please see the ID into xml file is : "email_template_auto_customer" and you are using the ID for fetch that record is : "email_template_customer_auto".

1) So, you need to change into following code : 

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

2) Or you need to change the ID into xml record as like below :

<record id="email_template_customer_auto" model="email.template">

0
Ahmed elbarbary
On 8/12/14, 6:48 AM

thank you very much, it works now. small changes can make a big difference

 do u have any idea about what i have change in this module if i want it to send a mail to the company if "a project created" not customer ??

hi chirag , do u have any idea about what i have change in this module if i want it to send a mail to the company if "a project created" not customer ??

Ahmed elbarbary
on 8/12/14, 10:03 AM

Hi, I have write down the answer for the project. Just have a look and make it running.

Emipro Technologies Pvt. Ltd.
on 8/13/14, 7:42 AM

thank you for the second time chirag

Ahmed elbarbary
on 8/13/14, 8:29 AM

your always welcome :)

Emipro Technologies Pvt. Ltd.
on 8/13/14, 8:46 AM

About This Community

This platform 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.

Register

Odoo Training Center

Access to our E-learning platform and experience all Odoo Apps through learning videos, exercises and Quizz.

Test it now

Question tools

3 follower(s)

Stats

Asked: 8/12/14, 6:24 AM
Seen: 5425 times
Last updated: 4/5/16, 12:44 AM