feat: add attachments in comment
This commit is contained in:
parent
47aa9a4669
commit
ee678f97c8
@ -105,6 +105,7 @@ def get_deal_activities(name):
|
|||||||
"creation": comment.creation,
|
"creation": comment.creation,
|
||||||
"owner": comment.owner,
|
"owner": comment.owner,
|
||||||
"content": comment.content,
|
"content": comment.content,
|
||||||
|
"attachments": get_attachments('Comment', comment.name),
|
||||||
"is_lead": False,
|
"is_lead": False,
|
||||||
}
|
}
|
||||||
activities.append(activity)
|
activities.append(activity)
|
||||||
@ -121,7 +122,7 @@ def get_deal_activities(name):
|
|||||||
"recipients": communication.recipients,
|
"recipients": communication.recipients,
|
||||||
"cc": communication.cc,
|
"cc": communication.cc,
|
||||||
"bcc": communication.bcc,
|
"bcc": communication.bcc,
|
||||||
"attachments": get_attachments(communication.name),
|
"attachments": get_attachments('Communication', communication.name),
|
||||||
"read_by_recipient": communication.read_by_recipient,
|
"read_by_recipient": communication.read_by_recipient,
|
||||||
},
|
},
|
||||||
"is_lead": False,
|
"is_lead": False,
|
||||||
@ -216,6 +217,7 @@ def get_lead_activities(name):
|
|||||||
"creation": comment.creation,
|
"creation": comment.creation,
|
||||||
"owner": comment.owner,
|
"owner": comment.owner,
|
||||||
"content": comment.content,
|
"content": comment.content,
|
||||||
|
"attachments": get_attachments('Comment', comment.name),
|
||||||
"is_lead": True,
|
"is_lead": True,
|
||||||
}
|
}
|
||||||
activities.append(activity)
|
activities.append(activity)
|
||||||
@ -232,7 +234,7 @@ def get_lead_activities(name):
|
|||||||
"recipients": communication.recipients,
|
"recipients": communication.recipients,
|
||||||
"cc": communication.cc,
|
"cc": communication.cc,
|
||||||
"bcc": communication.bcc,
|
"bcc": communication.bcc,
|
||||||
"attachments": get_attachments(communication.name),
|
"attachments": get_attachments('Communication', communication.name),
|
||||||
"read_by_recipient": communication.read_by_recipient,
|
"read_by_recipient": communication.read_by_recipient,
|
||||||
},
|
},
|
||||||
"is_lead": True,
|
"is_lead": True,
|
||||||
@ -249,10 +251,10 @@ def get_lead_activities(name):
|
|||||||
return activities, calls, notes, tasks
|
return activities, calls, notes, tasks
|
||||||
|
|
||||||
@redis_cache()
|
@redis_cache()
|
||||||
def get_attachments(name):
|
def get_attachments(doctype, name):
|
||||||
return frappe.db.get_all(
|
return frappe.db.get_all(
|
||||||
"File",
|
"File",
|
||||||
filters={"attached_to_doctype": "Communication", "attached_to_name": name},
|
filters={"attached_to_doctype": doctype, "attached_to_name": name},
|
||||||
fields=["name", "file_name", "file_url", "file_size", "is_private"],
|
fields=["name", "file_name", "file_url", "file_size", "is_private"],
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
@ -1,3 +1,5 @@
|
|||||||
|
from collections.abc import Iterable
|
||||||
|
|
||||||
import frappe
|
import frappe
|
||||||
from frappe import _
|
from frappe import _
|
||||||
from bs4 import BeautifulSoup
|
from bs4 import BeautifulSoup
|
||||||
@ -54,4 +56,41 @@ def extract_mentions(html):
|
|||||||
mentions.append(
|
mentions.append(
|
||||||
frappe._dict(full_name=d.get("data-label"), email=d.get("data-id"))
|
frappe._dict(full_name=d.get("data-label"), email=d.get("data-id"))
|
||||||
)
|
)
|
||||||
return mentions
|
return mentions
|
||||||
|
|
||||||
|
@frappe.whitelist()
|
||||||
|
def add_attachments(name: str, attachments: Iterable[str | dict]) -> None:
|
||||||
|
"""Add attachments to the given Comment
|
||||||
|
|
||||||
|
:param name: Comment name
|
||||||
|
:param attachments: File names or dicts with keys "fname" and "fcontent"
|
||||||
|
"""
|
||||||
|
# loop through attachments
|
||||||
|
for a in attachments:
|
||||||
|
if isinstance(a, str):
|
||||||
|
attach = frappe.db.get_value("File", {"name": a}, ["file_url", "is_private"], as_dict=1)
|
||||||
|
file_args = {
|
||||||
|
"file_url": attach.file_url,
|
||||||
|
"is_private": attach.is_private,
|
||||||
|
}
|
||||||
|
elif isinstance(a, dict) and "fcontent" in a and "fname" in a:
|
||||||
|
# dict returned by frappe.attach_print()
|
||||||
|
file_args = {
|
||||||
|
"file_name": a["fname"],
|
||||||
|
"content": a["fcontent"],
|
||||||
|
"is_private": 1,
|
||||||
|
}
|
||||||
|
else:
|
||||||
|
continue
|
||||||
|
|
||||||
|
file_args.update(
|
||||||
|
{
|
||||||
|
"attached_to_doctype": "Comment",
|
||||||
|
"attached_to_name": name,
|
||||||
|
"folder": "Home/Attachments",
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
_file = frappe.new_doc("File")
|
||||||
|
_file.update(file_args)
|
||||||
|
_file.save(ignore_permissions=True)
|
||||||
@ -474,8 +474,17 @@
|
|||||||
</div>
|
</div>
|
||||||
<div
|
<div
|
||||||
class="cursor-pointer rounded bg-gray-50 px-4 py-3 text-base leading-6 transition-all duration-300 ease-in-out"
|
class="cursor-pointer rounded bg-gray-50 px-4 py-3 text-base leading-6 transition-all duration-300 ease-in-out"
|
||||||
v-html="activity.content"
|
>
|
||||||
/>
|
<div v-html="activity.content" />
|
||||||
|
<div v-if="activity.attachments.length" class="flex flex-wrap gap-2 mt-2">
|
||||||
|
<AttachmentItem
|
||||||
|
v-for="a in activity.attachments"
|
||||||
|
:key="a.file_url"
|
||||||
|
:label="a.file_name"
|
||||||
|
:url="a.file_url"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div
|
<div
|
||||||
v-else-if="
|
v-else-if="
|
||||||
|
|||||||
@ -185,13 +185,19 @@ async function sendMail() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function sendComment() {
|
async function sendComment() {
|
||||||
await call('frappe.desk.form.utils.add_comment', {
|
let comment = await call('frappe.desk.form.utils.add_comment', {
|
||||||
reference_doctype: props.doctype,
|
reference_doctype: props.doctype,
|
||||||
reference_name: doc.value.data.name,
|
reference_name: doc.value.data.name,
|
||||||
content: newComment.value,
|
content: newComment.value,
|
||||||
comment_email: getUser().name,
|
comment_email: getUser().name,
|
||||||
comment_by: getUser()?.full_name || undefined,
|
comment_by: getUser()?.full_name || undefined,
|
||||||
})
|
})
|
||||||
|
if (comment && attachments.value.length) {
|
||||||
|
await call('crm.api.comment.add_attachments', {
|
||||||
|
name: comment.name,
|
||||||
|
attachments: attachments.value.map((x) => x.name),
|
||||||
|
})
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function submitEmail() {
|
async function submitEmail() {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user