This question has been flagged
2 Replies
6556 Views

Hi,

I have built an app for will which control access to various screens/fields via a field with in the app itself.  I will have the assigneesManagers field (with other fields)


assigneesManagers = fields.Many2many('res.users', 'user_assignee_managers', 'npirequest_id','resusers_id', 'Assignees - Management')


This field will be populated by the person responsible  and then when the form is pushed through to the next workflow state the application should be checking that the currently logged user exists within this many2many field (assigneesManagers), then we need to allow access to this user to update the orders faster.    


The function being called when I push through the record from "draft" state to the next step only provides the one arguement of self.   The only way I know to do this is to do an SQL query which requires the presence of the "Cr' object which doesn't seem to exist.  I only have "self"

--------------------------------------------------------------------------------------------------------

@api.multi def action_draft(self):

self.assigneesManagers = [(0,[15])]

self.state = 'draft'

self.statePurchasing = 'draft' self.stateManufacturing = 'draft'

--------------------------------------------------------------------------------------------

I want to add another line to this that gets the logged in users name and then searches the assigneesManagers field to check if the user exists as an assigned manager.  


Could somebody please help point me in the right direction for being able to do this.  Just need to be able to find a match in a many2many field and return try if a match is found. 


Looking forward to any rseponses.


Thanks,
Damien


Avatar
Discard
Best Answer

Hi,

1. Here you can access CR by self._cr or self.env.cr. for Query execution try self._cr.execute("yourQuery")

2. You can get the logged in user by the following code
     user_id = self.env.user.id

     user_name = self.env.user.name

     related_partner = self.env.user.partner_id.id

I hope I have given the hints. Now you can compare using these values.

Avatar
Discard
Author Best Answer

That worked!  Thankyou so much!

Avatar
Discard

You are Welcome