콘텐츠로 건너뛰기
메뉴
커뮤니티에 참여하려면 회원 가입을 하시기 바랍니다.
신고된 질문입니다
1 회신
5017 화면

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"

아바타
취소
베스트 답변

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.

아바타
취소

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

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

작성자

nice, a million thanks to you

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

관련 게시물 답글 화면 활동
1
10월 21
4655
2
9월 21
5631
Time field in odoo 해결 완료
3
3월 20
43164
1
7월 19
3037
2
5월 19
6439