Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: Telephony Agent #534

Merged
merged 10 commits into from
Jan 19, 2025
34 changes: 20 additions & 14 deletions crm/api/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,16 @@
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)
Expand All @@ -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(
Expand All @@ -37,7 +48,7 @@ def get_contacts():
"mobile_no",
"phone",
"company_name",
"modified"
"modified",
],
order_by="first_name asc",
distinct=True,
Expand All @@ -58,30 +69,25 @@ 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,
)

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)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright (c) 2025, Frappe Technologies Pvt. Ltd. and contributors
// For license information, please see license.txt

// frappe.ui.form.on("CRM Exotel Agent", {
// frappe.ui.form.on("CRM Telephony Agent", {
// refresh(frm) {

// },
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"actions": [],
"allow_rename": 1,
"autoname": "field:mobile_no",
"autoname": "field:user",
"creation": "2025-01-11 16:12:46.602782",
"doctype": "DocType",
"engine": "InnoDB",
Expand All @@ -10,7 +10,15 @@
"user_name",
"column_break_hdec",
"mobile_no",
"exotel_number"
"default_medium",
"section_break_ozjn",
"twilio",
"twilio_number",
"column_break_aydj",
"exotel",
"exotel_number",
"section_break_phlq",
"phone_nos"
],
"fields": [
{
Expand All @@ -20,7 +28,8 @@
"in_standard_filter": 1,
"label": "User",
"options": "User",
"reqd": 1
"reqd": 1,
"unique": 1
},
{
"fieldname": "column_break_hdec",
Expand All @@ -32,8 +41,7 @@
"in_list_view": 1,
"in_standard_filter": 1,
"label": "Mobile No.",
"reqd": 1,
"unique": 1
"read_only": 1
},
{
"fetch_from": "user.full_name",
Expand All @@ -44,19 +52,62 @@
"label": "User Name"
},
{
"depends_on": "exotel",
"fieldname": "exotel_number",
"fieldtype": "Data",
"in_list_view": 1,
"in_standard_filter": 1,
"label": "Exotel Number"
"label": "Exotel Number",
"mandatory_depends_on": "exotel"
},
{
"fieldname": "section_break_phlq",
"fieldtype": "Section Break"
},
{
"fieldname": "section_break_ozjn",
"fieldtype": "Section Break"
},
{
"fieldname": "column_break_aydj",
"fieldtype": "Column Break"
},
{
"depends_on": "twilio",
"fieldname": "twilio_number",
"fieldtype": "Data",
"label": "Twilio Number",
"mandatory_depends_on": "twilio"
},
{
"fieldname": "phone_nos",
"fieldtype": "Table",
"label": "Phone Numbers",
"options": "CRM Telephony Phone"
},
{
"default": "0",
"fieldname": "twilio",
"fieldtype": "Check",
"label": "Twilio"
},
{
"default": "0",
"fieldname": "exotel",
"fieldtype": "Check",
"label": "Exotel"
},
{
"fieldname": "default_medium",
"fieldtype": "Select",
"label": "Default Medium",
"options": "\nTwilio\nExotel"
}
],
"index_web_pages_for_search": 1,
"links": [],
"modified": "2025-01-15 20:03:31.162162",
"modified": "2025-01-19 14:17:12.880185",
"modified_by": "Administrator",
"module": "FCRM",
"name": "CRM Exotel Agent",
"name": "CRM Telephony Agent",
"naming_rule": "By fieldname",
"owner": "Administrator",
"permissions": [
Expand Down
34 changes: 34 additions & 0 deletions crm/fcrm/doctype/crm_telephony_agent/crm_telephony_agent.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# Copyright (c) 2025, Frappe Technologies Pvt. Ltd. and contributors
# For license information, please see license.txt

import frappe
from frappe import _
from frappe.model.document import Document


class CRMTelephonyAgent(Document):
def validate(self):
self.set_primary()

def set_primary(self):
# Used to set primary mobile no.
if len(self.phone_nos) == 0:
self.mobile_no = ""
return

is_primary = [phone.number for phone in self.phone_nos if phone.get("is_primary")]

if len(is_primary) > 1:
frappe.throw(
_("Only one {0} can be set as primary.").format(frappe.bold(frappe.unscrub("mobile_no")))
)

primary_number_exists = False
for d in self.phone_nos:
if d.get("is_primary") == 1:
primary_number_exists = True
self.mobile_no = d.number
break

if not primary_number_exists:
self.mobile_no = ""
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,25 @@
# import frappe
from frappe.tests import IntegrationTestCase, UnitTestCase


# On IntegrationTestCase, the doctype test records and all
# link-field test record dependencies are recursively loaded
# Use these module variables to add/remove to/from that list
EXTRA_TEST_RECORD_DEPENDENCIES = [] # eg. ["User"]
IGNORE_TEST_RECORD_DEPENDENCIES = [] # eg. ["User"]


class UnitTestCRMExotelAgent(UnitTestCase):
class UnitTestCRMTelephonyAgent(UnitTestCase):
"""
Unit tests for CRMExotelAgent.
Unit tests for CRMTelephonyAgent.
Use this class for testing individual functions and methods.
"""

pass


class IntegrationTestCRMExotelAgent(IntegrationTestCase):
class IntegrationTestCRMTelephonyAgent(IntegrationTestCase):
"""
Integration tests for CRMExotelAgent.
Integration tests for CRMTelephonyAgent.
Use this class for testing interactions between multiple components.
"""

Expand Down
40 changes: 40 additions & 0 deletions crm/fcrm/doctype/crm_telephony_phone/crm_telephony_phone.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
{
"actions": [],
"allow_rename": 1,
"creation": "2025-01-19 13:57:01.702519",
"doctype": "DocType",
"editable_grid": 1,
"engine": "InnoDB",
"field_order": [
"number",
"is_primary"
],
"fields": [
{
"fieldname": "number",
"fieldtype": "Data",
"in_list_view": 1,
"label": "Number",
"reqd": 1
},
{
"default": "0",
"fieldname": "is_primary",
"fieldtype": "Check",
"in_list_view": 1,
"label": "Is Primary"
}
],
"index_web_pages_for_search": 1,
"istable": 1,
"links": [],
"modified": "2025-01-19 13:58:59.063775",
"modified_by": "Administrator",
"module": "FCRM",
"name": "CRM Telephony Phone",
"owner": "Administrator",
"permissions": [],
"sort_field": "creation",
"sort_order": "DESC",
"states": []
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@
from frappe.model.document import Document


class CRMExotelAgent(Document):
class CRMTelephonyPhone(Document):
pass
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright (c) 2023, Frappe Technologies Pvt. Ltd. and contributors
// For license information, please see license.txt

// frappe.ui.form.on("Twilio Settings", {
// frappe.ui.form.on("CRM Twilio Settings", {
// refresh(frm) {

// },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@
"modified": "2025-01-15 19:35:13.406254",
"modified_by": "Administrator",
"module": "FCRM",
"name": "Twilio Settings",
"name": "CRM Twilio Settings",
"owner": "Administrator",
"permissions": [
{
Expand Down
Loading
Loading