Delegate a job of delegator to delegatee as permissions

Well , I am building this small app which help the company to achieve the delegation stage . For example If i have a user who will be leave for 10 days and i want to delegate his tasks - approve prunches- to another user so i build in the custom app a doctype with the basic info delegateor , delegatee , start , end date ,a and child table return the doctypes of this delegator.

in py once i try to achieve the goal and give the delegatee access to that delegator doctype i can’t how can i peak this certain point

thanks for all .

  • Actually it worked fine by fetch the delegator role then i assigement it to the delegatee which u need to be careful to few things :

1- if u are going to add a role using the add_roles() method that user shouldn’t have a role profile

so if the delegatee use roles the delegator should pass roles not profile because the profile will deatach the roles of that use , …,etc

notice that u can convert from profile role to roles or viceversa in the end just follow the follow of the delegatee so if it has a profile add a profile or create one with specific roles using the code i think that is all thanks

snippet code might help :

def add_user_roles(user, roles):

    if not user or not roles:

return




user = frappe.get_doc("User", user) if isinstance(user, str) else user

current_roles = {row.role for row in user.roles}

for role in sorted(set(roles) - current_roles):

if role:

user.append("roles", {"role": role})

user.save(ignore_permissions=True)





def add_user_role_profiles(user, role_profiles):

if not user or not role_profiles:

return




user = frappe.get_doc("User", user) if isinstance(user, str) else user

current_profiles = {row.role_profile for row in user.role_profiles}

for role_profile in sorted(set(role_profiles) - current_profiles):

if role_profile:

user.append("role_profiles", {"role_profile": role_profile})

user.save(ignore_permissions=True)