コンテンツへスキップ
メニュー
この質問にフラグが付けられました
1 返信
12179 ビュー

I have a field I can't read with search. I know it exist and is populated and the current value is -387.06.

With a simple search it always return a 0.0:

self.search([('id', '=', '1')]).day_profit

But if I try with a 

self.search_read([('id', '=', '1')])

[{'create_date': '2017-03-22 21:16:11', 'avg_minutes': u'6', 'write_uid': (1, u'Administrator'), 'fix_day': 588.24, 'id': 1, 'create_uid': (1, u'Administrator'), 'display_name': u'divina.custos,1', 'day_profit': -387.06, '__last_update': '2017-03-22 23:46:49'}]

That's curious enough, because if I search another filed like fix_day the search works as expected.

Where is the error?



アバター
破棄
最善の回答

HI,

search() returns a  recordset and search_read() returns a list of dict. In your attempt, you are trying to compare integer field with a string and ie, wrong. You should try

self.search([('id', '=', 1)])[0].day_profit.

This code will return null if the day_profit has no value.

アバター
破棄
著作者

Hilar, thanks for your reply.

I know how search_read works compared with search, was just an example to show the field is currently populated.

I've used self.search without specify the position in a list and it always worked fine. For example

self.search([('id', '=', 1)]).fix_day

or or .id/.ids worked fine and just day_profit not. But if adding [0] solve the issue...

A little more explanation will be really appreciated!

関連投稿 返信 ビュー 活動
0
3月 17
3227
1
12月 19
6031
1
2月 17
7367
2
7月 25
4635
2
12月 24
7775