콘텐츠로 건너뛰기
메뉴
커뮤니티에 참여하려면 회원 가입을 하시기 바랍니다.
신고된 질문입니다
1 회신
53574 화면

Im working with Odoo V8.

Can anybody  help with this error?

AttributeError: 'list' object has no attribute 'id'

what i did is the below:

vals.update({
'name': name,
'date_departure': datetime_departure,
'date_arrival': datetime_arrival
})
service = super(ServiceClass, self).create(vals)

and save the service id like this:

services.append((0, 0, service_id.id))

and finally return the services list. like this:

return services

so, when I save, it returns: AttributeError: 'list' object has no attribute 'id'

Can you please provide any solution? Thanks in advanced

아바타
취소
베스트 답변

Hi, 

services.append((4, service.id, 0))
note that :
  • (0, _, values) adds a new record created from the provided value dict.
  • (4, id, _) adds an existing record of id id to the set

in your case, you create a service and want to add it to a list of services.

아바타
취소
작성자

Thanks for answering my question I really appreciated it.

Look, what i have in my code now including your solution is :

for values in range(1, 7, 2):

if values > 1:

datetime_departure = datetime_departure + timedelta(

days=1)

datetime_arrival = datetime_arrival + timedelta(

days=1)

vals.update({

'name': name,

'date_departure': datetime_departure,

'date_arrival': datetime_arrival

})

service_id = super(ServiceClass, self).create(vals)

services.append((4, service_id.id, 0))

But, it doesn't work.

print '00', services

services.append((4, service_id.id, 0))

print '11', services

can you tell me the output ?

작성자

Thanks again for the answer.

When finally the function ends, it returns this: [(4, 48, 0), (4, 49, 0), (4, 50, 0)]

that is the final output doing return services

But, id I do return service_id like you suggest, it doesn't return the last id? and what i need is that it returns all the created ids.

Thanks

In ORM functions, you always need to return the super. to keep other calls from the function, otherwise it may break other treatments.

to give u a relevant answer, can you tell me why you need services ? in what case you use the data from services ?

작성자

Ok. I have a previous view wich has a One2many field. So, when I create an instance of that model(the One2many) it will be created as many times as the value of a field that the user introduces. For example, in the model there is a field called frequency, if frequency=3 I need that that model creates 3 times itself and in the tree of the One2many show those 3 records. Hope you understand... Thanks again for your time.

관련 게시물 답글 화면 활동
2
3월 16
7071
2
1월 24
14380
0
3월 25
1281
0
1월 25
3365
1
8월 23
14659