Skip to Content
Menu
This question has been flagged
1 Reply
5583 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!


Avatar
Discard
Best Answer

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.

Thanks. 


Avatar
Discard
Author

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

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.

Author

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.

Author

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

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

Author

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.

Related Posts Replies Views Activity
1
Nov 15
4345
0
Jan 21
1432
0
Mar 19
4077
2
Jul 18
27319
0
Feb 16
3365