What is the real difference between them?
The system creates a record in both: I was a guest one for customization and another for the system, but why are they separate with different names with the same structure?
DocPerm = System permissions from the DocType JSON file. Gets overwritten on app updates.
Custom DocPerm = Site-specific permission overrides. Survives app updates and takes precedence over DocPerm.
Frappe checks Custom DocPerm first, falls back to DocPerm if none exists. This separation lets app developers ship defaults while site admins customize without touching app code.
@marc_centura thx for your clearance
As you said, the DocPerm will be in the app level, while the Custom DocPerm will be in the site level, and its have the highest priority now. If I want to add my permission in my app of the other doctype in the other app without using the custom docperm, what should I use
Now I use this way add them from the custom docperm, then export them to fixtures.
do you have another way to do it?
What I understood:
You want to add permissions for DocTypes from another app from your app, without using Role Permission Manager + fixtures.
I think Custom DocPerm is exactly what you want/should use here.
What I would do is creating Custom DocPerm records during install and/or as patch. Something like this (note i did not test the code)
import frappe
from frappe.permissions import setup_custom_perms
def execute():
role = “My App Manager”
doctype = “Sales Invoice”
# create role if missing
if not frappe.db.exists("Role", role):
frappe.get_doc({
"doctype": "Role",
"role_name": role
}).insert(ignore_permissions=True)
# make sure custom permissions are enabled for this doctype
setup_custom_perms(doctype)
values = {
"doctype": "Custom DocPerm",
"parent": doctype,
"role": role,
"permlevel": 0,
"read": 1,
"write": 1,
"create": 1,
}
# update if exists, otherwise create
name = frappe.db.exists("Custom DocPerm", {
"parent": doctype,
"role": role,
"permlevel": 0
})
if name:
doc = frappe.get_doc("Custom DocPerm", name)
doc.update(values)
doc.save()
else:
frappe.get_doc(values).insert()
frappe.db.commit()
thx for code
Is this way is logic i will wrote a lot of Custom DocPerm here?