Odoo Help


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.


How to override the contactus class of the website_crm module to send mail instead of creating a lead?

Pascal Tremblay
on 11/3/15, 9:35 PM 711 views

Hello guys,

Our goal is to send a email to administrator instead of creating a lead via the website_crm form.

But I'm not able to override correctly the contactus class and his create_lead method to correctly send an email instead of creating a lead.

Here is my last try. It doesn't work. (error is : Model contactus_pt is declared but cannot be loaded!)

from openerp.addons.website_crm.controllers.main import contactus

class contactus_pt(osv.AbstractModel):

_inherit = ['mail.thread']

def create_lead(self, request, values, kwargs):

""" Allow to be overrided """

cr, context = request.cr, request.context

self.message_post(cr, uid, [new_id], body=_("pasdfas"), context=ctx)

return request.registry['crm.lead'].create(cr, SUPERUSER_ID, values, context=dict(context, mail_create_nosubscribe=True))

The message_post method has to work! I need it there. I will adjust all the parameters. But now, the class is not even loaded.

Please help. I'm tired of this problem!


Emipro Technologies Pvt. Ltd.

--Emipro Technologies Pvt. Ltd.--
Tiny ERP Pvt Ltd
| 6 7 8
Rajkot, India
--Emipro Technologies Pvt. Ltd.--

Being an emerging leader in IT market since 2011, Emipro Technologies Pvt. Ltd. has been providing a wide range of business solutions in Odoo & Magento. We are pleased to have a large pool of contented customers with our meticulous work in the domain of ERP & e-Commerce. A ray of relief & satisfaction to  our customers heart by our successful deployment in their organization, purely represents our success in Odoo platform. Hence, we take pride for being an Odoo partner with a vision of expanding our strategic alliances with our customers to offer them high value-added, trustworthy & cost effective solutions.


Since establishment, our business has span across 11 countries of the world. Our customers are companies of all sizes ranging from start-ups to large enterprises, who realize that they need a professional business solutions to generate revenue streams, establish proper communication channels or streamline business operations. Standing with strong determination of customer satisfaction, observing each minute detail of their business processes, providing proper guidance and moving forth to develop product accordingly adds our value and reliability among our customers. 


We are blessed with efficient, passionate & eclectic young developers who have come across almost all kinds of business profiles, working with full dedication, applying creativity & new features in existing modules and completing customer's projects successfully on predefined target. Our in-depth knowledge while giving business solutions in Odoo allows us to offer following services to our customers :


  • Consulting
  • Installation, Configuration & Customization
  • Training & Support
  • Maintenance
  • Upgradation
  • Documentation
  • Crafting community modules
  • Drafting videos on demand
  • Smart Apps development

We will be :) to welcome you @ www.emiprotechnologies.com to solve any kind of your business needs around Odoo. However we are just an inch away from you by email info@emiprotechnologies.com or a tweet to @EmiproTech

Emipro Technologies Pvt. Ltd.
On 11/3/15, 11:24 PM

Your problem is automatically resolve when you use default inheritance of the python language.

Please see the inheritance of the python and your solution in below code.

import openerp.addons.website_crm.controllers.main as website_crm_main
class contactus_pt(website_crm_main.contactus):
    def create_lead(self, request, values, kwargs):
        """ Allow to be overrided """
        cr, context = request.cr, request.context
        new_id = request.registry['crm.lead'].create(cr, SUPERUSER_ID, values, context=dict(context, mail_create_nosubscribe=True))
request.registry['crm.lead'].message_post(cr, uid, [new_id], body=_("pasdfas"), context=context)
        return new_id

Here according to python we have import main package from website_crm. And we have inherit contactus class inside our custom class "contactus_pt". 

This inheritance is a pure/basic python inheritance. Inside any web or website controller we can not make changes as like Odoo module. We have to use default python concept.

This is very important and less knowing things which I am going to share over here.

I am sure your issue will resolve.


Your inheritance works well. the class contactus_pt is loaded. But the message_post method doesn't work. I get this error ««« 'contactus (extended by contactus_pt)' object has no attribute 'message_post' »»». This is the real problem because message_post is not a real method of the class website_crm_main.contactus. How to add this new message_post method to the class? THanks to you

Pascal Tremblay
on 11/4/15, 8:12 AM

Hello, I have just update my answer. It is so simple no need of the message_post method. Just have a look on the updated answer.

Emipro Technologies Pvt. Ltd.
on 11/4/15, 8:40 AM

I have tried your code. Thanks. But I don't receive the message. The new_id variable take the id of the new created lead. ok But I don't see any message anywhere. I don't receive email.

Pascal Tremblay
on 11/5/15, 10:58 PM

I forgot to say that I have no error in the log. But i don't receive any meSsage. Where should the message be?

Pascal Tremblay
on 11/5/15, 11:22 PM

you can see one message inside communication section of that newly created lead.

Emipro Technologies Pvt. Ltd.
on 11/6/15, 4:17 AM

Ok, I open the new created lead and I see below it, in the communication section, the message posted. You answered my question very well. Thanks.

Pascal Tremblay
on 11/6/15, 11:18 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)


Asked: 11/3/15, 9:35 PM
Seen: 711 times
Last updated: 11/6/15, 11:17 AM