İç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 method using inherit?

Abone Ol

Get notified when there's activity on this post

Bu soru işaretlendi
calendarinheritanceinheritoverride
2 Cevaplar
34337 Görünümler
Avatar
Anabela Damas

Hi,

I'm trying to override a method in the class calendar_event, I see in here that is needed to re-define columns/fields but my function don have any field defined in the columns...

So what I've tried was this :

class calendar_event(osv.osv):

    _name = 'calendar.event'
    _inherit = "calendar.event"


    def create_attendees(self, cr, uid, ids, context):
        att_obj = self.pool.get('calendar.attendee')

        print 'JUST Print something to see if it uses this function '

        user_obj = self.pool.get('res.users')

        current_user = user_obj.browse(cr, uid, uid, context=context)
        for event in self.browse(cr, uid, ids, context):
            attendees = {}
            for att in event.attendee_ids:
                attendees[att.partner_id.id] = True
            new_attendees = []
            mail_to = ""
            for partner in event.partner_ids:
                if partner.id in attendees:
                    continue
                att_id = self.pool.get('calendar.attendee').create(cr, uid, {
                    'partner_id': partner.id,
                    'user_id': partner.user_ids and partner.user_ids[0].id or False,
                    'ref': self._name+','+str(event.id),
                    'email': partner.email
                }, context=context)
                if partner.email:
                    mail_to = mail_to + " " + partner.email
                self.write(cr, uid, [event.id], {
                    'attendee_ids': [(4, att_id)]
                }, context=context)
                new_attendees.append(att_id)

            if mail_to and current_user.email:
                att_obj._send_mail(cr, uid, new_attendees, mail_to,
                    email_from = current_user.email, context=context)
        return True


calendar_event()

How can I do this?

2
Avatar
Vazgeç
Avatar
Carlos Vasquez
En İyi Yanıt

Hi Anabela,

You only need to redefine columns when you are overwritting a method for a function field. In this case you are not. This method is not used to calculate a field, but to do some other functionality.

The way you are doing this inherit is right. Just a couple of recommendations (assuming you are on v7):

  • Use python standards for class name (camelCase). For your class it would be calendarEvent.
  • Use the new orm.Model object instead of osv.osv. For this you have to import osv.orm first.
  • You don't need anymore the explicit call at the end of the class.
  • For maintainability reasons, always try to implement you inherited methods calling the original one, instead of just copy-pasting it and changing it in your code. This can be done with the super method. In your case it would be:

    super(calendarEvent, self).create_attendees(cr, uid, ids, context)

Regards

6
Avatar
Vazgeç
Anabela Damas
Üretici

Hi Carlos,

I'm a newbie in python, I do stuff like I see in other modules =)

Thanks for the recommendations ;)

Some doubts...

In the second dot I did like this :

from openerp.osv import fields, orm

class calendar_event(orm.Model):

#_name = 'calendar.event'
_inherit = 'calendar.event'

And nothing happened

As I am newbie in python the dot four is very hard because I never know where to put the code, and copy and paste all code is much easier =) Because I want to change some lines in the middle of the function.

Anabela Damas
Üretici

So I try everything and the openerp is still using the original def create_attendees(self, cr, uid, ids, context) .... I don't know what I'm doing wrong =(

Thanks

Carlos Vasquez

Have you created the __init__.py for your module? In this __init__.py you need to have a simple line with: "import file". (change file with the name of your py file without the .py)

Carlos Vasquez

Also, when you make changes to the __openerp__.py and the __init__.py, it is usually necessary to update your module in your database.

Anabela Damas
Üretici

Unfortunately yes, have all of that ... I really don't know what is wrong, I was doing this inherit in a module that does other stuff.

And for tests I created a new single module just with this (mymodule.py), a __init__.py and the __openerp__.py files. This function for some reason that I don't understand doesn't override the original function.... what is weird is that I've made this to other functions and it's working.... =(

Thanks

Carlos Vasquez

One possible explanation is that there is another module installed that is also inheriting this method. If that other module takes precedence, and doesn't do a super call (as I explained in my answer) it will only run that particular module's code. If you are doing this for other methods with a positive result, than it can be either a typo somewhere, or something a little more complicated. It would take a closer look to your code, server and database to find the problem.

Anabela Damas
Üretici

Thanks for all =) I've done a workaround =)

Anabela Damas
Üretici

The workaround has a bug, so I tried again to find the problem I've made a grep to find where this function appears and the only places is my code and the original...

Carlos Llamacho

Hi, i have always used the osv.osv model to do my classes but now i read that the new orm.Model is prefered. There is documentation regarding the differences between them?

fussions

Carlos, can you tell me where I can read about using orm.Model object instead osv.osv. Is it mentioned in OpenERP documentation or one can only derive it from the OpenErp source code?

Carlos Llamacho

I haven't found any official documentation regarding orm.Model as better to use than osv.osv. I have however asked the same question in an Openerp Google group and they recommend to start using orm.Model instead of osv.osv as the later is going to be replaced. Only maintain osv.osv for compatibility issues with former versions.

Avatar
patrick
En İyi Yanıt

No need to define _name, as your module will inherit the class, with the name.

After making your module, you have to install it. The module (with other files and folders) needs to be in /addons directory (on Ubuntu: /usr/lib/pymodules/python2.7/openerp/addons). Now you go to Settings -> Update Module List, than Settings -> Installed modules. Remove the filter 'installed', and search for your module. Click on it, and click on the button 'Install'.

If you want to see some output, don't use print, but use logging.warning('your text here'). You have to import logging first, before usage.

1
Avatar
Vazgeç
Anabela Damas
Üretici

from openerp.osv import logging

2013-06-20 19:25:32,114 15008 CRITICAL teste20jun openerp.modules.module: Couldn't load module gestao_ideias 2013-06-20 19:25:32,114 15008 CRITICAL teste20jun openerp.modules.module: cannot import name logging 2013-06-20 19:25:32,115 15008 ERROR teste20jun openerp.netsvc: cannot import name logging

logging.warning('your text here')

I try this way but didn't work...

patrick

I use the text 'import logging', and it is working. It is a default python thing you import, not something from openERP.

Anabela Damas
Üretici

I tried this:

        import logging
        logging.warning('Something')

and nothing happened. Thanks

patrick

The result of the warning should be in your logging file (on Ubuntu: /vaar/log/openerp/openerp-server.log).

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
how to override an inherited method? Çözüldü
inheritance inherit method override
Avatar
Avatar
Avatar
Avatar
5
Tem 18
24339
How to extend an existing class and include social newtork features in the sub class
inheritance inherit
Avatar
Avatar
3
Tem 18
4642
How to inherit a selection field without old values ? Çözüldü
fields inheritance override
Avatar
Avatar
1
Eki 22
7570
Overwrite a model / a method in I10n_de/models/datev
inherit overwrite override
Avatar
0
Tem 22
2873
Inheritance in discuss module (mail)
inheritance inherit discuss
Avatar
0
Oca 22
3387
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