fix: allow agent to set default medium from settings
This commit is contained in:
parent
5cd2f2bd39
commit
346efbbe78
@ -5,7 +5,16 @@ import frappe
|
|||||||
def get_users():
|
def get_users():
|
||||||
users = frappe.qb.get_query(
|
users = frappe.qb.get_query(
|
||||||
"User",
|
"User",
|
||||||
fields=["name", "email", "enabled", "user_image", "first_name", "last_name", "full_name", "user_type"],
|
fields=[
|
||||||
|
"name",
|
||||||
|
"email",
|
||||||
|
"enabled",
|
||||||
|
"user_image",
|
||||||
|
"first_name",
|
||||||
|
"last_name",
|
||||||
|
"full_name",
|
||||||
|
"user_type",
|
||||||
|
],
|
||||||
order_by="full_name asc",
|
order_by="full_name asc",
|
||||||
distinct=True,
|
distinct=True,
|
||||||
).run(as_dict=1)
|
).run(as_dict=1)
|
||||||
@ -14,11 +23,13 @@ def get_users():
|
|||||||
if frappe.session.user == user.name:
|
if frappe.session.user == user.name:
|
||||||
user.session_user = True
|
user.session_user = True
|
||||||
|
|
||||||
user.is_manager = (
|
user.is_manager = "Sales Manager" in frappe.get_roles(user.name) or user.name == "Administrator"
|
||||||
"Sales Manager" in frappe.get_roles(user.name) or user.name == "Administrator"
|
|
||||||
)
|
user.is_agent = frappe.db.exists("CRM Telephony Agent", {"user": user.name})
|
||||||
|
|
||||||
return users
|
return users
|
||||||
|
|
||||||
|
|
||||||
@frappe.whitelist()
|
@frappe.whitelist()
|
||||||
def get_contacts():
|
def get_contacts():
|
||||||
contacts = frappe.get_all(
|
contacts = frappe.get_all(
|
||||||
@ -37,7 +48,7 @@ def get_contacts():
|
|||||||
"mobile_no",
|
"mobile_no",
|
||||||
"phone",
|
"phone",
|
||||||
"company_name",
|
"company_name",
|
||||||
"modified"
|
"modified",
|
||||||
],
|
],
|
||||||
order_by="first_name asc",
|
order_by="first_name asc",
|
||||||
distinct=True,
|
distinct=True,
|
||||||
@ -58,18 +69,12 @@ def get_contacts():
|
|||||||
|
|
||||||
return contacts
|
return contacts
|
||||||
|
|
||||||
|
|
||||||
@frappe.whitelist()
|
@frappe.whitelist()
|
||||||
def get_lead_contacts():
|
def get_lead_contacts():
|
||||||
lead_contacts = frappe.get_all(
|
lead_contacts = frappe.get_all(
|
||||||
"CRM Lead",
|
"CRM Lead",
|
||||||
fields=[
|
fields=["name", "lead_name", "mobile_no", "phone", "image", "modified"],
|
||||||
"name",
|
|
||||||
"lead_name",
|
|
||||||
"mobile_no",
|
|
||||||
"phone",
|
|
||||||
"image",
|
|
||||||
"modified"
|
|
||||||
],
|
|
||||||
filters={"converted": 0},
|
filters={"converted": 0},
|
||||||
order_by="lead_name asc",
|
order_by="lead_name asc",
|
||||||
distinct=True,
|
distinct=True,
|
||||||
@ -77,11 +82,12 @@ def get_lead_contacts():
|
|||||||
|
|
||||||
return lead_contacts
|
return lead_contacts
|
||||||
|
|
||||||
|
|
||||||
@frappe.whitelist()
|
@frappe.whitelist()
|
||||||
def get_organizations():
|
def get_organizations():
|
||||||
organizations = frappe.qb.get_query(
|
organizations = frappe.qb.get_query(
|
||||||
"CRM Organization",
|
"CRM Organization",
|
||||||
fields=['*'],
|
fields=["*"],
|
||||||
order_by="name asc",
|
order_by="name asc",
|
||||||
distinct=True,
|
distinct=True,
|
||||||
).run(as_dict=1)
|
).run(as_dict=1)
|
||||||
|
|||||||
@ -67,7 +67,7 @@ import {
|
|||||||
import { Dialog, Button, Avatar } from 'frappe-ui'
|
import { Dialog, Button, Avatar } from 'frappe-ui'
|
||||||
import { ref, markRaw, computed, watch, h } from 'vue'
|
import { ref, markRaw, computed, watch, h } from 'vue'
|
||||||
|
|
||||||
const { isManager, getUser } = usersStore()
|
const { isManager, isAgent, getUser } = usersStore()
|
||||||
|
|
||||||
const user = computed(() => getUser() || {})
|
const user = computed(() => getUser() || {})
|
||||||
|
|
||||||
@ -108,20 +108,22 @@ const tabs = computed(() => {
|
|||||||
label: __('Telephony'),
|
label: __('Telephony'),
|
||||||
icon: PhoneIcon,
|
icon: PhoneIcon,
|
||||||
component: markRaw(TelephonySettings),
|
component: markRaw(TelephonySettings),
|
||||||
|
condition: () => isManager() || isAgent(),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
label: __('WhatsApp'),
|
label: __('WhatsApp'),
|
||||||
icon: WhatsAppIcon,
|
icon: WhatsAppIcon,
|
||||||
component: markRaw(WhatsAppSettings),
|
component: markRaw(WhatsAppSettings),
|
||||||
condition: () => isWhatsappInstalled.value,
|
condition: () => isWhatsappInstalled.value && isManager(),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
label: __('ERPNext'),
|
label: __('ERPNext'),
|
||||||
icon: ERPNextIcon,
|
icon: ERPNextIcon,
|
||||||
component: markRaw(ERPNextSettings),
|
component: markRaw(ERPNextSettings),
|
||||||
|
condition: () => isManager(),
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
condition: () => isManager(),
|
condition: () => isManager() || isAgent(),
|
||||||
},
|
},
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|||||||
@ -19,17 +19,18 @@
|
|||||||
<FormControl
|
<FormControl
|
||||||
type="select"
|
type="select"
|
||||||
v-model="defaultCallingMedium"
|
v-model="defaultCallingMedium"
|
||||||
:label="__('Default calling medium')"
|
:label="__('Default medium')"
|
||||||
:options="[
|
:options="[
|
||||||
{ label: __(''), value: '' },
|
{ label: __(''), value: '' },
|
||||||
{ label: __('Twilio'), value: 'Twilio' },
|
{ label: __('Twilio'), value: 'Twilio' },
|
||||||
{ label: __('Exotel'), value: 'Exotel' },
|
{ label: __('Exotel'), value: 'Exotel' },
|
||||||
]"
|
]"
|
||||||
class="w-1/2"
|
class="w-1/2"
|
||||||
|
:description="__('Default calling medium for logged in user')"
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<!-- Twilio -->
|
<!-- Twilio -->
|
||||||
<div class="flex flex-col justify-between gap-4">
|
<div v-if="isManager()" class="flex flex-col justify-between gap-4">
|
||||||
<span class="text-base font-semibold text-ink-gray-9">
|
<span class="text-base font-semibold text-ink-gray-9">
|
||||||
{{ __('Twilio') }}
|
{{ __('Twilio') }}
|
||||||
</span>
|
</span>
|
||||||
@ -42,7 +43,7 @@
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<!-- Exotel -->
|
<!-- Exotel -->
|
||||||
<div class="flex flex-col justify-between gap-4">
|
<div v-if="isManager()" class="flex flex-col justify-between gap-4">
|
||||||
<span class="text-base font-semibold text-ink-gray-9">
|
<span class="text-base font-semibold text-ink-gray-9">
|
||||||
{{ __('Exotel') }}
|
{{ __('Exotel') }}
|
||||||
</span>
|
</span>
|
||||||
@ -85,9 +86,12 @@ import {
|
|||||||
call,
|
call,
|
||||||
} from 'frappe-ui'
|
} from 'frappe-ui'
|
||||||
import { defaultCallingMedium } from '@/composables/settings'
|
import { defaultCallingMedium } from '@/composables/settings'
|
||||||
|
import { usersStore } from '@/stores/users'
|
||||||
import { createToast, getRandom } from '@/utils'
|
import { createToast, getRandom } from '@/utils'
|
||||||
import { ref, computed, watch } from 'vue'
|
import { ref, computed, watch } from 'vue'
|
||||||
|
|
||||||
|
const { isManager, isAgent } = usersStore()
|
||||||
|
|
||||||
const twilioFields = createResource({
|
const twilioFields = createResource({
|
||||||
url: 'crm.api.doc.get_fields',
|
url: 'crm.api.doc.get_fields',
|
||||||
cache: ['fields', 'Twilio Settings'],
|
cache: ['fields', 'Twilio Settings'],
|
||||||
@ -273,6 +277,9 @@ function update() {
|
|||||||
if (mediumChanged.value) {
|
if (mediumChanged.value) {
|
||||||
updateMedium()
|
updateMedium()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!isManager()) return
|
||||||
|
|
||||||
if (twilio.isDirty) {
|
if (twilio.isDirty) {
|
||||||
twilio.save.submit()
|
twilio.save.submit()
|
||||||
}
|
}
|
||||||
@ -298,6 +305,8 @@ async function updateMedium() {
|
|||||||
const error = ref('')
|
const error = ref('')
|
||||||
|
|
||||||
function validateIfDefaultMediumIsEnabled() {
|
function validateIfDefaultMediumIsEnabled() {
|
||||||
|
if (isAgent() && !isManager()) return true
|
||||||
|
|
||||||
if (defaultCallingMedium.value === 'Twilio' && !twilio.doc.enabled) {
|
if (defaultCallingMedium.value === 'Twilio' && !twilio.doc.enabled) {
|
||||||
error.value = __('Twilio is not enabled')
|
error.value = __('Twilio is not enabled')
|
||||||
return false
|
return false
|
||||||
|
|||||||
@ -53,9 +53,14 @@ export const usersStore = defineStore('crm-users', () => {
|
|||||||
return getUser(email).is_manager
|
return getUser(email).is_manager
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function isAgent(email) {
|
||||||
|
return getUser(email).is_agent
|
||||||
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
users,
|
users,
|
||||||
getUser,
|
getUser,
|
||||||
isManager,
|
isManager,
|
||||||
|
isAgent,
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user