'Check if permission exists for reference document'

def check_reference_doc_permission(self):

    if self.attached_to_name:
        try:
            if ((not self.flags.ignore_permissions) and (not frappe.has_permission(self.attached_to_doctype, u'write', self.attached_to_name))):
                frappe.throw(frappe._(u'No    permission    to    write    /    remove.'), frappe.PermissionError)
        except frappe.DoesNotExistError:
            pass
