Skip to content

Commit

Permalink
fix: assign & send notification if task is created
Browse files Browse the repository at this point in the history
  • Loading branch information
shariquerik committed Sep 23, 2024
1 parent 29c709e commit f09364e
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 5 deletions.
4 changes: 2 additions & 2 deletions crm/fcrm/doctype/crm_notification/crm_notification.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
"fieldtype": "Select",
"in_list_view": 1,
"label": "Type",
"options": "Mention\nWhatsApp",
"options": "Mention\nTask\nWhatsApp",
"reqd": 1
},
{
Expand Down Expand Up @@ -116,7 +116,7 @@
],
"index_web_pages_for_search": 1,
"links": [],
"modified": "2024-04-25 16:26:07.484857",
"modified": "2024-09-23 17:22:06.973897",
"modified_by": "Administrator",
"module": "FCRM",
"name": "CRM Notification",
Expand Down
30 changes: 28 additions & 2 deletions crm/fcrm/doctype/crm_notification/crm_notification.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,35 @@
# For license information, please see license.txt

import frappe
from frappe import _
from frappe.model.document import Document


class CRMNotification(Document):
def on_update(self):
frappe.publish_realtime("crm_notification")
def on_update(self):
frappe.publish_realtime("crm_notification")

def notify_user(args):
"""
Notify the assigned user
"""
args = frappe._dict(args)
if args.owner == args.assigned_to:
return

values = frappe._dict(
doctype="CRM Notification",
from_user=args.owner,
to_user=args.assigned_to,
type=args.notification_type,
message=args.message,
notification_text=args.notification_text,
notification_type_doctype=args.doctype,
notification_type_doc=args.name,
reference_doctype=args.reference_doctype,
reference_name=args.reference_docname,
)

if frappe.db.exists("CRM Notification", values):
return
frappe.get_doc(values).insert()
46 changes: 45 additions & 1 deletion crm/fcrm/doctype/crm_task/crm_task.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,55 @@
# Copyright (c) 2023, Frappe Technologies Pvt. Ltd. and contributors
# For license information, please see license.txt

# import frappe
import frappe
from frappe import _
from frappe.model.document import Document
from frappe.desk.form.assign_to import add as assign
from crm.fcrm.doctype.crm_notification.crm_notification import notify_user


class CRMTask(Document):
def after_insert(self):
self.assign_to()

def assign_to(self):
if self.assigned_to:
assign({
"assign_to": [self.assigned_to],
"doctype": self.doctype,
"name": self.name,
"description": self.title or self.description,
})
self.notify_assigned_user()

def notify_assigned_user(self):
"""
Notify the assigned user about the task assignment
"""

owner = frappe.get_cached_value("User", self.owner, "full_name")
notification_text = f"""
<div class="mb-2 leading-5 text-gray-600">
<span class="font-medium text-gray-900">{ owner }</span>
<span>{ _('assigned a new task {0} to you').format(
f'<span class="font-medium text-gray-900">{ self.title }</span>'
) }</span>
</div>
"""

notify_user({
"owner": self.owner,
"assigned_to": self.assigned_to,
"notification_type": "Task",
"message": self.description,
"notification_text": notification_text,
"doctype": self.doctype,
"name": self.name,
"reference_doctype": self.reference_doctype,
"reference_docname": self.reference_docname,
})


@staticmethod
def default_list_data():
columns = [
Expand Down

0 comments on commit f09364e

Please sign in to comment.