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
Odoo is the world's easiest all-in-one management software.
It includes hundreds of business apps:
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
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...
Please, take a look to the function and tell me which one is correct
Please answer me!! 'project_services': (1, u'fixe_italie') Thats what i get
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
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?
Tạo tài khoản ngay hôm nay để tận hưởng các tính năng độc đáo và tham gia cộng đồng tuyệt vời của chúng tôi!
Đăng kýBài viết liên quan | Trả lời | Lượt xem | Hoạt động | |
---|---|---|---|---|
|
0
thg 3 25
|
1418 | ||
|
0
thg 1 25
|
3495 | ||
|
1
thg 8 23
|
14856 | ||
change password
Đã xử lý
|
|
1
thg 8 23
|
13509 | |
|
1
thg 7 23
|
10487 |
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.
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)
Please, take a look to the function and tell me which one is correct