Skip to Content
Menu
Dette spørgsmål er blevet anmeldt
1 Svar
53613 Visninger

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

Avatar
Kassér
Bedste svar

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.

Avatar
Kassér
Forfatter

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 ?

Forfatter

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 ?

Forfatter

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.

Related Posts Besvarelser Visninger Aktivitet
2
mar. 16
7117
2
jan. 24
14399
0
mar. 25
1295
0
jan. 25
3404
1
aug. 23
14721