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

Hi,

for example in sale.order.line model we have price_unit field, but in front view we see "Unit Price"

price_unit = fields.Float('Unit Price', required=True, digits=dp.get_precision('Product Price'), default=0.0)

How to pull out this text through a python? such as such 

test = self.env['sale.order.line'].browse(1).price_unit.string

and in test variable will be "Unit Price"

Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhất

The field label is stored in the model ir.model.fields. You can find a definite object by its name and related model. An example:

field_id = self.env["ir.model.fields"].sudo()._search([
("name", "=", "price_unit"),
("model", "=", "sale.order.line")
], limit=1)
label = field_id and field_id.field_description or "Not defined"

Take into account that the name would be shown in the SuperUser language. In order to show it a different language you should pass the context with a required lang code.

Ảnh đại diện
Huỷ bỏ

field_id.with_context(lang='ru_RU').field_description - should work.

Better use English: otherwise the question might be closed by others.

Tác giả

nice, a million thanks to you

I did not close the question, but deleted the russian comment :-)

Bài viết liên quan Trả lời Lượt xem Hoạt động
1
thg 10 21
4667
2
thg 9 21
5652
Time field in odoo Đã xử lý
3
thg 3 20
43193
1
thg 7 19
3043
2
thg 5 19
6445