From 5d4feb5dbb264611d2d257eea8f8f45b9636fbae Mon Sep 17 00:00:00 2001 From: gavin Date: Tue, 4 Aug 2020 17:45:14 +0530 Subject: [PATCH] feat: Convenience APIs for tags (#11088) Co-authored-by: Suraj Shetty <13928957+surajshetty3416@users.noreply.github.com> --- frappe/model/document.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/frappe/model/document.py b/frappe/model/document.py index 69a781d6d1..316c576f55 100644 --- a/frappe/model/document.py +++ b/frappe/model/document.py @@ -1307,6 +1307,16 @@ class Document(BaseDocument): users = set([assignment.owner for assignment in assignments]) return users + def add_tag(self, tag): + """Add a Tag to this document""" + from frappe.desk.doctype.tag.tag import DocTags + DocTags(self.doctype).add(self.name, tag) + + def get_tags(self): + """Return a list of Tags attached to this document""" + from frappe.desk.doctype.tag.tag import DocTags + return DocTags(self.doctype).get_tags(self.name).split(",")[1:] + def execute_action(doctype, name, action, **kwargs): """Execute an action on a document (called by background worker)""" doc = frappe.get_doc(doctype, name)