Bỏ qua để đến Nội dung
Menu
Câu hỏi này đã bị gắn cờ
1 Trả lời
5372 Lượt xem

Hi, guys. I have a problem in many2one field. So here is my code in model.py


prodname = fields.Many2one('product.template', string='Product Name')


I want to drop down my product list. the problem is, sometimes is success also error. the error is like this


AttributeError: '_unknown' object has no attribute 'id'


In the Technical > Fields, the related model is '_unknown' that is supposed to 'product.template', right? 

Please, help me to fix this. Thanks a lot.

Ảnh đại diện
Huỷ bỏ
Tác giả

Yes, thank you so much Yurii. I forgot to add the "depends" value. Thank you, it's work.

Câu trả lời hay nhất

Hi!

Could you check that you have added the necessary depends to your __manifest__.py? It is similar as you didn't add the dependency to the "product" module that contains the "product.template" model.

"depends": ["product"],

As a suggestion, the relation field name would be more clearer if it will have the suffix "_id" for Many2one fields and "_ids" for Many2many or One2many fields. As recommended in Odoo Developer Guidelines: https://www.odoo.com/documentation/14.0/developer/misc/other/guidelines.html?highlight=developer guideline#symbols-and-conventions

Ảnh đại diện
Huỷ bỏ
Bài viết liên quan Trả lời Lượt xem Hoạt động
1
thg 6 23
1370
1
thg 4 25
4176
2
thg 2 22
2913
1
thg 6 25
1858
3
thg 7 25
3476