Skip to Content
Meniu
Trebuie să fiți înregistrat pentru a interacționa cu comunitatea.
Această întrebare a fost marcată
6 Răspunsuri
235 Vizualizări

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

Imagine profil
Abandonează

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.

Cel mai bun răspuns

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)


Imagine profil
Abandonează
Autor

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.

Cel mai bun răspuns

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:)

Imagine profil
Abandonează
Cel mai bun răspuns

Hi,

I think you can ues the same example:

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

Imagine profil
Abandonează
Autor

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

Related Posts Răspunsuri Vizualizări Activitate
0
mar. 25
1418
0
ian. 25
3495
1
aug. 23
14856
1
aug. 23
13509
1
iul. 23
10486