Se rendre au contenu
Menu
Cette question a été signalée
1 Répondre
6355 Vues

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
Ignorer
Meilleure réponse

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
Ignorer
Auteur

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.

Auteur

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.

Auteur

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.

Auteur

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.

Publications associées Réponses Vues Activité
1
nov. 15
5257
0
juin 25
607
1
mai 25
1391
0
janv. 21
2447
0
mars 19
5268