Skip to Content
Меню
Вам необхідно зареєструватися, щоб взаємодіяти зі спільнотою.
Це запитання позначене
6 Відповіді
237 Переглядів

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

Аватар
Відмінити

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.

Найкраща відповідь

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)


Аватар
Відмінити
Автор

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.

Найкраща відповідь

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

Аватар
Відмінити
Найкраща відповідь

Hi,

I think you can ues the same example:

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

Аватар
Відмінити
Автор

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

Related Posts Відповіді Переглядів Дія
0
бер. 25
1419
0
січ. 25
3495
1
серп. 23
14860
change password Вирішено
1
серп. 23
13510
1
лип. 23
10488