Odoo Help

Welcome!

This community is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.

0

ids parameter in write ORM function help.

orm
By
Lakay lakay
on 9/15/14, 12:20 AM 1,109 views

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'}) 

 

 

0

Prakash

--Prakash--
3173
| 5 4 7
Bikaner, India
--Prakash--

OpenERP Devloper at SunARC Technology

Prakash
On 9/15/14, 12:52 AM

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})

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?

Lakay lakay
on 9/15/14, 1:57 AM

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.

Prakash
on 9/15/14, 2:14 AM

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,

Lakay lakay
on 9/15/14, 2:48 AM

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.

Prakash
on 9/15/14, 2:56 AM

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

Lakay lakay
on 9/15/14, 3:07 AM

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)

Prakash
on 9/15/14, 3:26 AM

thank you so much prakash!

Lakay lakay
on 9/15/14, 4:02 AM

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

1 follower(s)

Stats

Asked: 9/15/14, 12:20 AM
Seen: 1109 times
Last updated: 3/16/15, 8:10 AM