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

Writing two models toghether, in the same module, shows me a key error "account.invoice" (inherited model)

Tilmeld

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

Dette spørgsmål er blevet anmeldt
developmentmodulesinheritancemodelsclass
12 Besvarelser
9480 Visninger
Avatar
Ing. Daniel Blanco

I am writing this code:

class my_class_a(models.Model):

[....]

class my_class_b(models.Model):

    _inherit = "res.partner"

   field_ids = fields.Many2Many(........)


class my_class_c(models.Model):

    _inherit = "account.invoice"

    field_myfield = fields.Char(....)


In this case, I am getting a "key error: account.invoice", but if put my_class_b in a separate module, everything works fine. Even get key error if y separate my_class_b in another file, and import it from __init__.py


Why is this for? 


[....]


0
Avatar
Kassér
Nicolas PIGANEAU

Are you sure that your module depends on 'account' module in the __openerp__.py manifest?

ABU K

what is the use and what is the purpose behind this

ABU K

what is the use and what is the purpose behind this

Ing. Daniel Blanco
Forfatter

There is a typo in the example. The last class is class_c

Ing. Daniel Blanco
Forfatter

Nicolas. This was the cause. Thanks! If you want to convert as an answer in order for me to vote it

OdooBot
Two components that should work together, that for some reason I tested they worked fine, only when created as separate modules.. but the  problem was that in the manifest definition, where I should have included account as a dependency, as you see the answer.


Atte:



Ing. Daniel Blanco
Director
Blanco Martín & Asociados
Móvil: +56 9 73880409 / +54 9 351 228-0893
Skype: hdanielb
Twitter: hdanielb
http://linkd.in/danielblanco


Argentina:
BMyA S.A.
Nicasio 6970. Córdoba
+54 351 5694621 / +54 351 5691933
Argüello - Córdoba
http://www.blancomartin.com.ar

Chile: 
Blanco Martín EIRL
Apoquindo 6410 Of 212
+56 2 2840 0990 / +56 2 2979 0208
Las Condes - Región Metropolitana
http://www.blancomartin.cl




2015-03-31 4:13 GMT-03:00 Dep <libukoshym-gmail.com@mail.odoo.com>:

what is the use and what is the purpose behind this

--
Dep
Sent by Odoo Inc. using Odoo about Forum Post Writing two models toghether, in the same module, shows me a key error "account.invoice" (inherited model)

Avatar
Ing. Daniel Blanco
Forfatter Bedste svar

@Nicolas PIGANEAU:  

you made the thing! This was the cause! THANKS!

("Are you sure that your module depends on 'account' module in the __openerp__.py manifest? ")

In the merged module there was an empty depends declaration. I assumed that depends declaration was to force the module installation only, and as it was one of the main modules.

Cannot convert your comment as an answer because of karma. But you deserve. Thank you.

1
Avatar
Kassér
Avatar
Temur
Bedste svar
  • you're using the same name ( my_class_b ) for the two classes, while you're inheriting from different ones.

0
Avatar
Kassér
Ivan

I think the _name has nothing to do with the problem. In fact, defining an ORM class with an explicitly different name from the original ORM model has it's own meaning (see https://doc.odoo.com/v6.0/developer/2_5_Objects_Fields_Methods/object_inherit.html/). But, yes, you should not define both class with the same name in the same file as only one will be registered. If you put it in different file, it will have different namespace. A namespace in python is defined, among other things, by the folder and file/module (a module in python is defined as a file) name. See https://docs.python.org/2/tutorial/classes.html#python-scopes-and-namespaces for more on namespace.

Temur

thanks @ivan, I know about meaning of _name, etc... but there I don't see sense to use same _name in two classes while inheriting one from "res.partner" and another from "account.invoice", as there is used same class name for both then "_name" will be the same also. it's not problem that "_name" is different from it's parents one(while it may be, regarding requirements), but it's problem that it's not different between these two classes... so if it's absolutely necessary to use same name for both class, then explicitly using "_name" and make them different from each other by the "_name" may help (?)

Ivan

AFAIK, if _name is not stated, the inheritance will just take the _name attribute from the class which is _inherit-ed. You can check the create_instance method of orm for v7.0 or _build_model of BaseModel for v8.0 to get a clearer picture of how this work. So, it is not OK to use the same class name (my_class_b) because of the Python namespace. It is OK to not explicitly specify the _name attribute if _inherit has been specified (and it will be derived from the _inherit attribute, not the class name, first). It is somewhat OK to explicitly specify _name if all the repercussions has been considered even if _inherit is specified (I wouldn't do this, but you might be able to get away by specifying the same value _name attribute, which will translate to table name if _table_name attribute is not specified).

Temur

as noted in the question namespace problem was resolved by putting my_class_b (probably one of them) in the separated module. I mean using same name for the two class in this conditions (putting them in different modules), without violating namespace rules. I tried to give second option, using _name but I see it doesn't gave anything. so I'll remove second one and leave just first note in my answer, as we are agree that using the same name for the two classes in the above code is causing the problem. thanks for your comments @Ivan

Ing. Daniel Blanco
Forfatter

It was a typo in the example. Corrected.. but the problem persists

Ing. Daniel Blanco
Forfatter

the _name field "IS" in the real code.

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 inherit from a Python class that isn't a model and also inherit a model
modules inheritance models version14
Avatar
0
nov. 20
6281
how to inherit view in existing module. Løst
views modules fields inheritance models
Avatar
Avatar
Avatar
3
jan. 22
54671
Odoo 18 - Custom Module - Error on nested class view Løst
development modules
Avatar
Avatar
Avatar
2
jul. 25
3676
classical inheritance
development inheritance
Avatar
Avatar
1
okt. 24
2523
How to upgrade modules in a specific file?
development modules
Avatar
0
mar. 24
2512
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