Overslaan naar inhoud
Menu
Je moet geregistreerd zijn om te kunnen communiceren met de community.
Deze vraag is gerapporteerd
1 Beantwoorden
12172 Weergaven

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?



Avatar
Annuleer
Beste antwoord

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.

Avatar
Annuleer
Auteur

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!

Gerelateerde posts Antwoorden Weergaven Activiteit
0
mrt. 17
3222
1
dec. 19
6023
1
feb. 17
7350
2
jul. 25
4621
2
dec. 24
7771