def delete_file(self): """If file not attached to any other record, delete it""" if self.file_name and self.content_hash and (not frappe.db.count("File", {"content_hash": self.content_hash, "name": ["!=", self.name]})): delete_file_data_content(self) elif self.file_url: delete_file_data_content(self, only_thumbnail=True)
def on_trash(self): if self.attached_to_name: # check persmission try: if not getattr(self, 'ignore_permissions', False) and \ not frappe.has_permission(self.attached_to_doctype, "write", self.attached_to_name): frappe.msgprint(frappe._("No permission to write / remove."), raise_exception=True) except frappe.DoesNotExistError: pass # if file not attached to any other record, delete it if self.file_name and self.content_hash and (not frappe.db.count("File Data", {"content_hash": self.content_hash, "name": ["!=", self.name]})): delete_file_data_content(self)
def on_trash(self): if self.attached_to_name: # check persmission try: if not getattr(self, 'ignore_permissions', False) and \ not frappe.has_permission(self.attached_to_doctype, "write", self.attached_to_name): frappe.msgprint(frappe._("No permission to write / remove."), raise_exception=True) except frappe.DoesNotExistError: pass # if file not attached to any other record, delete it if self.file_name and not frappe.db.count("File Data", {"content_hash": self.content_hash, "name": ["!=", self.name]}): delete_file_data_content(self)