Skip to content

Commit

Permalink
fix: change feedback doctype from child to stand alone
Browse files Browse the repository at this point in the history
  • Loading branch information
RitvikSardana committed Nov 25, 2024
1 parent 6c70954 commit 5d96b71
Show file tree
Hide file tree
Showing 6 changed files with 71 additions and 30 deletions.
7 changes: 3 additions & 4 deletions helpdesk/helpdesk/doctype/hd_article/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
17 changes: 2 additions & 15 deletions helpdesk/helpdesk/doctype/hd_article/hd_article.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,7 @@
"subtitle",
"article_image",
"content_section",
"content",
"feedbacks_section",
"feedbacks"
"content"
],
"fields": [
{
Expand Down Expand Up @@ -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",
Expand Down
15 changes: 7 additions & 8 deletions helpdesk/helpdesk/doctype/hd_article/hd_article.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
Original file line number Diff line number Diff line change
@@ -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) {

// },
// });
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"doctype": "DocType",
"engine": "InnoDB",
"field_order": [
"article",
"user",
"feedback"
],
Expand All @@ -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": []
Expand Down
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 5d96b71

Please sign in to comment.