Skip to Content
Odoo Menu
  • Sign in
  • Try it free
  • Apps
    Finance
    • Accounting
    • Invoicing
    • Expenses
    • Spreadsheet (BI)
    • Documents
    • Sign
    Sales
    • CRM
    • Sales
    • POS Shop
    • POS Restaurant
    • Subscriptions
    • Rental
    Websites
    • Website Builder
    • eCommerce
    • Blog
    • Forum
    • Live Chat
    • eLearning
    Supply Chain
    • Inventory
    • Manufacturing
    • PLM
    • Purchase
    • Maintenance
    • Quality
    Human Resources
    • Employees
    • Recruitment
    • Time Off
    • Appraisals
    • Referrals
    • Fleet
    Marketing
    • Social Marketing
    • Email Marketing
    • SMS Marketing
    • Events
    • Marketing Automation
    • Surveys
    Services
    • Project
    • Timesheets
    • Field Service
    • Helpdesk
    • Planning
    • Appointments
    Productivity
    • Discuss
    • Approvals
    • IoT
    • VoIP
    • Knowledge
    • WhatsApp
    Third party apps Odoo Studio Odoo Cloud Platform
  • Industries
    Retail
    • Book Store
    • Clothing Store
    • Furniture Store
    • Grocery Store
    • Hardware Store
    • Toy Store
    Food & Hospitality
    • Bar and Pub
    • Restaurant
    • Fast Food
    • Guest House
    • Beverage Distributor
    • Hotel
    Real Estate
    • Real Estate Agency
    • Architecture Firm
    • Construction
    • Estate Management
    • Gardening
    • Property Owner Association
    Consulting
    • Accounting Firm
    • Odoo Partner
    • Marketing Agency
    • Law firm
    • Talent Acquisition
    • Audit & Certification
    Manufacturing
    • Textile
    • Metal
    • Furnitures
    • Food
    • Brewery
    • Corporate Gifts
    Health & Fitness
    • Sports Club
    • Eyewear Store
    • Fitness Center
    • Wellness Practitioners
    • Pharmacy
    • Hair Salon
    Trades
    • Handyman
    • IT Hardware & Support
    • Solar Energy Systems
    • Shoe Maker
    • Cleaning Services
    • HVAC Services
    Others
    • Nonprofit Organization
    • Environmental Agency
    • Billboard Rental
    • Photography
    • Bike Leasing
    • Software Reseller
    Browse all Industries
  • Community
    Learn
    • Tutorials
    • Documentation
    • Certifications
    • Training
    • Blog
    • Podcast
    Empower Education
    • Education Program
    • Scale Up! Business Game
    • Visit Odoo
    Get the Software
    • Download
    • Compare Editions
    • Releases
    Collaborate
    • Github
    • Forum
    • Events
    • Translations
    • Become a Partner
    • Services for Partners
    • Register your Accounting Firm
    Get Services
    • Find a Partner
    • Find an Accountant
    • Meet an advisor
    • Implementation Services
    • Customer References
    • Support
    • Upgrades
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Get a demo
  • Pricing
  • Help

Odoo is the world's easiest all-in-one management software.
It includes hundreds of business apps:

  • CRM
  • e-Commerce
  • Accounting
  • Inventory
  • PoS
  • Project
  • MRP
All apps
You need to be registered to interact with the community.
All Posts People Badges
Tags (View all)
odoo accounting v14 pos v15
About this forum
You need to be registered to interact with the community.
All Posts People Badges
Tags (View all)
odoo accounting v14 pos v15
About this forum
Help

How to override a function in a module that's already overiding res.users. i.e(auth_signup)

Subscribe

Get notified when there's activity on this post

This question has been flagged
inheritancemultipletracebacksignupauth_signup
1 Reply
12282 Views
Avatar
Lloyd

Summary:

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?

Code from my file below


from datetime import datetime, timedelta
import random
from urlparse import urljoin
import werkzeug

from openerp.addons.base.ir.ir_mail_server import MailDeliveryException
from openerp.osv import osv, fields
from openerp.tools.misc import DEFAULT_SERVER_DATETIME_FORMAT, ustr
from ast import literal_eval
from openerp.tools.translate import _

class SignupError(Exception):
pass


# Inherit Res User - Auth Signup
#==============================================================
class auth_res_users_inherit(osv.Model):
_inherit = 'res.users'

# Inherit Res User - Auth Signup
#==============================================================
class auth_res_users_inherit(osv.Model):
_inherit = 'res.users'

def _signup_create_user(self, cr, uid, values, context=None):
""" create a new user from the template user """
ir_config_parameter = self.pool.get('ir.config_parameter')
template_user_id = literal_eval(ir_config_parameter.get_param(cr, uid, 'auth_signup.template_user_id', 'False'))
assert template_user_id and self.exists(cr, uid, template_user_id, context=context), 'Signup: invalid template user'

# 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"

        if self.search(cr, uid, [('login','=',values.get('login'))],context=context):
raise SignupError("User with email login '%s' already exists, please use a unique email address." %values.get('login'))

        # create a copy of the template user (attached to a specific partner_id if given)
values['active'] = True
context = dict(context or {}, no_reset_password=True)
try:
with cr.savepoint():
return self.copy(cr, uid, template_user_id, values, context=context)
except Exception, e:
# copy may failed if asked login is not available.
raise SignupError(ustr(e))

auth_res_users_inherit()
0
Avatar
Discard
Avatar
Axel Mendoza
Best Answer

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

Hope this helps

0
Avatar
Discard
Lloyd
Author

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.

Enjoying the discussion? Don't just read, join in!

Create an account today to enjoy exclusive features and engage with our awesome community!

Sign up
Related Posts Replies Views Activity
Multiple models from different objects
inheritance multiple
Avatar
Avatar
Avatar
4
Sep 19
5871
An exception while creating new user signup. Record does not exist or has been deleted. None
signup auth_signup
Avatar
Avatar
1
Mar 18
6301
How to add Country field in signup page?
login signup auth_signup
Avatar
Avatar
1
Apr 25
4463
How to inherit multiple classes in odoo Solved
inheritance multiple classes
Avatar
Avatar
Avatar
Avatar
3
Jan 24
16724
multiple models inherited in a class Solved
inheritance models multiple
Avatar
Avatar
Avatar
5
Jun 21
19112
Community
  • Tutorials
  • Documentation
  • Forum
Open Source
  • Download
  • Github
  • Runbot
  • Translations
Services
  • Odoo.sh Hosting
  • Support
  • Upgrade
  • Custom Developments
  • Education
  • Find an Accountant
  • Find a Partner
  • Become a Partner
About us
  • Our company
  • Brand Assets
  • Contact us
  • Jobs
  • Events
  • Podcast
  • Blog
  • Customers
  • Legal • Privacy
  • Security
الْعَرَبيّة Català 简体中文 繁體中文 (台灣) Čeština Dansk Nederlands English Suomi Français Deutsch हिंदी Bahasa Indonesia Italiano 日本語 한국어 (KR) Lietuvių kalba Język polski Português (BR) română русский язык Slovenský jazyk slovenščina Español (América Latina) Español ภาษาไทย Türkçe українська Tiếng Việt

Odoo is a suite of open source business apps that cover all your company needs: CRM, eCommerce, accounting, inventory, point of sale, project management, etc.

Odoo's unique value proposition is to be at the same time very easy to use and fully integrated.

Website made with

Odoo Experience on YouTube

1. Use the live chat to ask your questions.
2. The operator answers within a few minutes.

Live support on Youtube
Watch now