Overslaan naar inhoud
Menu
Je moet geregistreerd zijn om te kunnen communiceren met de community.
Deze vraag is gerapporteerd
6 Antwoorden
242 Weergaven

Hi everybody!!!

Please, i have a many2one field defined like this:

'project_service' : fields.many2one('project_service', string= 'service'),


The problem is that when when i want to make print on this field i get "false" despite it was defined very well.

Is it empty or what please who can help

Thanks a lot in advance

Avatar
Annuleer

For a many2one field, if no value is selected, it will return False. If there is any value for it, it displays the id of the selected record at the print statement.

I think syntax like 'project_service' : fields.many2one('project.service', string= 'service'), Try this one.

Beste antwoord

Abdelwahed,

You should first understand the important basics/conventions on Odoo/OpenERP.

When you use a many2one field,try doing this:

'project_service_id': fields.many2one('project.service', 'Service')

With whatever object/handle you print, are you sure you are browsing through the righ model and reaching to this field?

If this field has a value, then you must do this:

<YourObject>.project_service_id and <YourObject>.project_service_id.name or '' .

Hope this helps.

SerpentCS

(contact@serpentcs.com)


Avatar
Annuleer
Auteur

Thanks a lot you ave answered me ;) Look i have changed the field: 'project_service_id': fields.many2one ('project.service', string= 'Services'), An dwhen i want to print it i have done this: service = vals.get('project_service_id') print service

Important thing is , where do you use it. You need a right container! If you use in create()/write() its vals! otherwise, its through object.

Beste antwoord

first, i think that yur definition of a m2o field should be dot notated , not underscore... like:
'project_service': fields.many2one('project.service', string='service')

second... if that fields has no value (or it has Null value) it is interpreted as False. so in your report parser, you should check if the field value exists, and suggest some value for cases where it does not exist...

as noted in Tom's answer... in your report (rml or qweb) in part where you call a m2o field value 
(let's say it is o.project_service ) you should do something like:

if o.project_service != Null or o.project_service Is Not False:
    print o.project_service
else:
    print ''


to put it in short (pythonic form) jou can just write:

o.project_service and o.project_service or ''

(in human readable format it would read like: if there is a o.project_service value, write thta value othervise write '' or any other desired value/blank string...)

hope this will explain why and what you need to do in report:)

Avatar
Annuleer
Beste antwoord

Hi,

I think you can ues the same example:

object.project_service and object.project_service.name or ''

Avatar
Annuleer
Auteur

thanks for the answer but i didnt understand you. in fact, why is my field.many2one is empty it returns False??

Gerelateerde posts Antwoorden Weergaven Activiteit
0
mrt. 25
1419
0
jan. 25
3498
1
aug. 23
14865
1
aug. 23
13511
1
jul. 23
10489