Skip ke Konten
Menu
Pertanyaan ini telah diberikan tanda
4 Replies
211 Tampilan

Hi guys!!!!!

Please, when i make a print on my field.many2one i get this: (id, name_field)

'project_service': fields.many2one ('project_service_line', string= 'Services'),

Please who knows the error please!!!!

I need help please


Avatar
Buang

The declaration of the fileld must be as below 'project_service': fields.many2one('parentModel','Services') It should be model name not the class name? Please describe which error you are getting. and the line of code you used. If you user print project_service, it will display the id of the selected value.

Penulis

Thanks a lot for the answer!! But, the field is declared correctly: 'project_service': fields.many2one ('project_service_line', string= 'Services'), where project_service_line is the name of the model. But when i run my function and i display the field i found only the id and when i want to see the field i found False or (id, name_field)

Penulis

Please, take a look to the function and tell me which one is correct

Jawaban Terbai

m2o field contains only id of a record in other model (2one) so... 

when you print o.project_service the result on report will be as you already got... if you want to display just name you should consider writing something like: 

o.project_service.name    ... or o.projet_service.code... or maybe even: 

[[o.project_service.code]] - [[o.project_service.name]]  to get : code - name printed out...


hope it helps


EDIT 1. after additional question:yout method could be written better/faster like this:.

cr.execute("select id, int_service, ext_service, unit_service, int_service_unit, ext_service_unit, service_type, service_id from project_services")

ret=cr.dictfetchall()

retunr ret

this 2 lines will do the same as your code starting with:

obj = self.pool.get('project_service')  ...

return ret


This part you should check: 

obj_ids = obj.search(cr, uid, [], context=context)

if you need only project_service related to selected project_id , then this line should be like:

obj_ids = obj.search(cr, uid, [('project_id','=',project_id)])

(or use:

cr.execute("select id, project_id, int_service, ext_service, unit_service, int_service_unit, ext_service_unit, service_type, service_id from project_services where project_id = %(project_id)s", {'project_id' : project_id})

or 

cr.execute("select id, project_id, int_service, ext_service, unit_service, int_service_unit, ext_service_unit, service_type, service_id from project_services where project_id = %s" % project_id)

both synthax will work )

test this out, see if it will work...

Avatar
Buang
Penulis

Please, take a look to the function and tell me which one is correct

Penulis

Please answer me!! 'project_services': (1, u'fixe_italie') Thats what i get

Penulis Jawaban Terbai

Here is my function. It works very well.

Ist it Fine to make like that in project_services.Which one is correct??????????

def get_inputs(self, cr, uid,ids, state, project, context=None):

ret = []

print ('--------------------get_inputs---------------------')

project_id = _get_project_id_by_name (self,cr, uid, project, context)

print ('project =')

print project_id

obj = self.pool.get('project_service')

obj_ids = obj.search(cr, uid, [], context=context)

res = obj.read(cr, uid, obj_ids, ['id', 'int_service','ext_service','unit_service','int_service_unit','ext_service_unit','service_type','service_id'], context)

print res

for r in res :

inputs = {

'project_services': r['id'] or id,

'project_id' : project_id,

'int_services': r['int_service'],

'ext_services': r['ext_service'],

'unit_services': r['unit_service'],

'int_services_unit': r['int_service_unit'],

'ext_services_unit': r['ext_service_unit'],

'service_type': r['service_type'],

'service_idd': r['service_id'],

}

ret += [inputs]

print ('------------liste de services-------')

print ret

return ret

Avatar
Buang

this method is wery confusing... but if you ask what should you use for bolded then it should be r['id'] defintly... but this is sooo not good... your obj_ids variable will always contain ALL the records from 'project_service' (because you didnt put any select condition) ... so you will always read all the records ... then... using += for appending to lis variable is not pythonic... you shoul use : ret.append(inputs) instead of ret += [inputs] ...and most unclear on this method is : where do you use it? in report parser or as a class method?

Post Terkait Replies Tampilan Aktivitas
0
Mar 25
1414
0
Jan 25
3493
1
Agu 23
14853
change password Diselesaikan
1
Agu 23
13504
1
Jul 23
10484