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