From 5d96b71283de27b887e63c1a6840b5dd20fd5562 Mon Sep 17 00:00:00 2001 From: RitvikSardana Date: Mon, 25 Nov 2024 13:18:09 +0530 Subject: [PATCH] fix: change feedback doctype from child to stand alone --- helpdesk/helpdesk/doctype/hd_article/api.py | 7 ++--- .../doctype/hd_article/hd_article.json | 17 ++--------- .../helpdesk/doctype/hd_article/hd_article.py | 15 +++++----- .../hd_article_feedback.js | 8 +++++ .../hd_article_feedback.json | 25 ++++++++++++++-- .../test_hd_article_feedback.py | 29 +++++++++++++++++++ 6 files changed, 71 insertions(+), 30 deletions(-) create mode 100644 helpdesk/helpdesk/doctype/hd_article_feedback/hd_article_feedback.js create mode 100644 helpdesk/helpdesk/doctype/hd_article_feedback/test_hd_article_feedback.py diff --git a/helpdesk/helpdesk/doctype/hd_article/api.py b/helpdesk/helpdesk/doctype/hd_article/api.py index 0547c5cac..aced7e96c 100644 --- a/helpdesk/helpdesk/doctype/hd_article/api.py +++ b/helpdesk/helpdesk/doctype/hd_article/api.py @@ -24,17 +24,16 @@ def get_article(name: str): feedback = { "user_feedback": frappe.db.get_value( - "HD Article Feedback", {"user": user, "parent": name}, "feedback" + "HD Article Feedback", {"user": user, "article": name}, "feedback" ) or None, "total_likes": frappe.db.count( - "HD Article Feedback", {"parent": name, "feedback": "Like"} + "HD Article Feedback", {"article": name, "feedback": "Like"} ), "total_dislikes": frappe.db.count( - "HD Article Feedback", {"parent": name, "feedback": "Dislike"} + "HD Article Feedback", {"article": name, "feedback": "Dislike"} ), } - article["feedbacks"] = None return { **article, diff --git a/helpdesk/helpdesk/doctype/hd_article/hd_article.json b/helpdesk/helpdesk/doctype/hd_article/hd_article.json index d86c6d703..df87fc7b7 100644 --- a/helpdesk/helpdesk/doctype/hd_article/hd_article.json +++ b/helpdesk/helpdesk/doctype/hd_article/hd_article.json @@ -17,9 +17,7 @@ "subtitle", "article_image", "content_section", - "content", - "feedbacks_section", - "feedbacks" + "content" ], "fields": [ { @@ -99,22 +97,11 @@ "fieldname": "subtitle", "fieldtype": "Small Text", "label": "Subtitle" - }, - { - "fieldname": "feedbacks_section", - "fieldtype": "Section Break", - "label": "Feedbacks" - }, - { - "fieldname": "feedbacks", - "fieldtype": "Table", - "label": "feedbacks", - "options": "HD Article Feedback" } ], "links": [], "make_attachments_public": 1, - "modified": "2024-11-24 22:54:55.477514", + "modified": "2024-11-25 13:02:28.644492", "modified_by": "Administrator", "module": "Helpdesk", "name": "HD Article", diff --git a/helpdesk/helpdesk/doctype/hd_article/hd_article.py b/helpdesk/helpdesk/doctype/hd_article/hd_article.py index b29b3c6d1..5761ceaa2 100644 --- a/helpdesk/helpdesk/doctype/hd_article/hd_article.py +++ b/helpdesk/helpdesk/doctype/hd_article/hd_article.py @@ -55,17 +55,16 @@ def before_save(self): @frappe.whitelist() def set_feedback(self, value): user = frappe.session.user - feedback_exists = frappe.db.exists( - "HD Article Feedback", {"user": user, "parent": self.name} + feedback = frappe.db.exists( + "HD Article Feedback", {"user": user, "article": self.name} ) - if feedback_exists: - frappe.db.set_value( - "HD Article Feedback", feedback_exists, "feedback", value - ) + if feedback: + frappe.db.set_value("HD Article Feedback", feedback, "feedback", value) return - self.append("feedbacks", {"user": user, "feedback": value}) - self.save() + frappe.new_doc( + "HD Article Feedback", user=user, article=self.name, feedback=value + ).insert() @property def title_slug(self) -> str: diff --git a/helpdesk/helpdesk/doctype/hd_article_feedback/hd_article_feedback.js b/helpdesk/helpdesk/doctype/hd_article_feedback/hd_article_feedback.js new file mode 100644 index 000000000..0e718eddc --- /dev/null +++ b/helpdesk/helpdesk/doctype/hd_article_feedback/hd_article_feedback.js @@ -0,0 +1,8 @@ +// Copyright (c) 2024, Frappe Technologies and contributors +// For license information, please see license.txt + +// frappe.ui.form.on("HD Article Feedback", { +// refresh(frm) { + +// }, +// }); diff --git a/helpdesk/helpdesk/doctype/hd_article_feedback/hd_article_feedback.json b/helpdesk/helpdesk/doctype/hd_article_feedback/hd_article_feedback.json index 6e10b653e..7d40fc403 100644 --- a/helpdesk/helpdesk/doctype/hd_article_feedback/hd_article_feedback.json +++ b/helpdesk/helpdesk/doctype/hd_article_feedback/hd_article_feedback.json @@ -5,6 +5,7 @@ "doctype": "DocType", "engine": "InnoDB", "field_order": [ + "article", "user", "feedback" ], @@ -22,17 +23,35 @@ "in_list_view": 1, "label": "Feedback", "options": "\nLike\nDislike" + }, + { + "fieldname": "article", + "fieldtype": "Link", + "label": "Article", + "options": "HD Article" } ], "index_web_pages_for_search": 1, - "istable": 1, "links": [], - "modified": "2024-11-24 18:46:11.731463", + "modified": "2024-11-25 13:02:57.975496", "modified_by": "Administrator", "module": "Helpdesk", "name": "HD Article Feedback", "owner": "Administrator", - "permissions": [], + "permissions": [ + { + "create": 1, + "delete": 1, + "email": 1, + "export": 1, + "print": 1, + "read": 1, + "report": 1, + "role": "System Manager", + "share": 1, + "write": 1 + } + ], "sort_field": "creation", "sort_order": "DESC", "states": [] diff --git a/helpdesk/helpdesk/doctype/hd_article_feedback/test_hd_article_feedback.py b/helpdesk/helpdesk/doctype/hd_article_feedback/test_hd_article_feedback.py new file mode 100644 index 000000000..76ab986d5 --- /dev/null +++ b/helpdesk/helpdesk/doctype/hd_article_feedback/test_hd_article_feedback.py @@ -0,0 +1,29 @@ +# Copyright (c) 2024, Frappe Technologies and Contributors +# See license.txt + +# import frappe +from frappe.tests import IntegrationTestCase, UnitTestCase + +# On IntegrationTestCase, the doctype test records and all +# link-field test record depdendencies are recursively loaded +# Use these module variables to add/remove to/from that list +EXTRA_TEST_RECORD_DEPENDENCIES = [] # eg. ["User"] +IGNORE_TEST_RECORD_DEPENDENCIES = [] # eg. ["User"] + + +class UnitTestHDArticleFeedback(UnitTestCase): + """ + Unit tests for HDArticleFeedback. + Use this class for testing individual functions and methods. + """ + + pass + + +class IntegrationTestHDArticleFeedback(IntegrationTestCase): + """ + Integration tests for HDArticleFeedback. + Use this class for testing interactions between multiple components. + """ + + pass