fix: assign & send notification if task is created
This commit is contained in:
parent
29c709e424
commit
f09364ee94
@ -34,7 +34,7 @@
|
||||
"fieldtype": "Select",
|
||||
"in_list_view": 1,
|
||||
"label": "Type",
|
||||
"options": "Mention\nWhatsApp",
|
||||
"options": "Mention\nTask\nWhatsApp",
|
||||
"reqd": 1
|
||||
},
|
||||
{
|
||||
@ -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",
|
||||
|
||||
@ -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()
|
||||
@ -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 = [
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user