Se rendre au contenu
Menu
Cette question a été signalée
1 Répondre
53418 Vues

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
Ignorer
Meilleure réponse

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
Ignorer
Auteur

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 ?

Auteur

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 ?

Auteur

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.

Publications associées Réponses Vues Activité
2
mars 16
7005
2
janv. 24
14299
0
mars 25
1148
0
janv. 25
3194
1
août 23
14458