Odoo Help


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

Ing. Daniel Blanco
on 3/29/15, 5:28 PM 2,132 views

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? 


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

on 3/30/15, 3:26 PM

what is the use and what is the purpose behind this

on 3/31/15, 3:13 AM

what is the use and what is the purpose behind this

on 3/31/15, 3:13 AM

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

Daniel Blanco
on 3/31/15, 7:50 AM

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

Daniel Blanco
on 3/31/15, 8:07 AM
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.


Ing. Daniel Blanco
Blanco Martín & Asociados
Skype: hdanielb
Twitter: hdanielb

Nicasio 6970. Córdoba
Argüello - Córdoba

Blanco Martín EIRL
Apoquindo 6410 Of 212
Las Condes - Región Metropolitana

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

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)

Daniel Blanco
on 3/31/15, 8:18 AM
Ing. Daniel Blanco
On 3/31/15, 8:01 AM

@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.




| 6 5 7
Tbilisi, Georgia
On 3/31/15, 3:47 AM
  • you're using the same name ( my_class_b ) for the two classes, while you're inheriting from different ones.

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.

on 3/31/15, 4:13 AM

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 (?)

on 3/31/15, 5:10 AM

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).

on 3/31/15, 6:50 AM

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

on 3/31/15, 7:50 AM

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

Daniel Blanco
on 3/31/15, 7:52 AM

the _name field "IS" in the real code.

Daniel Blanco
on 3/31/15, 7:53 AM

About This Community

This platform is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.


Odoo Training Center

Access to our E-learning platform and experience all Odoo Apps through learning videos, exercises and Quizz.

Test it now

Question tools

1 follower(s)


Asked: 3/29/15, 5:28 PM
Seen: 2132 times
Last updated: 12/28/16, 3:00 AM