Odoo Help


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 1,222 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!


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

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.


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

1 follower(s)


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