'Reset `permissions` with Custom DocPerm if exists'

def set_custom_permissions(self):

    if (frappe.flags.in_patch or frappe.flags.in_import or frappe.flags.in_install):
        return
    if ((not self.istable) and (self.name not in (u'DocType', u'DocField', u'DocPerm', u'Custom    DocPerm'))):
        custom_perms = frappe.get_all(u'Custom    DocPerm', fields=u'*', filters=dict(parent=self.name), update=dict(doctype=u'Custom    DocPerm'))
        if custom_perms:
            self.permissions = [Document(d) for d in custom_perms]
