Skip to Content
Odoo Menu
  • Log ind
  • Prøv gratis
  • Apps
    Økonomi
    • Bogføring
    • Fakturering
    • Udgifter
    • Regneark (BI)
    • Dokumenter
    • e-Signatur
    Salg
    • CRM
    • Salg
    • POS Butik
    • POS Restaurant
    • Abonnementer
    • Udlejning
    Hjemmeside
    • Hjemmesidebygger
    • e-Handel
    • Blog
    • Forum
    • LiveChat
    • e-Læring
    Forsyningskæde
    • Lagerbeholdning
    • Produktion
    • PLM
    • Indkøb
    • Vedligeholdelse
    • Kvalitet
    HR
    • Medarbejdere
    • Rekruttering
    • Fravær
    • Medarbejdersamtaler
    • Anbefalinger
    • Flåde
    Marketing
    • Markedsføring på sociale medier
    • E-mailmarketing
    • SMS-marketing
    • Arrangementer
    • Automatiseret marketing
    • Spørgeundersøgelser
    Tjenester
    • Projekt
    • Timesedler
    • Udkørende Service
    • Kundeservice
    • Planlægning
    • Aftaler
    Produktivitet
    • Dialog
    • Godkendelser
    • IoT
    • VoIP
    • Vidensdeling
    • WhatsApp
    Tredjepartsapps Odoo Studio Odoo Cloud-platform
  • Brancher
    Detailhandel
    • Boghandel
    • Tøjforretning
    • Møbelforretning
    • Dagligvarebutik
    • Byggemarked
    • Legetøjsforretning
    Mad og værtsskab
    • Bar og pub
    • Restaurant
    • Fastfood
    • Gæstehus
    • Drikkevareforhandler
    • Hotel
    Ejendom
    • Ejendomsmægler
    • Arkitektfirma
    • Byggeri
    • Ejendomsadministration
    • Havearbejde
    • Boligejerforening
    Rådgivning
    • Regnskabsfirma
    • Odoo-partner
    • Marketingbureau
    • Advokatfirma
    • Rekruttering
    • Audit & certificering
    Produktion
    • Tekstil
    • Metal
    • Møbler
    • Fødevareproduktion
    • Bryggeri
    • Firmagave
    Heldbred & Fitness
    • Sportsklub
    • Optiker
    • Fitnesscenter
    • Kosmetolog
    • Apotek
    • Frisør
    Håndværk
    • Handyman
    • IT-hardware og support
    • Solenergisystemer
    • Skomager
    • Rengøringsservicer
    • VVS- og ventilationsservice
    Andet
    • Nonprofitorganisation
    • Miljøagentur
    • Udlejning af billboards
    • Fotografi
    • Cykeludlejning
    • Softwareforhandler
    Gennemse alle brancher
  • Community
    Få mere at vide
    • Tutorials
    • Dokumentation
    • Certificeringer
    • Oplæring
    • Blog
    • Podcast
    Bliv klogere
    • Udannelselsesprogram
    • Scale Up!-virksomhedsspillet
    • Besøg Odoo
    Få softwaren
    • Download
    • Sammenlign versioner
    • Udgaver
    Samarbejde
    • Github
    • Forum
    • Arrangementer
    • Oversættelser
    • Bliv partner
    • Tjenester til partnere
    • Registrér dit regnskabsfirma
    Modtag tjenester
    • Find en partner
    • Find en bogholder
    • Kontakt en rådgiver
    • Implementeringstjenester
    • Kundereferencer
    • Support
    • Opgraderinger
    Github Youtube Twitter LinkedIn Instagram Facebook Spotify
    +1 (650) 691-3277
    Få en demo
  • Prissætning
  • Hjælp

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

  • CRM
  • e-Commerce
  • Bogføring
  • Lager
  • PoS
  • Projekt
  • MRP
All apps
Du skal være registreret for at interagere med fællesskabet.
All Posts People Emblemer
Tags (View all)
odoo accounting v14 pos v15
Om dette forum
Du skal være registreret for at interagere med fællesskabet.
All Posts People Emblemer
Tags (View all)
odoo accounting v14 pos v15
Om dette forum
Hjælp

How to override a method using inherit?

Tilmeld

Få besked, når der er aktivitet på dette indlæg

Dette spørgsmål er blevet anmeldt
calendarinheritanceinheritoverride
2 Besvarelser
34321 Visninger
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
Kassér
Avatar
Carlos Vasquez
Bedste svar

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
Kassér
Anabela Damas
Forfatter

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
Forfatter

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
Forfatter

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
Forfatter

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

Anabela Damas
Forfatter

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
Bedste svar

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
Kassér
Anabela Damas
Forfatter

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
Forfatter

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!

Tilmeld dig
Related Posts Besvarelser Visninger Aktivitet
how to override an inherited method? Løst
inheritance inherit method override
Avatar
Avatar
Avatar
Avatar
5
jul. 18
24321
How to extend an existing class and include social newtork features in the sub class
inheritance inherit
Avatar
Avatar
3
jul. 18
4638
How to inherit a selection field without old values ? Løst
fields inheritance override
Avatar
Avatar
1
okt. 22
7565
Overwrite a model / a method in I10n_de/models/datev
inherit overwrite override
Avatar
0
jul. 22
2861
Inheritance in discuss module (mail)
inheritance inherit discuss
Avatar
0
jan. 22
3382
Community
  • Tutorials
  • Dokumentation
  • Forum
Open Source
  • Download
  • Github
  • Runbot
  • Oversættelser
Tjenester
  • Odoo.sh-hosting
  • Support
  • Opgradere
  • Individuelt tilpasset udvikling
  • Uddannelse
  • Find en bogholder
  • Find en partner
  • Bliv partner
Om os
  • Vores virksomhed
  • Brandaktiver
  • Kontakt os
  • Stillinger
  • Arrangementer
  • Podcast
  • Blog
  • Kunder
  • Juridiske dokumenter • Privatlivspolitik
  • Sikkerhedspolitik
الْعَرَبيّة 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 er en samling open source-forretningsapps, der dækker alle dine virksomhedsbehov – lige fra CRM, e-handel og bogføring til lagerstyring, POS, projektledelse og meget mere.

Det unikke ved Odoo er, at systemet både er brugervenligt og fuldt integreret.

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