Bỏ qua để đến Nội dung
Odoo Menu
  • Đăng nhập
  • Dùng thử miễn phí
  • Ứng dụng
    Tài chính
    • Kế toán
    • Hóa đơn
    • Chi phí
    • Bảng tính (BI)
    • Tài liệu
    • Ký tên
    Bán hàng
    • CRM
    • Bán hàng
    • POS Cửa hàng
    • POS Nhà hàng
    • Đăng ký
    • Cho thuê
    Trang web
    • Trình tạo trang web
    • Thương mại điện tử
    • Blog
    • Diễn đàn
    • Trò chuyện trực tiếp
    • Học trực tuyến
    Chuỗi cung ứng
    • Tồn kho
    • Sản xuất
    • PLM
    • Mua hàng
    • Bảo dưỡng
    • Chất lượng
    Nhân sự
    • Nhân viên
    • Tuyển dụng
    • Ngày nghỉ
    • Đánh giá
    • Giới thiệu
    • Đội xe
    Marketing
    • Marketing trên MXH
    • Marketing qua email
    • Marketing qua SMS
    • Sự kiện
    • Tự động hóa Marketing
    • Khảo sát
    Dịch vụ
    • Dự án
    • Bảng chấm công
    • Dịch vụ hiện trường
    • Hỗ trợ
    • Kế hoạch
    • Lịch hẹn
    Năng suất
    • Thảo luận
    • Phê duyệt
    • IoT
    • VoIP
    • Kiến thức
    • WhatsApp
    Ứng dụng của bên thứ ba Studio Odoo Nền tảng Đám mây Odoo
  • Ngành
    Bán lẻ
    • Nhà sách
    • Cửa hàng quần áo
    • Cửa hàng nội thất
    • Cửa hàng tạp hóa
    • Cửa hàng đồ kim khí
    • Cửa hàng đồ chơi
    Ẩm thực & Dịch vụ lưu trú
    • Bar và quán rượu
    • Nhà hàng
    • Đồ ăn nhanh
    • Guest house
    • Nhà phân phối đồ uống
    • Khách sạn
    Bất động sản
    • Công ty môi giới bất động sản
    • Công ty kiến trúc
    • Xây dựng
    • Quản lý bất động sản
    • Làm vườn
    • Hiệp hội chủ sở hữu bất động sản
    Tư vấn
    • Công ty kế toán
    • Đối tác Odoo
    • Công ty marketing
    • Công ty luật
    • Tuyển dụng
    • Thanh tra & chứng nhận
    Sản xuất
    • Dệt may
    • Kim loại
    • Nội thất
    • Ẩm thực
    • Nhà máy bia
    • Quà tặng doanh nghiệp
    Sức khoẻ & fitness
    • CLB thể thao
    • Cửa hàng kính mắt
    • Trung tâm fitness
    • Chuyên gia chăm sóc sức khỏe
    • Hiệu thuốc
    • Tiệm làm tóc
    Thương mại
    • Dịch vụ sửa chữa
    • Phần cứng CNTT & Hỗ trợ
    • Hệ thống năng lượng mặt trời
    • Công ty sản xuất giày
    • Dịch vụ vệ sinh
    • Dịch vụ HVAC
    Khác
    • Tổ chức phi lợi nhuận
    • Cơ quan môi trường
    • Cho thuê biển quảng cáo
    • Nhiếp ảnh
    • Cho thuê xe đạp
    • Đại lý phần mềm
    Xem tất cả ngành
  • Cộng đồng
    Học tập
    • Khóa học
    • Tài liệu
    • Chứng chỉ
    • Đào tạo
    • Blog
    • Podcast
    Thúc đẩy đào tạo
    • Chương trình đào tạo
    • Trò chơi kinh doanh Scale Up!
    • Tham quan Odoo
    Nhận phần mềm
    • Tải xuống
    • So sánh các phiên bản
    • Phiên bản
    Hợp tác
    • Github
    • Diễn đàn
    • Sự kiện
    • Dịch thuật
    • Trở thành đối tác
    • Dịch vụ dành cho Đối tác
    • Đăng ký công ty kế toán của bạn
    Nhận dịch vụ
    • Tìm đối tác
    • Tìm kế toán
    • Gặp chuyên gia hỗ trợ
    • Dịch vụ Triển khai
    • Khách hàng tham khảo
    • Hỗ trợ
    • Nâng cấp
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Nhận một buổi demo
  • Bảng giá
  • Trợ giúp

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

  • CRM
  • e-Commerce
  • Kế toán
  • Tồn kho
  • PoS
  • Dự án
  • MRP
