Merge pull request #1110 from frappe/mergify/bp/main-hotfix/pr-1104
This commit is contained in:
commit
b0009e1701
@ -662,7 +662,7 @@ def get_fields_meta(doctype, restricted_fieldtypes=None, as_array=False, only_re
|
|||||||
|
|
||||||
@frappe.whitelist()
|
@frappe.whitelist()
|
||||||
def remove_assignments(doctype, name, assignees, ignore_permissions=False):
|
def remove_assignments(doctype, name, assignees, ignore_permissions=False):
|
||||||
assignees = json.loads(assignees)
|
assignees = frappe.parse_json(assignees)
|
||||||
|
|
||||||
if not assignees:
|
if not assignees:
|
||||||
return
|
return
|
||||||
|
|||||||
137
crm/api/todo.py
137
crm/api/todo.py
@ -1,90 +1,79 @@
|
|||||||
import frappe
|
import frappe
|
||||||
from frappe import _
|
from frappe import _
|
||||||
|
|
||||||
from crm.fcrm.doctype.crm_notification.crm_notification import notify_user
|
from crm.fcrm.doctype.crm_notification.crm_notification import notify_user
|
||||||
|
|
||||||
|
|
||||||
def after_insert(doc, method):
|
def after_insert(doc, method):
|
||||||
if (
|
if doc.reference_type in ["CRM Lead", "CRM Deal"] and doc.reference_name and doc.allocated_to:
|
||||||
doc.reference_type in ["CRM Lead", "CRM Deal"]
|
fieldname = "lead_owner" if doc.reference_type == "CRM Lead" else "deal_owner"
|
||||||
and doc.reference_name
|
owner = frappe.db.get_value(doc.reference_type, doc.reference_name, fieldname)
|
||||||
and doc.allocated_to
|
if not owner:
|
||||||
):
|
frappe.db.set_value(
|
||||||
fieldname = "lead_owner" if doc.reference_type == "CRM Lead" else "deal_owner"
|
doc.reference_type, doc.reference_name, fieldname, doc.allocated_to, update_modified=False
|
||||||
lead_owner = frappe.db.get_value(
|
)
|
||||||
doc.reference_type, doc.reference_name, fieldname
|
|
||||||
)
|
|
||||||
if not lead_owner:
|
|
||||||
frappe.db.set_value(
|
|
||||||
doc.reference_type, doc.reference_name, fieldname, doc.allocated_to
|
|
||||||
)
|
|
||||||
|
|
||||||
if (
|
if doc.reference_type in ["CRM Lead", "CRM Deal", "CRM Task"] and doc.reference_name and doc.allocated_to:
|
||||||
doc.reference_type in ["CRM Lead", "CRM Deal", "CRM Task"]
|
notify_assigned_user(doc)
|
||||||
and doc.reference_name
|
|
||||||
and doc.allocated_to
|
|
||||||
):
|
|
||||||
notify_assigned_user(doc)
|
|
||||||
|
|
||||||
|
|
||||||
def on_update(doc, method):
|
def on_update(doc, method):
|
||||||
if (
|
if (
|
||||||
doc.has_value_changed("status")
|
doc.has_value_changed("status")
|
||||||
and doc.status == "Cancelled"
|
and doc.status == "Cancelled"
|
||||||
and doc.reference_type in ["CRM Lead", "CRM Deal", "CRM Task"]
|
and doc.reference_type in ["CRM Lead", "CRM Deal", "CRM Task"]
|
||||||
and doc.reference_name
|
and doc.reference_name
|
||||||
and doc.allocated_to
|
and doc.allocated_to
|
||||||
):
|
):
|
||||||
notify_assigned_user(doc, is_cancelled=True)
|
notify_assigned_user(doc, is_cancelled=True)
|
||||||
|
|
||||||
|
|
||||||
def notify_assigned_user(doc, is_cancelled=False):
|
def notify_assigned_user(doc, is_cancelled=False):
|
||||||
_doc = frappe.get_doc(doc.reference_type, doc.reference_name)
|
_doc = frappe.get_doc(doc.reference_type, doc.reference_name)
|
||||||
owner = frappe.get_cached_value("User", frappe.session.user, "full_name")
|
owner = frappe.get_cached_value("User", frappe.session.user, "full_name")
|
||||||
notification_text = get_notification_text(owner, doc, _doc, is_cancelled)
|
notification_text = get_notification_text(owner, doc, _doc, is_cancelled)
|
||||||
|
|
||||||
message = (
|
message = (
|
||||||
_("Your assignment on {0} {1} has been removed by {2}").format(
|
_("Your assignment on {0} {1} has been removed by {2}").format(
|
||||||
doc.reference_type, doc.reference_name, owner
|
doc.reference_type, doc.reference_name, owner
|
||||||
)
|
)
|
||||||
if is_cancelled
|
if is_cancelled
|
||||||
else _("{0} assigned a {1} {2} to you").format(
|
else _("{0} assigned a {1} {2} to you").format(owner, doc.reference_type, doc.reference_name)
|
||||||
owner, doc.reference_type, doc.reference_name
|
)
|
||||||
)
|
|
||||||
)
|
|
||||||
|
|
||||||
redirect_to_doctype, redirect_to_name = get_redirect_to_doc(doc)
|
redirect_to_doctype, redirect_to_name = get_redirect_to_doc(doc)
|
||||||
|
|
||||||
notify_user(
|
notify_user(
|
||||||
{
|
{
|
||||||
"owner": frappe.session.user,
|
"owner": frappe.session.user,
|
||||||
"assigned_to": doc.allocated_to,
|
"assigned_to": doc.allocated_to,
|
||||||
"notification_type": "Assignment",
|
"notification_type": "Assignment",
|
||||||
"message": message,
|
"message": message,
|
||||||
"notification_text": notification_text,
|
"notification_text": notification_text,
|
||||||
"reference_doctype": doc.reference_type,
|
"reference_doctype": doc.reference_type,
|
||||||
"reference_docname": doc.reference_name,
|
"reference_docname": doc.reference_name,
|
||||||
"redirect_to_doctype": redirect_to_doctype,
|
"redirect_to_doctype": redirect_to_doctype,
|
||||||
"redirect_to_docname": redirect_to_name,
|
"redirect_to_docname": redirect_to_name,
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
def get_notification_text(owner, doc, reference_doc, is_cancelled=False):
|
def get_notification_text(owner, doc, reference_doc, is_cancelled=False):
|
||||||
name = doc.reference_name
|
name = doc.reference_name
|
||||||
doctype = doc.reference_type
|
doctype = doc.reference_type
|
||||||
|
|
||||||
if doctype.startswith("CRM "):
|
if doctype.startswith("CRM "):
|
||||||
doctype = doctype[4:].lower()
|
doctype = doctype[4:].lower()
|
||||||
|
|
||||||
if doctype in ["lead", "deal"]:
|
if doctype in ["lead", "deal"]:
|
||||||
name = (
|
name = (
|
||||||
reference_doc.lead_name or name
|
reference_doc.lead_name or name
|
||||||
if doctype == "lead"
|
if doctype == "lead"
|
||||||
else reference_doc.organization or reference_doc.lead_name or name
|
else reference_doc.organization or reference_doc.lead_name or name
|
||||||
)
|
)
|
||||||
|
|
||||||
if is_cancelled:
|
if is_cancelled:
|
||||||
return f"""
|
return f"""
|
||||||
<div class="mb-2 leading-5 text-ink-gray-5">
|
<div class="mb-2 leading-5 text-ink-gray-5">
|
||||||
<span>{ _('Your assignment on {0} {1} has been removed by {2}').format(
|
<span>{ _('Your assignment on {0} {1} has been removed by {2}').format(
|
||||||
doctype,
|
doctype,
|
||||||
@ -94,7 +83,7 @@ def get_notification_text(owner, doc, reference_doc, is_cancelled=False):
|
|||||||
</div>
|
</div>
|
||||||
"""
|
"""
|
||||||
|
|
||||||
return f"""
|
return f"""
|
||||||
<div class="mb-2 leading-5 text-ink-gray-5">
|
<div class="mb-2 leading-5 text-ink-gray-5">
|
||||||
<span class="font-medium text-ink-gray-9">{ owner }</span>
|
<span class="font-medium text-ink-gray-9">{ owner }</span>
|
||||||
<span>{ _('assigned a {0} {1} to you').format(
|
<span>{ _('assigned a {0} {1} to you').format(
|
||||||
@ -104,9 +93,9 @@ def get_notification_text(owner, doc, reference_doc, is_cancelled=False):
|
|||||||
</div>
|
</div>
|
||||||
"""
|
"""
|
||||||
|
|
||||||
if doctype == "task":
|
if doctype == "task":
|
||||||
if is_cancelled:
|
if is_cancelled:
|
||||||
return f"""
|
return f"""
|
||||||
<div class="mb-2 leading-5 text-ink-gray-5">
|
<div class="mb-2 leading-5 text-ink-gray-5">
|
||||||
<span>{ _('Your assignment on task {0} has been removed by {1}').format(
|
<span>{ _('Your assignment on task {0} has been removed by {1}').format(
|
||||||
f'<span class="font-medium text-ink-gray-9">{ reference_doc.title }</span>',
|
f'<span class="font-medium text-ink-gray-9">{ reference_doc.title }</span>',
|
||||||
@ -114,7 +103,7 @@ def get_notification_text(owner, doc, reference_doc, is_cancelled=False):
|
|||||||
) }</span>
|
) }</span>
|
||||||
</div>
|
</div>
|
||||||
"""
|
"""
|
||||||
return f"""
|
return f"""
|
||||||
<div class="mb-2 leading-5 text-ink-gray-5">
|
<div class="mb-2 leading-5 text-ink-gray-5">
|
||||||
<span class="font-medium text-ink-gray-9">{ owner }</span>
|
<span class="font-medium text-ink-gray-9">{ owner }</span>
|
||||||
<span>{ _('assigned a new task {0} to you').format(
|
<span>{ _('assigned a new task {0} to you').format(
|
||||||
@ -125,8 +114,8 @@ def get_notification_text(owner, doc, reference_doc, is_cancelled=False):
|
|||||||
|
|
||||||
|
|
||||||
def get_redirect_to_doc(doc):
|
def get_redirect_to_doc(doc):
|
||||||
if doc.reference_type == "CRM Task":
|
if doc.reference_type == "CRM Task":
|
||||||
reference_doc = frappe.get_doc(doc.reference_type, doc.reference_name)
|
reference_doc = frappe.get_doc(doc.reference_type, doc.reference_name)
|
||||||
return reference_doc.reference_doctype, reference_doc.reference_docname
|
return reference_doc.reference_doctype, reference_doc.reference_docname
|
||||||
|
|
||||||
return doc.reference_type, doc.reference_name
|
return doc.reference_type, doc.reference_name
|
||||||
|
|||||||
10
frontend/auto-imports.d.ts
vendored
Normal file
10
frontend/auto-imports.d.ts
vendored
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
/* eslint-disable */
|
||||||
|
/* prettier-ignore */
|
||||||
|
// @ts-nocheck
|
||||||
|
// noinspection JSUnusedGlobalSymbols
|
||||||
|
// Generated by unplugin-auto-import
|
||||||
|
// biome-ignore lint: disable
|
||||||
|
export {}
|
||||||
|
declare global {
|
||||||
|
|
||||||
|
}
|
||||||
2
frontend/components.d.ts
vendored
2
frontend/components.d.ts
vendored
@ -25,6 +25,7 @@ declare module 'vue' {
|
|||||||
AscendingIcon: typeof import('./src/components/Icons/AscendingIcon.vue')['default']
|
AscendingIcon: typeof import('./src/components/Icons/AscendingIcon.vue')['default']
|
||||||
AssignmentModal: typeof import('./src/components/Modals/AssignmentModal.vue')['default']
|
AssignmentModal: typeof import('./src/components/Modals/AssignmentModal.vue')['default']
|
||||||
AssignTo: typeof import('./src/components/AssignTo.vue')['default']
|
AssignTo: typeof import('./src/components/AssignTo.vue')['default']
|
||||||
|
AssignToBody: typeof import('./src/components/AssignToBody.vue')['default']
|
||||||
AttachmentArea: typeof import('./src/components/Activities/AttachmentArea.vue')['default']
|
AttachmentArea: typeof import('./src/components/Activities/AttachmentArea.vue')['default']
|
||||||
AttachmentIcon: typeof import('./src/components/Icons/AttachmentIcon.vue')['default']
|
AttachmentIcon: typeof import('./src/components/Icons/AttachmentIcon.vue')['default']
|
||||||
AttachmentItem: typeof import('./src/components/AttachmentItem.vue')['default']
|
AttachmentItem: typeof import('./src/components/AttachmentItem.vue')['default']
|
||||||
@ -172,6 +173,7 @@ declare module 'vue' {
|
|||||||
LucideChevronRight: typeof import('~icons/lucide/chevron-right')['default']
|
LucideChevronRight: typeof import('~icons/lucide/chevron-right')['default']
|
||||||
LucidePenLine: typeof import('~icons/lucide/pen-line')['default']
|
LucidePenLine: typeof import('~icons/lucide/pen-line')['default']
|
||||||
LucideRefreshCcw: typeof import('~icons/lucide/refresh-ccw')['default']
|
LucideRefreshCcw: typeof import('~icons/lucide/refresh-ccw')['default']
|
||||||
|
LucideX: typeof import('~icons/lucide/x')['default']
|
||||||
MarkAsDoneIcon: typeof import('./src/components/Icons/MarkAsDoneIcon.vue')['default']
|
MarkAsDoneIcon: typeof import('./src/components/Icons/MarkAsDoneIcon.vue')['default']
|
||||||
MaximizeIcon: typeof import('./src/components/Icons/MaximizeIcon.vue')['default']
|
MaximizeIcon: typeof import('./src/components/Icons/MaximizeIcon.vue')['default']
|
||||||
MenuIcon: typeof import('./src/components/Icons/MenuIcon.vue')['default']
|
MenuIcon: typeof import('./src/components/Icons/MenuIcon.vue')['default']
|
||||||
|
|||||||
@ -50,11 +50,13 @@
|
|||||||
class="activity grid grid-cols-[30px_minmax(auto,_1fr)] gap-2 px-3 sm:gap-4 sm:px-10"
|
class="activity grid grid-cols-[30px_minmax(auto,_1fr)] gap-2 px-3 sm:gap-4 sm:px-10"
|
||||||
>
|
>
|
||||||
<div
|
<div
|
||||||
class="relative flex justify-center after:absolute after:left-[50%] after:top-0 after:-z-10 after:border-l after:border-outline-gray-modals"
|
class="z-0 relative flex justify-center before:absolute before:left-[50%] before:-z-[1] before:top-0 before:border-l before:border-outline-gray-modals"
|
||||||
:class="i != activities.length - 1 ? 'after:h-full' : 'after:h-4'"
|
:class="
|
||||||
|
i != activities.length - 1 ? 'before:h-full' : 'before:h-4'
|
||||||
|
"
|
||||||
>
|
>
|
||||||
<div
|
<div
|
||||||
class="z-10 flex h-8 w-7 items-center justify-center bg-surface-white"
|
class="flex h-8 w-7 items-center justify-center bg-surface-white"
|
||||||
>
|
>
|
||||||
<CommentIcon class="text-ink-gray-8" />
|
<CommentIcon class="text-ink-gray-8" />
|
||||||
</div>
|
</div>
|
||||||
@ -72,11 +74,13 @@
|
|||||||
class="activity grid grid-cols-[30px_minmax(auto,_1fr)] gap-4 px-3 sm:px-10"
|
class="activity grid grid-cols-[30px_minmax(auto,_1fr)] gap-4 px-3 sm:px-10"
|
||||||
>
|
>
|
||||||
<div
|
<div
|
||||||
class="relative flex justify-center after:absolute after:left-[50%] after:top-0 after:-z-10 after:border-l after:border-outline-gray-modals"
|
class="z-0 relative flex justify-center before:absolute before:left-[50%] before:-z-[1] before:top-0 before:border-l before:border-outline-gray-modals"
|
||||||
:class="i != activities.length - 1 ? 'after:h-full' : 'after:h-4'"
|
:class="
|
||||||
|
i != activities.length - 1 ? 'before:h-full' : 'before:h-4'
|
||||||
|
"
|
||||||
>
|
>
|
||||||
<div
|
<div
|
||||||
class="z-10 flex h-8 w-7 items-center justify-center bg-surface-white text-ink-gray-8"
|
class="flex h-8 w-7 items-center justify-center bg-surface-white text-ink-gray-8"
|
||||||
>
|
>
|
||||||
<MissedCallIcon
|
<MissedCallIcon
|
||||||
v-if="call.status == 'No Answer'"
|
v-if="call.status == 'No Answer'"
|
||||||
@ -116,11 +120,11 @@
|
|||||||
>
|
>
|
||||||
<div
|
<div
|
||||||
v-if="['Activity', 'Emails'].includes(title)"
|
v-if="['Activity', 'Emails'].includes(title)"
|
||||||
class="relative flex justify-center before:absolute before:left-[50%] before:top-0 before:-z-10 before:border-l before:border-outline-gray-modals"
|
class="z-0 relative flex justify-center before:absolute before:left-[50%] before:-z-[1] before:top-0 before:border-l before:border-outline-gray-modals"
|
||||||
:class="[i != activities.length - 1 ? 'before:h-full' : 'before:h-4']"
|
:class="[i != activities.length - 1 ? 'before:h-full' : 'before:h-4']"
|
||||||
>
|
>
|
||||||
<div
|
<div
|
||||||
class="z-10 flex h-7 w-7 items-center justify-center bg-surface-white"
|
class="flex h-7 w-7 items-center justify-center bg-surface-white"
|
||||||
:class="{
|
:class="{
|
||||||
'mt-2.5': ['communication'].includes(activity.activity_type),
|
'mt-2.5': ['communication'].includes(activity.activity_type),
|
||||||
'bg-surface-white': ['added', 'removed', 'changed'].includes(
|
'bg-surface-white': ['added', 'removed', 'changed'].includes(
|
||||||
@ -555,6 +559,7 @@ const all_activities = createResource({
|
|||||||
transform: ([versions, calls, notes, tasks, attachments]) => {
|
transform: ([versions, calls, notes, tasks, attachments]) => {
|
||||||
return { versions, calls, notes, tasks, attachments }
|
return { versions, calls, notes, tasks, attachments }
|
||||||
},
|
},
|
||||||
|
onSuccess: () => nextTick(() => scroll()),
|
||||||
})
|
})
|
||||||
|
|
||||||
const showWhatsappTemplates = ref(false)
|
const showWhatsappTemplates = ref(false)
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
<template>
|
<template>
|
||||||
<div @click="showCallLogDetailModal = true" class="cursor-pointer">
|
<div>
|
||||||
<div class="mb-1 flex items-center justify-stretch gap-2 py-1 text-base">
|
<div class="mb-1 flex items-center justify-stretch gap-2 py-1 text-base">
|
||||||
<div class="inline-flex items-center flex-wrap gap-1 text-ink-gray-5">
|
<div class="inline-flex items-center flex-wrap gap-1 text-ink-gray-5">
|
||||||
<Avatar
|
<Avatar
|
||||||
@ -25,7 +25,8 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div
|
<div
|
||||||
class="flex flex-col gap-2 border border-outline-gray-modals rounded-md bg-surface-cards px-3 py-2.5 text-ink-gray-9"
|
@click="showCallLogDetailModal = true"
|
||||||
|
class="flex flex-col gap-2 border cursor-pointer border-outline-gray-modals rounded-md bg-surface-cards px-3 py-2.5 text-ink-gray-9"
|
||||||
>
|
>
|
||||||
<div class="flex items-center justify-between">
|
<div class="flex items-center justify-between">
|
||||||
<div class="inline-flex gap-2 items-center text-base font-medium">
|
<div class="inline-flex gap-2 items-center text-base font-medium">
|
||||||
|
|||||||
@ -1,31 +1,100 @@
|
|||||||
<template>
|
<template>
|
||||||
<component
|
<NestedPopover>
|
||||||
v-if="assignees?.length"
|
<template #target>
|
||||||
:is="assignees?.length == 1 ? 'Button' : 'div'"
|
<div class="flex items-center">
|
||||||
>
|
<component
|
||||||
<MultipleAvatar :avatars="assignees" @click="showAssignmentModal = true" />
|
v-if="assignees?.length"
|
||||||
</component>
|
:is="assignees?.length == 1 ? 'Button' : 'div'"
|
||||||
<Button v-else @click="showAssignmentModal = true">
|
>
|
||||||
{{ __('Assign to') }}
|
<MultipleAvatar :avatars="assignees" />
|
||||||
</Button>
|
</component>
|
||||||
<AssignmentModal
|
<Button v-else :label="__('Assign to')" />
|
||||||
v-if="showAssignmentModal"
|
</div>
|
||||||
v-model="showAssignmentModal"
|
</template>
|
||||||
v-model:assignees="assignees"
|
<template #body="{ open }">
|
||||||
:doctype="doctype"
|
<AssignToBody
|
||||||
:doc="data"
|
v-show="open"
|
||||||
/>
|
v-model="assignees"
|
||||||
|
:docname="docname"
|
||||||
|
:doctype="doctype"
|
||||||
|
:open="open"
|
||||||
|
:onUpdate="ownerField && saveAssignees"
|
||||||
|
/>
|
||||||
|
</template>
|
||||||
|
</NestedPopover>
|
||||||
</template>
|
</template>
|
||||||
<script setup>
|
<script setup>
|
||||||
|
import NestedPopover from '@/components/NestedPopover.vue'
|
||||||
import MultipleAvatar from '@/components/MultipleAvatar.vue'
|
import MultipleAvatar from '@/components/MultipleAvatar.vue'
|
||||||
import AssignmentModal from '@/components/Modals/AssignmentModal.vue'
|
import AssignToBody from '@/components/AssignToBody.vue'
|
||||||
import { ref } from 'vue'
|
import { useDocument } from '@/data/document'
|
||||||
|
import { toast } from 'frappe-ui'
|
||||||
|
import { computed } from 'vue'
|
||||||
|
|
||||||
const props = defineProps({
|
const props = defineProps({
|
||||||
data: Object,
|
|
||||||
doctype: String,
|
doctype: String,
|
||||||
|
docname: String,
|
||||||
})
|
})
|
||||||
|
|
||||||
const showAssignmentModal = ref(false)
|
const { document } = useDocument(props.doctype, props.docname)
|
||||||
|
|
||||||
const assignees = defineModel()
|
const assignees = defineModel()
|
||||||
|
|
||||||
|
const ownerField = computed(() => {
|
||||||
|
if (props.doctype === 'CRM Lead') {
|
||||||
|
return 'lead_owner'
|
||||||
|
} else if (props.doctype === 'CRM Deal') {
|
||||||
|
return 'deal_owner'
|
||||||
|
} else {
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
async function saveAssignees(
|
||||||
|
addedAssignees,
|
||||||
|
removedAssignees,
|
||||||
|
addAssignees,
|
||||||
|
removeAssignees,
|
||||||
|
) {
|
||||||
|
removedAssignees.length && (await removeAssignees.submit(removedAssignees))
|
||||||
|
addedAssignees.length && (await addAssignees.submit(addedAssignees))
|
||||||
|
|
||||||
|
const nextAssignee = assignees.value.find(
|
||||||
|
(a) => a.name !== document.doc[ownerField.value],
|
||||||
|
)
|
||||||
|
|
||||||
|
let owner = ownerField.value.replace('_', ' ')
|
||||||
|
|
||||||
|
if (
|
||||||
|
document.doc[ownerField.value] &&
|
||||||
|
removedAssignees.includes(document.doc[ownerField.value])
|
||||||
|
) {
|
||||||
|
document.doc[ownerField.value] = nextAssignee ? nextAssignee.name : ''
|
||||||
|
document.save.submit()
|
||||||
|
|
||||||
|
if (nextAssignee) {
|
||||||
|
toast.info(
|
||||||
|
__(
|
||||||
|
'Since you removed {0} from the assignee, the {0} has been changed to the next available assignee {1}.',
|
||||||
|
[owner, nextAssignee.label || nextAssignee.name],
|
||||||
|
),
|
||||||
|
)
|
||||||
|
} else {
|
||||||
|
toast.info(
|
||||||
|
__(
|
||||||
|
'Since you removed {0} from the assignee, the {0} has also been removed.',
|
||||||
|
[owner],
|
||||||
|
),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
} else if (!document.doc[ownerField.value] && nextAssignee) {
|
||||||
|
document.doc[ownerField.value] = nextAssignee ? nextAssignee.name : ''
|
||||||
|
toast.info(
|
||||||
|
__('Since you added a new assignee, the {0} has been set to {1}.', [
|
||||||
|
owner,
|
||||||
|
nextAssignee.label || nextAssignee.name,
|
||||||
|
]),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|||||||
212
frontend/src/components/AssignToBody.vue
Normal file
212
frontend/src/components/AssignToBody.vue
Normal file
@ -0,0 +1,212 @@
|
|||||||
|
<template>
|
||||||
|
<div
|
||||||
|
class="flex flex-col gap-2 my-2 w-[470px] rounded-lg bg-surface-modal shadow-2xl ring-1 ring-black p-3 ring-opacity-5 focus:outline-none"
|
||||||
|
>
|
||||||
|
<div class="text-base text-ink-gray-5">{{ __('Assign to') }}</div>
|
||||||
|
<Link
|
||||||
|
class="form-control"
|
||||||
|
value=""
|
||||||
|
doctype="User"
|
||||||
|
@change="(option) => addValue(option) && ($refs.input.value = '')"
|
||||||
|
:placeholder="__('John Doe')"
|
||||||
|
:filters="{
|
||||||
|
name: ['in', users.data.crmUsers?.map((user) => user.name)],
|
||||||
|
}"
|
||||||
|
:hideMe="true"
|
||||||
|
>
|
||||||
|
<template #target="{ togglePopover }">
|
||||||
|
<div
|
||||||
|
class="w-full min-h-12 flex flex-wrap items-center gap-1.5 p-1.5 pb-5 rounded-lg bg-surface-gray-2 cursor-text"
|
||||||
|
@click.stop="togglePopover"
|
||||||
|
>
|
||||||
|
<Tooltip
|
||||||
|
:text="assignee.name"
|
||||||
|
v-for="assignee in assignees"
|
||||||
|
:key="assignee.name"
|
||||||
|
@click.stop
|
||||||
|
>
|
||||||
|
<div>
|
||||||
|
<div
|
||||||
|
class="flex items-center text-sm p-0.5 text-ink-gray-6 border border-outline-gray-1 bg-surface-modal rounded-full cursor-pointer"
|
||||||
|
@click.stop
|
||||||
|
>
|
||||||
|
<UserAvatar :user="assignee.name" size="sm" />
|
||||||
|
<div class="ml-1">{{ getUser(assignee.name).full_name }}</div>
|
||||||
|
<Button
|
||||||
|
variant="ghost"
|
||||||
|
class="rounded-full !size-4 m-1"
|
||||||
|
@click.stop="removeValue(assignee.name)"
|
||||||
|
>
|
||||||
|
<template #icon>
|
||||||
|
<FeatherIcon name="x" class="h-3 w-3 text-ink-gray-6" />
|
||||||
|
</template>
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</Tooltip>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
<template #item-prefix="{ option }">
|
||||||
|
<UserAvatar class="mr-2" :user="option.value" size="sm" />
|
||||||
|
</template>
|
||||||
|
<template #item-label="{ option }">
|
||||||
|
<Tooltip :text="option.value">
|
||||||
|
<div class="cursor-pointer text-ink-gray-9">
|
||||||
|
{{ getUser(option.value).full_name }}
|
||||||
|
</div>
|
||||||
|
</Tooltip>
|
||||||
|
</template>
|
||||||
|
</Link>
|
||||||
|
<div class="flex items-center justify-between gap-2">
|
||||||
|
<div
|
||||||
|
class="text-base text-ink-gray-5 cursor-pointer select-none"
|
||||||
|
@click="assignToMe = !assignToMe"
|
||||||
|
>
|
||||||
|
{{ __('Assign to me') }}
|
||||||
|
</div>
|
||||||
|
<Switch v-model="assignToMe" @click.stop />
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script setup>
|
||||||
|
import UserAvatar from '@/components/UserAvatar.vue'
|
||||||
|
import Link from '@/components/Controls/Link.vue'
|
||||||
|
import { usersStore } from '@/stores/users'
|
||||||
|
import { capture } from '@/telemetry'
|
||||||
|
import { Tooltip, Switch, toast, createResource } from 'frappe-ui'
|
||||||
|
import { ref, watch } from 'vue'
|
||||||
|
|
||||||
|
const props = defineProps({
|
||||||
|
doctype: {
|
||||||
|
type: String,
|
||||||
|
default: '',
|
||||||
|
},
|
||||||
|
docname: {
|
||||||
|
type: Object,
|
||||||
|
default: null,
|
||||||
|
},
|
||||||
|
open: {
|
||||||
|
type: Boolean,
|
||||||
|
default: false,
|
||||||
|
},
|
||||||
|
onUpdate: {
|
||||||
|
type: Function,
|
||||||
|
default: null,
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
const emit = defineEmits(['reload'])
|
||||||
|
|
||||||
|
const assignees = defineModel()
|
||||||
|
const oldAssignees = ref([])
|
||||||
|
const assignToMe = ref(false)
|
||||||
|
|
||||||
|
const error = ref('')
|
||||||
|
|
||||||
|
const { users, getUser } = usersStore()
|
||||||
|
|
||||||
|
const removeValue = (value) => {
|
||||||
|
if (value === getUser('').name) {
|
||||||
|
assignToMe.value = false
|
||||||
|
}
|
||||||
|
|
||||||
|
assignees.value = assignees.value.filter(
|
||||||
|
(assignee) => assignee.name !== value,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
const addValue = (value) => {
|
||||||
|
if (value === getUser('').name) {
|
||||||
|
assignToMe.value = true
|
||||||
|
}
|
||||||
|
|
||||||
|
error.value = ''
|
||||||
|
let obj = {
|
||||||
|
name: value,
|
||||||
|
image: getUser(value).user_image,
|
||||||
|
label: getUser(value).full_name,
|
||||||
|
}
|
||||||
|
if (!assignees.value.find((assignee) => assignee.name === value)) {
|
||||||
|
assignees.value.push(obj)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
watch(assignToMe, (val) => {
|
||||||
|
let user = getUser('')
|
||||||
|
if (val) {
|
||||||
|
addValue(user.name)
|
||||||
|
} else {
|
||||||
|
removeValue(user.name)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
watch(
|
||||||
|
() => props.open,
|
||||||
|
(val) => {
|
||||||
|
if (val) {
|
||||||
|
oldAssignees.value = [...(assignees.value || [])]
|
||||||
|
|
||||||
|
assignToMe.value = assignees.value.some(
|
||||||
|
(assignee) => assignee.name === getUser('').name,
|
||||||
|
)
|
||||||
|
} else {
|
||||||
|
updateAssignees()
|
||||||
|
}
|
||||||
|
},
|
||||||
|
)
|
||||||
|
|
||||||
|
async function updateAssignees() {
|
||||||
|
if (JSON.stringify(oldAssignees.value) === JSON.stringify(assignees.value))
|
||||||
|
return
|
||||||
|
|
||||||
|
const removedAssignees = oldAssignees.value
|
||||||
|
.filter(
|
||||||
|
(assignee) => !assignees.value.find((a) => a.name === assignee.name),
|
||||||
|
)
|
||||||
|
.map((assignee) => assignee.name)
|
||||||
|
|
||||||
|
const addedAssignees = assignees.value
|
||||||
|
.filter(
|
||||||
|
(assignee) => !oldAssignees.value.find((a) => a.name === assignee.name),
|
||||||
|
)
|
||||||
|
.map((assignee) => assignee.name)
|
||||||
|
|
||||||
|
if (props.onUpdate) {
|
||||||
|
props.onUpdate(
|
||||||
|
addedAssignees,
|
||||||
|
removedAssignees,
|
||||||
|
addAssignees,
|
||||||
|
removeAssignees,
|
||||||
|
)
|
||||||
|
} else {
|
||||||
|
if (removedAssignees.length) {
|
||||||
|
await removeAssignees.submit(removedAssignees)
|
||||||
|
}
|
||||||
|
if (addedAssignees.length) {
|
||||||
|
addAssignees.submit(addedAssignees)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const addAssignees = createResource({
|
||||||
|
url: 'frappe.desk.form.assign_to.add',
|
||||||
|
makeParams: (addedAssignees) => ({
|
||||||
|
doctype: props.doctype,
|
||||||
|
name: props.docname,
|
||||||
|
assign_to: addedAssignees,
|
||||||
|
}),
|
||||||
|
onSuccess: () => {
|
||||||
|
capture('assign_to', { doctype: props.doctype })
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
const removeAssignees = createResource({
|
||||||
|
url: 'crm.api.doc.remove_assignments',
|
||||||
|
makeParams: (removedAssignees) => ({
|
||||||
|
doctype: props.doctype,
|
||||||
|
name: props.docname,
|
||||||
|
assignees: removedAssignees,
|
||||||
|
}),
|
||||||
|
})
|
||||||
|
</script>
|
||||||
@ -1,30 +1,8 @@
|
|||||||
<template>
|
<template>
|
||||||
<Dialog
|
<Dialog
|
||||||
v-model="show"
|
v-model="show"
|
||||||
:options="{
|
:options="{ title: __('Assign To'), size: 'xl' }"
|
||||||
title: __('Assign To'),
|
@close="() => (assignees = [...oldAssignees])"
|
||||||
size: 'xl',
|
|
||||||
actions: [
|
|
||||||
{
|
|
||||||
label: __('Cancel'),
|
|
||||||
variant: 'subtle',
|
|
||||||
onClick: () => {
|
|
||||||
assignees = [...oldAssignees]
|
|
||||||
show = false
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
label: __('Update'),
|
|
||||||
variant: 'solid',
|
|
||||||
onClick: () => updateAssignees(),
|
|
||||||
},
|
|
||||||
],
|
|
||||||
}"
|
|
||||||
@close="
|
|
||||||
() => {
|
|
||||||
assignees = [...oldAssignees]
|
|
||||||
}
|
|
||||||
"
|
|
||||||
>
|
>
|
||||||
<template #body-content>
|
<template #body-content>
|
||||||
<Link
|
<Link
|
||||||
@ -33,9 +11,43 @@
|
|||||||
doctype="User"
|
doctype="User"
|
||||||
@change="(option) => addValue(option) && ($refs.input.value = '')"
|
@change="(option) => addValue(option) && ($refs.input.value = '')"
|
||||||
:placeholder="__('John Doe')"
|
:placeholder="__('John Doe')"
|
||||||
:filters="{ name: ['in', users.data.crmUsers?.map((user) => user.name)] }"
|
:filters="{
|
||||||
|
name: ['in', users.data.crmUsers?.map((user) => user.name)],
|
||||||
|
}"
|
||||||
:hideMe="true"
|
:hideMe="true"
|
||||||
>
|
>
|
||||||
|
<template #target="{ togglePopover }">
|
||||||
|
<div
|
||||||
|
class="w-full min-h-12 flex flex-wrap items-center gap-1.5 p-1.5 pb-5 rounded-lg bg-surface-gray-2 cursor-text"
|
||||||
|
@click.stop="togglePopover"
|
||||||
|
>
|
||||||
|
<Tooltip
|
||||||
|
:text="assignee.name"
|
||||||
|
v-for="assignee in assignees"
|
||||||
|
:key="assignee.name"
|
||||||
|
@click.stop
|
||||||
|
>
|
||||||
|
<div>
|
||||||
|
<div
|
||||||
|
class="flex items-center text-sm text-ink-gray-6 border border-outline-gray-1 bg-surface-white rounded-full hover:bg-surface-white !p-0.5"
|
||||||
|
@click.stop
|
||||||
|
>
|
||||||
|
<UserAvatar :user="assignee.name" size="sm" />
|
||||||
|
<div class="ml-1">{{ getUser(assignee.name).full_name }}</div>
|
||||||
|
<Button
|
||||||
|
variant="ghost"
|
||||||
|
class="rounded-full !size-4 m-1"
|
||||||
|
@click.stop="removeValue(assignee.name)"
|
||||||
|
>
|
||||||
|
<template #icon>
|
||||||
|
<FeatherIcon name="x" class="h-3 w-3 text-ink-gray-6" />
|
||||||
|
</template>
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</Tooltip>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
<template #item-prefix="{ option }">
|
<template #item-prefix="{ option }">
|
||||||
<UserAvatar class="mr-2" :user="option.value" size="sm" />
|
<UserAvatar class="mr-2" :user="option.value" size="sm" />
|
||||||
</template>
|
</template>
|
||||||
@ -47,30 +59,28 @@
|
|||||||
</Tooltip>
|
</Tooltip>
|
||||||
</template>
|
</template>
|
||||||
</Link>
|
</Link>
|
||||||
<div class="mt-3 flex flex-wrap items-center gap-2">
|
</template>
|
||||||
<Tooltip
|
<template #actions>
|
||||||
:text="assignee.name"
|
<div class="flex justify-between items-center gap-2">
|
||||||
v-for="assignee in assignees"
|
<div><ErrorMessage :message="__(error)" /></div>
|
||||||
:key="assignee.name"
|
<div class="flex items-center justify-end gap-2">
|
||||||
>
|
<Button
|
||||||
<div>
|
variant="subtle"
|
||||||
<Button :label="getUser(assignee.name).full_name" theme="gray">
|
:label="__('Cancel')"
|
||||||
<template #prefix>
|
@click="
|
||||||
<UserAvatar :user="assignee.name" size="sm" />
|
() => {
|
||||||
</template>
|
assignees = [...oldAssignees]
|
||||||
<template #suffix>
|
show = false
|
||||||
<FeatherIcon
|
}
|
||||||
v-if="assignee.name !== owner"
|
"
|
||||||
class="h-3.5"
|
/>
|
||||||
name="x"
|
<Button
|
||||||
@click.stop="removeValue(assignee.name)"
|
variant="solid"
|
||||||
/>
|
:label="__('Update')"
|
||||||
</template>
|
@click="updateAssignees()"
|
||||||
</Button>
|
/>
|
||||||
</div>
|
</div>
|
||||||
</Tooltip>
|
|
||||||
</div>
|
</div>
|
||||||
<ErrorMessage class="mt-2" v-if="error" :message="__(error)" />
|
|
||||||
</template>
|
</template>
|
||||||
</Dialog>
|
</Dialog>
|
||||||
</template>
|
</template>
|
||||||
@ -132,7 +142,7 @@ const addValue = (value) => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function updateAssignees() {
|
async function updateAssignees() {
|
||||||
const removedAssignees = oldAssignees.value
|
const removedAssignees = oldAssignees.value
|
||||||
.filter(
|
.filter(
|
||||||
(assignee) => !assignees.value.find((a) => a.name === assignee.name),
|
(assignee) => !assignees.value.find((a) => a.name === assignee.name),
|
||||||
@ -146,7 +156,7 @@ function updateAssignees() {
|
|||||||
.map((assignee) => assignee.name)
|
.map((assignee) => assignee.name)
|
||||||
|
|
||||||
if (removedAssignees.length) {
|
if (removedAssignees.length) {
|
||||||
call('crm.api.doc.remove_assignments', {
|
await call('crm.api.doc.remove_assignments', {
|
||||||
doctype: props.doctype,
|
doctype: props.doctype,
|
||||||
name: props.doc.name,
|
name: props.doc.name,
|
||||||
assignees: JSON.stringify(removedAssignees),
|
assignees: JSON.stringify(removedAssignees),
|
||||||
|
|||||||
@ -16,7 +16,7 @@
|
|||||||
v-if="document.actions?.length"
|
v-if="document.actions?.length"
|
||||||
:actions="document.actions"
|
:actions="document.actions"
|
||||||
/>
|
/>
|
||||||
<AssignTo v-model="assignees.data" :data="doc" doctype="CRM Deal" />
|
<AssignTo v-model="assignees.data" doctype="CRM Deal" :docname="dealId" />
|
||||||
<Dropdown
|
<Dropdown
|
||||||
v-if="doc"
|
v-if="doc"
|
||||||
:options="
|
:options="
|
||||||
|
|||||||
@ -16,7 +16,7 @@
|
|||||||
v-if="document.actions?.length"
|
v-if="document.actions?.length"
|
||||||
:actions="document.actions"
|
:actions="document.actions"
|
||||||
/>
|
/>
|
||||||
<AssignTo v-model="assignees.data" :data="doc" doctype="CRM Lead" />
|
<AssignTo v-model="assignees.data" doctype="CRM Lead" :docname="leadId" />
|
||||||
<Dropdown
|
<Dropdown
|
||||||
v-if="doc"
|
v-if="doc"
|
||||||
:options="
|
:options="
|
||||||
|
|||||||
@ -42,7 +42,7 @@
|
|||||||
v-if="doc.name"
|
v-if="doc.name"
|
||||||
class="flex h-12 items-center justify-between gap-2 border-b px-3 py-2.5"
|
class="flex h-12 items-center justify-between gap-2 border-b px-3 py-2.5"
|
||||||
>
|
>
|
||||||
<AssignTo v-model="assignees.data" :data="doc" doctype="CRM Deal" />
|
<AssignTo v-model="assignees.data" doctype="CRM Deal" :docname="dealId" />
|
||||||
<div class="flex items-center gap-2">
|
<div class="flex items-center gap-2">
|
||||||
<CustomActions
|
<CustomActions
|
||||||
v-if="document._actions?.length"
|
v-if="document._actions?.length"
|
||||||
|
|||||||
@ -42,7 +42,7 @@
|
|||||||
v-if="doc.name"
|
v-if="doc.name"
|
||||||
class="flex h-12 items-center justify-between gap-2 border-b px-3 py-2.5"
|
class="flex h-12 items-center justify-between gap-2 border-b px-3 py-2.5"
|
||||||
>
|
>
|
||||||
<AssignTo v-model="assignees.data" :data="doc" doctype="CRM Lead" />
|
<AssignTo v-model="assignees.data" doctype="CRM Lead" :docname="leadId" />
|
||||||
<div class="flex items-center gap-2">
|
<div class="flex items-center gap-2">
|
||||||
<CustomActions
|
<CustomActions
|
||||||
v-if="document._actions?.length"
|
v-if="document._actions?.length"
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user