Přejít na obsah
Odoo Menu
  • Přihlásit se
  • Vyzkoušejte zdarma
  • Aplikace
    Finance
    • Účetnictví
    • Fakturace
    • Výdaje
    • Spreadsheet (BI)
    • Dokumenty
    • Podpisy
    Prodej
    • CRM
    • Prodej
    • POS Obchod
    • POS Restaurace
    • Předplatné
    • Pronájem
    Webové stránky
    • Webové stránky
    • E-shop
    • Blog
    • Fórum
    • Živý chat
    • eLearning
    Dodavatelský řetězec
    • Sklad
    • Výroba
    • PLM
    • Nákup
    • Údržba
    • Kvalita
    Lidské zdroje
    • Zaměstnanci
    • Nábor
    • Volno
    • Hodnocení zaměstnanců
    • Doporučení
    • Vozový park
    Marketing
    • Marketing sociálních sítí
    • Emailový marketing
    • SMS Marketing
    • Události
    • Marketingová automatizace
    • Dotazníky
    Služby
    • Projekt
    • Časové výkazy
    • Práce v terénu
    • Helpdesk
    • Plánování
    • Schůzky
    Produktivita
    • Diskuze
    • Schvalování
    • IoT
    • VoIP
    • Znalosti
    • WhatsApp
    Aplikace třetích stran Odoo Studio Odoo cloudová platforma
  • Branže
    Maloobchod
    • Knihkupectví
    • Obchod s oblečením
    • Obchod s nábytkem
    • Potraviny
    • Obchod s hardwarem
    • Hračkářství
    Jídlo a pohostinství
    • Bar a Pub
    • Restaurace
    • Fast Food
    • Penzion
    • Distributor nápojů
    • Hotel
    Nemovitost
    • Realitní kancelář
    • Architektonická firma
    • Stavba
    • Správa nemovitostí
    • Zahradnictví
    • Asociace vlastníků nemovitosti
    Poradenství
    • Účetní firma
    • Odoo Partner
    • Marketingová agentura
    • Právník
    • Akvizice talentů
    • Audit a certifikace
    Výroba
    • Textil
    • Kov
    • Nábytek
    • Jídlo
    • Pivovar
    • Korporátní dárky
    Zdraví a fitness
    • Sportovní klub
    • Prodejna brýli
    • Fitness Centrum
    • Wellness praktikové
    • Lékárna
    • Kadeřnictví
    Transakce
    • Údržbář
    • Podpora IT & hardware
    • Systémy solární energie
    • Výrobce obuvi
    • Úklidové služby
    • Služby HVAC
    Ostatní
    • Nezisková organizace
    • Agentura pro životní prostředí
    • Pronájem billboardů
    • Fotografování
    • Leasing jízdních kol
    • Prodejce softwaru
    Procházet všechna odvětví
  • Komunita
    Edukační program
    • Tutoriály
    • Dokumentace
    • Certifikace
    • Vzdělávání
    • Blog
    • Podcast
    Podpora vzdělávání
    • Vzdělávací program
    • Scale Up! Hra na firmu
    • Navštivte Odoo
    Získat software
    • Stáhnout
    • Porovnejte edice
    • Verze
    Spolupráce
    • Github
    • Fórum
    • Události
    • Překlady
    • Stát se partnerem
    • Služby pro partnery
    • Registrujte svou účetní firmu
    Získat služby
    • Najít partnera
    • Najít účetní
    • Setkejte se s poradcem
    • Implementační služby
    • Zákaznické reference
    • Podpora
    • Upgrady
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Dohodnout demo
  • Ceník
  • Pomoc

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

  • CRM
  • e-Commerce
  • Účetnictví
  • Sklad
  • PoS
  • Projekty
  • MRP
All apps
You need to be registered to interact with the community.
All Posts Lidé Odznaky
Štítky (View all)
odoo accounting v14 pos v15
O tomto fóru
You need to be registered to interact with the community.
All Posts Lidé Odznaky
Štítky (View all)
odoo accounting v14 pos v15
O tomto fóru
Pomoc

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

Odebírat

Get notified when there's activity on this post

This question has been flagged
inheritancemultipletracebacksignupauth_signup
1 Odpovědět
12290 Zobrazení
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
Zrušit
Avatar
Axel Mendoza
Nejlepší odpověď

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
Zrušit
Lloyd
Autor

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!

Přihlásit se
Related Posts Odpovědi Zobrazení Aktivita
Multiple models from different objects
inheritance multiple
Avatar
Avatar
Avatar
4
zář 19
5883
An exception while creating new user signup. Record does not exist or has been deleted. None
signup auth_signup
Avatar
Avatar
1
bře 18
6312
How to add Country field in signup page?
login signup auth_signup
Avatar
Avatar
1
dub 25
4467
How to inherit multiple classes in odoo Vyřešeno
inheritance multiple classes
Avatar
Avatar
Avatar
Avatar
3
led 24
16731
multiple models inherited in a class Vyřešeno
inheritance models multiple
Avatar
Avatar
Avatar
5
čvn 21
19116
Komunita
  • Tutoriály
  • Dokumentace
  • Fórum
Open Source
  • Stáhnout
  • Github
  • Runbot
  • Překlady
Služby
  • Odoo.sh hostování
  • Podpora
  • Upgrade
  • Nestandardní vývoj
  • Edukační program
  • Najít účetní
  • Najít partnera
  • Stát se partnerem
O nás
  • Naše společnost
  • Podklady značky
  • Kontakujte nás
  • Práce
  • Události
  • Podcast
  • Blog
  • Zákazníci
  • Právní dokumenty • Soukromí
  • Zabezpečení
الْعَرَبيّة 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 je balíček open-source aplikací, které pokrývají všechny potřeby vaší společnosti: CRM, e-shop, účetnictví, sklady, kasy, projektové řízení a další.

Unikátní nabídka od Odoo poskytuje velmi jednoduché uživatelské rozhraní a vše je integrované na jednom místě.

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