All apps
Bạn cần phải đăng ký để tương tác với cộng đồng.
Tất cả bài viết Người Huy hiệu
Thẻ (Xem tất cả)
odoo accounting v14 pos v15
Về diễn đàn này
Bạn cần phải đăng ký để tương tác với cộng đồng.
Tất cả bài viết Người Huy hiệu
Thẻ (Xem tất cả)
odoo accounting v14 pos v15
Về diễn đàn này
Hỗ trợ

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

Đăng ký nhận tin

Nhận thông báo khi có hoạt động trên bài viết này

Câu hỏi này đã bị gắn cờ
developmentmodulesinheritancemodelsclass
12 Trả lời
9475 Lượt xem
Ảnh đại diện
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
Ảnh đại diện
Huỷ bỏ
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
Tác giả

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

Ing. Daniel Blanco
Tác giả

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)

Ảnh đại diện
Ing. Daniel Blanco
Tác giả Câu trả lời hay nhất

@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
Ảnh đại diện
Huỷ bỏ
Ảnh đại diện
Temur
Câu trả lời hay nhất
  • you're using the same name ( my_class_b ) for the two classes, while you're inheriting from different ones.

0
Ảnh đại diện
Huỷ bỏ
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
Tác giả

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

Ing. Daniel Blanco
Tác giả

the _name field "IS" in the real code.

Bạn có hứng thú với cuộc thảo luận không? Đừng chỉ đọc, hãy tham gia nhé!

Tạo tài khoản ngay hôm nay để tận hưởng các tính năng độc đáo và tham gia cộng đồng tuyệt vời của chúng tôi!

Đăng ký
Bài viết liên quan Trả lời Lượt xem Hoạt động
How to inherit from a Python class that isn't a model and also inherit a model
modules inheritance models version14
Ảnh đại diện
0
thg 11 20
6281
how to inherit view in existing module. Đã xử lý
views modules fields inheritance models
Ảnh đại diện
Ảnh đại diện
Ảnh đại diện
3
thg 1 22
54671
Odoo 18 - Custom Module - Error on nested class view Đã xử lý
development modules
Ảnh đại diện
Ảnh đại diện
Ảnh đại diện
2
thg 7 25
3676
classical inheritance
development inheritance
Ảnh đại diện
Ảnh đại diện
1
thg 10 24
2523
How to upgrade modules in a specific file?
development modules
Ảnh đại diện
0
thg 3 24
2512
Cộng đồng
  • Khóa học
  • Tài liệu
  • Diễn đàn
Open source
  • Tải xuống
  • Github
  • Runbot
  • Dịch thuật
Dịch vụ
  • Lưu trữ Odoo.sh
  • Hỗ trợ
  • Nâng cấp
  • Phát triển tùy chỉnh
  • Đào tạo
  • Tìm kế toán
  • Tìm đối tác
  • Trở thành đối tác
Giới thiệu công ty
  • Công ty của chúng tôi
  • Tài sản thương hiệu
  • Liên hệ
  • Việc làm
  • Sự kiện
  • Podcast
  • Blog
  • Khách hàng
  • Pháp lý • Riêng tư
  • Bảo mật
الْعَرَبيّة 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 là bộ ứng dụng kinh doanh có open source đáp ứng tất cả các nhu cầu của công ty bạn: CRM, thương mại điện tử, kế toán, tồn kho, POS, quản lý dự án, v.v.

Định hướng giá trị riêng biệt của Odoo là tích hợp hoàn toàn và dễ dàng sử dụng.

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