Ir al contenido
Menú
Se marcó esta pregunta
14 Respuestas
32323 Vistas

thanks in Advance please define it in detail...

Avatar
Descartar
Mejor respuesta

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
Descartar
Mejor respuesta

hi, Usman Farzand


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

self.env.user will return Current User Record





Avatar
Descartar

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.

Autor

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

Autor

('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),

Autor

@ 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,)'

Autor

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

Mejor respuesta

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
Descartar
Publicaciones relacionadas Respuestas Vistas Actividad
0
may 20
2931
1
mar 15
6316
0
ago 16
2591
3
abr 25
11739
1
oct 19
2864