Skip to Content
Menu
This question has been flagged
5 Replies
4606 Views

i want to change task in project module so that only task initiator can change the stages of task for this i need current user id and task initiator id .

current login user can get as

current_user = fields.Many2one('res.users','Current User', default=lambda self: self.env.user.id) 
now i want to get task initiator id how can i get ? so that i can compare theme.
Avatar
Discard
Best Answer

Hi,

In all models there is a field named create_uid , which will record the id of the user who created the record. So in your case you can use the create_uid field as task initiator or better you can create/use any of existing fields in the model to handle it. 

Now lets assume the field is create_uid itself, then on changing the state of tasks, it might be either by a button click or just drag and drop, so inside the write function or corresponding function, you can get the task initiator id from self.create_uid then you can compare it with the logged in user.

You can get the current logged in user from this : self.env.user.id

So you can compare it like this,

if self.env.user.id == self.create_uid:
print("yes")
else:
raise warning

Thanks

Avatar
Discard
Author

thank you so much Its very helpful to me

if this helpful pls acept this as answer ..

Best Answer

Just in case somebody would be interested how it works with automated actions - you have to add .id to create_uid in order to get only iud, otherwise it will return smth like:

res.users(10,)


So sample code for automated actions would be :

if env.user.id == record.create_uid.id:

     raise Warning('Editor = Creator!')

else:

     raise Warning('You are not allowed to edit tasks created by other users')


Avatar
Discard

This was really usefull, i was struggling, i was missing thr .id, many thanks

Best Answer

To know the details of a model and the fields
please go to settings in debug mode
under technical ->database structure ->models
search with model name and u can see all the fields

Avatar
Discard