How to have all the allow modules in user doctype unchecked by default after saving the new user?

My requirement is to show only specific modules in the “Allow Modules” section in the user doctype, to the sub-admin while creating a new user.

I have done this using the following technique

Now the problem I am facing is, after creating the user only specified modules (that I want) are showing but all the modules (even which are not shown) are getting saved as allowed (checked true) when I am saving the user, so now I want all the modules to be unchecked by default.

How to have all the allow modules in user doctype unchecked by default after saving the new user?

1 Like

i too struck in the same scenario

when i get values for the block modues from the api. it blocks those module[it unchecked those modules] but i want to check those modules particularly, but by default all the module is checked…how can i uncheck other modules and check the specific module from the api.?
[ the passing block modules is getting unchecked but i want them to be checked specifically and the other modules to be uncheked ]

@frappe.whitelist( allow_guest = True )
def insert_user(first_name,email):

user = frappe.get_doc({
    "doctype":"User",
    "first_name":first_name,
    "email":email,
    "new_password":"Frappe@123",
    "roles": [{"role": "System Manager"},{"role": "Blogger"},{"role": "Loan Manager"}],
    "block_modules":[{"module":"Contacts"},{"module":"Core"},{"module":"Email"},{"module": "Desk"},{"module": "Accounts"}] 
    
    })


user.insert(ignore_permissions=True)    
frappe.db.commit()

return f"The data for {first_name} inserted"