Ir al contenido
Menú
Se marcó esta pregunta
1 Responder
7738 Vistas

Hi, 

i have a function here:

def btnSet(self,cr,uid,ids,values,context=None):
                self.write(cr,uid,ids,{'current':'true'})

                return True

I know that ids is the id record , for example self.write(cr,uid,[1],{'current':'true'}) 

[1] -> for one only.      [1,2,3]-> for multiple record   [???] -> for all, (just with the same uid, not all record with varying uid)

 

record 1's current field will be set to 'true'   what if i want all record for that certain uid? (its like changing all the values of 'current' field to true.

self.write(cr,uid,????,{'current':'true'}) 

 

 

Avatar
Descartar
Mejor respuesta

uid - Current User Login ID so it shows all the record same ID.

using write method below code to update single record:-

self.write(cr,uid,[ids],{'current':'true'}) 

using write method below code to update multile record:-

for id in ids:
    self.write(cr,uid,[id],{'current':'true'})

Edit:-             

search_ids = self.search(cr, uid, [('create_uid','=',uid)])
 if search_ids:
      for id in search_ids:
          self.write(cr,uid,[id],{'current':False})

Avatar
Descartar
Autor

Sorry, i dont get it.. sorry for my foolishness .. could you help me understand what if its like this for example my records are: id create_uid addr write_uid current 3 5 SG 1 f 4 5 PH 1 f 5 1 PH1 5 t 1 5 PH2 5 t for example i logged as # 5, ofcourse all create_uid with #5 will be shown and if i want to modify (fields with id 3,4,1) their 'current' fields i will just self.write(cr,uid,[3,4,1],{'current':'true'}) its just like hardcoding. what if i want "all" which has contain_id of '5' to be all 'f' what would i change?

I'm not sure I follow you. Based on your requirement search the records based on condition it return search record ids and update the records.

Autor

your editted code works, search_ids = self.search(cr, uid, [('create_uid','=',uid)]) if search_ids: for id in search_ids: self.write(cr,uid,[id],{'current':False}) this is what iwanted can you explain the flow please,

using ORM search method based on condition it return matched condition LIst of record ids. And after using search List of ids update the record using write method.

Autor

why you replace [ids] with [('create_uid','=',uid)] can you explain ? thx

see the link https://doc.odoo.com/6.0/developer/2_5_Objects_Fields_Methods/methods/ Expressing a search domain (args) Each tuple in the search domain needs to have 3 elements, in the form: ('field_name', 'operator', value)

Autor

thank you so much prakash!

Publicaciones relacionadas Respuestas Vistas Actividad
0
sept 19
98
1
jul 17
4145
4
ago 16
8360
1
may 16
4959
1
mar 16
4985