Inheriting Auth_signup and overriding _signup_create_user function in res_users.py to raise a clean signup error if email

I am trying to inherit the _signup_create_user() function defined in the res_users class within the res_users.py file in the auth_signup module.

The inheritence code and function is as below to raise an error that removes the ugly traceback (""duplicate key value violates unique constraint "res_users_login_key" DETAIL: Key (login)=(test@test.com) already exists. "") and adds a more user friendly message, the code added to the function is in bold underneath the assert values lines. This raises an internal server error, and just seems to halt where the the traceback is called and doesn't seem to return from the function. But basically the problem isn't the lines of code because those two lines work if added into that function itself within the base code of auth_signup. So the problem is with the inheritence and I can't figure out why.

So essentially, after that long winded explanation, my question is this, how do you override a function for a model that was defined in a module's class that itself inherited the original model? Is there another import I'm missing perhaps? Should the inherit field contain a longer path to associate my class with auth_signup's module res.user inheritence and not the base res.user model. I can't find any documentation on how to override a function within a class that's already inheriting a model itself. (If that is indeed the problem here, I can only speculate at the moment for I'm not sure what is going wrong). In the meantime I'll have to just edit auth_signup itself, but I know this is not good practice editing the module itself.

If anyone can help I would be greatly appreciative, or just point me in the right direction if inheriting and overriding functions in python that have already been inherited and overriden in dependent modules.

And perhaps Odoo can just fix the function itself in auth_signup on their next commit?

# check that uninvited users may sign up if 'partner_id' not in values: if not literal_eval(ir_config_parameter.get_param(cr, uid, 'auth_signup.allow_uninvited', 'False')): raise SignupError('Signup is not allowed for uninvited users')

assert values.get('login'), "Signup: no login given for new user" assert values.get('partner_id') or values.get('name'), "Signup: no name or partner given for new user"

I could help you to develop anything and solve complex problems based on technologies, integrations and tricky stuffs mostly in Python with OpenERP/Odoo, Zato, Django and many others frameworks programming languages and technologies.

I offers consulting services to anyone with an unanswered questions or needs for customizations. Think about it, maybe it's better to have an expert to solve your issues and projects than having a full time employee trying to understand what to do an how

You just need to add a dependency with the other module that inherit the original function in your __openerp__.py. That will cause that your function get called first than the other module function. This dependency is done by put the name of the other module in the depends list of your module __openerp__.py

Another suggestion is that if you just wanna add a validation you could add only that code in your inherit function and then make a call to the super function to call the function that you are overriding

Hi Alex, thanks for the reply. I already did have the dependency for the auth_signup module in my __openerp__.py, but even if I just inherit that class and copy the function as is without changing it, leaving it as is, then assuming my function will get called first, it still throws an internal server error. I will try play around with calling the super function and see if that works rather, thanks for the suggestion. Will post the code here if I get that right.

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