Community mailing list archives

function to disable employee's fields(resource_id, user_id and product_id)

Emna Ragheb
- 02/18/2015 18:55:41

Hello community , 

I whould like to create a function wich disable the resource_id, the user_id and the product_id related to the employee by clicking on the button that calls this function.

Here is my essay:

def disable_employee(self, cr, uid, ids, context=None):




            #disable employee's resource

            obj = self.pool.get('resource.resource').browse(cr, uid, uid, context=context)

            for res in obj:

                self.write(cr, uid, ids, {'active':True}, context=None)


            #disable res_users's id 

            obj_user = obj.browse(cr,uid,ids,context=context)[0]

            user_id = obj_user['user_id'].id

            obju = self.pool.get('res.users')

            deu = obju.write(cr, uid, int(user_id), {'active':False}, context=None)


            #disable product

            name = obj_user['name']

            #print name

            objp = self.pool.get('product.product')

            objpid =, uid, [('name', '=', name)])


            dep = objp.write(cr, uid, objpid, {'active':False}, context=None)

        except Exception, ex:

            return False

        return False

I'm using Odoo 8, help me please to resolve that , when I tested it only the resouce is deactivated, I didn't get any error but the function doesn't work correctly and I don't know why .

thank you !