İçereği Atla
Odoo Menü
  • Portal
  • Ücretsiz deneyin
  • Uygulamalar
    Finans
    • Muhasebe
    • Faturalama
    • Masraf Yönetimi
    • Elektronik Çizelge (BI)
    • Belgeler
    • İmza
    Satış
    • Müşteri İlişkileri Yönetimi (CRM)
    • Satış
    • Satış Noktası Mağaza
    • Satış Noktası Restoran
    • Abonelikler
    • Kiralama
    Web Sitesi
    • Web Sitesi Oluşturucu
    • eTicaret
    • Blog
    • Forum
    • Canlı Sohbet
    • eÖğrenme
    Tedarik Zinciri
    • Envanter
    • Üretim
    • Ürün Yaşam Döngüsü Yönetimi
    • Satın Alma
    • Bakım
    • Kalite
    İnsan Kaynakları
    • Çalışanlar
    • İşe Alım
    • İzin
    • Değerlendirme
    • Referans
    • Filo Yönetimi
    Pazarlama
    • Sosyal Medyada Pazarlama
    • E-posta ile Pazarlama
    • SMS ile Pazarlama
    • Etkinlikler
    • Pazarlama Otomasyonu
    • Anket
    Hizmetler
    • Proje Yönetimi
    • Çalışma Çizelgeleri
    • Saha Hizmeti
    • Yardım Masası
    • Planlama
    • Randevular
    Verimlilik
    • Sohbet
    • Onay
    • Nesnelerin İnterneti
    • VoIP
    • Bilgi Bankası
    • WhatsApp
    Üçüncü taraf uygulamalar Odoo Stüdyo Odoo Bulut Platformu
  • Sektörler
    Perakende satış
    • Kitapçı
    • Giyim Mağazası
    • Mobilya Mağazası
    • Gıda Marketi
    • Hırdavat Dükkanı
    • Oyuncak Dükkanı
    Gıda ve Konaklama
    • Bar ve Pub
    • Restoran
    • Fast Food Restoranı
    • Konuk Evi
    • İçecek Distribütörü
    • Otel
    Gayrimenkul
    • Emlak Acentesi
    • Mimarlık Firması
    • İnşaat
    • Emlak Yönetimi
    • Bahçe Tasarımı
    • Mülk Sahipleri Derneği
    Uzmanlık
    • Muhasebe Firması
    • Odoo Partner
    • Pazarlama Ajansı
    • Hukuk Firması
    • Yetenek Kazanımı
    • Denetim ve Belgelendirme
    Üretim
    • Tekstil
    • Metal
    • Mobilyalar
    • Gıda
    • Bira fabrikası
    • Kurumsal Hediye
    Sağlık ve Spor
    • Spor Kulübü
    • Optik Mağazası
    • Fitness Merkezi
    • Sağlıklı Yaşam Merkezi
    • Eczane
    • Kuaför Salonu
    Ticaret
    • Tamirci
    • BT Donanım & Destek
    • Güneş Enerjisi Sistemleri
    • Ayakkabı İmalatçısı
    • Temizlik Hizmetleri
    • HVAC Hizmetleri
    Diğerleri
    • Kar Amacı Gütmeyen Kuruluş
    • Çevre Ajansı
    • Reklam Panosu Kiralama
    • Fotoğrafçılık
    • Bisiklet Kiralama
    • Yazılım Bayisi
    Tüm Sektörlere Göz Atın
  • Topluluk
    Öğrenim
    • Eğitim Araçları
    • Dokümantasyon
    • Sertifikasyonlar
    • Eğitim Etkinlikleri
    • Blog
    • Podcast
    Eğitim ve Gelişim
    • Eğitim Programı
    • Scale Up! İşletme Oyunu
    • Odoo'yu Ziyaret Edin
    Yazılım
    • İndirin
    • Sürümleri Kıyaslayın
    • Sürümler
    İş Birliği
    • Github
    • Forum
    • Etkinlikler
    • Çeviriler
    • Partner Olun
    • Partnerler için Hizmetler
    • Muhasebe Firmanızı Kaydettirin
    Hizmetler
    • Partner Bulun
    • Muhasebeci Bulun
    • Bir danışmanla görüşün
    • Kurulum Hizmetleri
    • Müşteri Referansları
    • Destek
    • Sürüm Yükseltme
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Demo randevusu alın
  • Fiyatlandırma
  • Yardım

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

  • Müşteri İlişkileri Yönetimi
  • e-Commerce
  • Muhasebe
  • Envanter
  • PoS
  • Proje Yönetimi
  • MRP
All apps
You need to be registered to interact with the community.
All Posts People Badges
Etiketler (View all)
odoo accounting v14 pos v15
About this forum
You need to be registered to interact with the community.
All Posts People Badges
Etiketler (View all)
odoo accounting v14 pos v15
About this forum
Yardım

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

Abone Ol

Get notified when there's activity on this post

Bu soru işaretlendi
inheritancemultipletracebacksignupauth_signup
1 Cevapla
12296 Görünümler
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
Vazgeç
Avatar
Axel Mendoza
En İyi Yanıt

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
Vazgeç
Lloyd
Üretici

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!

Üye Ol
İlgili Gönderiler Cevaplar Görünümler Aktivite
Multiple models from different objects
inheritance multiple
Avatar
Avatar
Avatar
4
Eyl 19
5883
An exception while creating new user signup. Record does not exist or has been deleted. None
signup auth_signup
Avatar
Avatar
1
Mar 18
6312
How to add Country field in signup page?
login signup auth_signup
Avatar
Avatar
1
Nis 25
4467
How to inherit multiple classes in odoo Çözüldü
inheritance multiple classes
Avatar
Avatar
Avatar
Avatar
3
Oca 24
16732
multiple models inherited in a class Çözüldü
inheritance models multiple
Avatar
Avatar
Avatar
5
Haz 21
19118
Topluluk
  • Eğitim Araçları
  • Dokümantasyon
  • Forum
Açık Kaynak
  • İndirin
  • Github
  • Runbot
  • Çeviriler
Hizmetler
  • Odoo.sh Hosting
  • Destek
  • Sürüm Yükseltme
  • Özel Geliştirmeler
  • Eğitim
  • Muhasebeci Bulun
  • Partner Bulun
  • Partner Olun
Hakkında
  • Şirketimiz
  • Pazarlama Gereçleri
  • İletişim
  • Kariyer
  • Etkinlikler
  • Podcast
  • Blog
  • Müşteriler
  • Hukuki • Gizlilik
  • Güvenlik
الْعَرَبيّة 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, müşteri ilişkileri yönetimi, eTicaret, muhasebe, envanter, satış noktası, proje yönetimi gibi şirketinizin tüm ihtiyaçlarını karşılayan bir açık kaynak işletme uygulamaları paketidir.

Odoo’nun eşsiz değer önermesi, aynı anda hem kullanımının çok kolay olup hem de tamamen entegre olmasıdır.

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