Skip to Content
Menu
You need to be registered to interact with the community.
This question has been flagged
14 Odgovori
32388 Prikazi

thanks in Advance please define it in detail...

Avatar
Opusti
Best Answer

Hi,

self.env.uid will give the id of the current user

and

self.env.user will return the current user record

Example

self.env.uid - 1
self.env.user - res.users(1,)

Thanks

Avatar
Opusti
Best Answer

hi, Usman Farzand


self.env.uid will return Id of Current Login User

self.env.user will return Current User Record





Avatar
Opusti

Hey,

Earlier when i have checked my answer it was accepted and have green tick in it, and now it seems the green tick for you answer.

Anything new you have added in the answer ? or my answer is wrong ? was not my clear ?

* was not my answer clear ?

no you are right, but you not mentation that Current Login User. i think

What does the meaning of current user ? Didn't see that ? Are you saying current user and current login user is different ?

Look even in your answer you have used current user record.

Avtor

you both are right can you please any one tell me if it's different from each other

self.env.uid - 1

self.env.user - res.users(1,)

then why condition is same for both ????

@api.multi

def do_clear_done(self):

domain = [('is_done', '=', True),'|',('user_id', '=', self.env.uid),

('user_id', '=', False)]

dones = self.search(domain)

dones.write({'active': False})

return True

@api.multi

def do_toggle_done(self):

for task in self:

if task.user_id != self.env.user:

raise ValidationError('Only the Responsible can do this!')

return super(TodoTask, self).do_toggle_done()

if condition chk and domain chk in same way can any one tell me more in detail sorry i'm beginner

Avtor

('user_id', '=', self.env.uid),

if task.user_id != self.env.user:

noted point why ?

see the thing is, when You simply write 'user_id' than it will return one Object like res.users(1,)

and if you want to put condition on it than u required Object in other side also otherwise it give Error to you. so we use self.env.user.

And For the Domain case i think while You Search any Record or Applying Domain on Record then you need ID of the Record, so domain = [('is_done', '=', True),'|',('user_id', '=', self.env.uid),

Avtor

@ Palkesh Baraiya if i write

if task.user_id != self.env.id:

excpt this

if task.user_id != self.env.user

is it will correct ?

thanks for answer i clear my more concept....

Look If you want to Compare only ID than u can write

if task.user_id.id != self.env.uid:

it will compare your 'user_id' with current Login User ID. like

if 'user_id' = 1 and Current Login user('self.env.uid') = 1

than Condition was fulfil.

and other case was,

if task.user_id != self.env.user

it will use 'user_id' as object like 'res.partner(1,)' and for self.env.user as 'Current Login User Object like res.users(1,)'

Avtor

excellent thank you soo much @Palkesh Baraiya....thanks again...

Best Answer

self.env.uid will return Database table Id  (ex: admin login --> 1)

self.env.user will return ORM browse object (ex: admin login --> res.user(1))

Avatar
Opusti
Related Posts Odgovori Prikazi Aktivnost
0
maj 20
2970
1
mar. 15
6366
0
avg. 16
2621
3
apr. 25
12007
1
okt. 19
2908