mirror of
https://github.com/frappe/erpnext.git
synced 2026-08-12 22:21:50 +00:00
fix(crm_settings): skip allowed users check when frappe crm is installed locally
(cherry picked from commit 41badb3d74)
This commit is contained in:
@@ -2,6 +2,35 @@
|
|||||||
// For license information, please see license.txt
|
// For license information, please see license.txt
|
||||||
|
|
||||||
frappe.ui.form.on("CRM Settings", {
|
frappe.ui.form.on("CRM Settings", {
|
||||||
// refresh: function(frm) {
|
refresh: function (frm) {
|
||||||
// }
|
const flag = frm.events.calculate_visiblity_flag(frm);
|
||||||
|
|
||||||
|
frm.set_df_property("allowed_users", "hidden", !flag);
|
||||||
|
frm.set_df_property("allowed_users", "reqd", flag);
|
||||||
|
},
|
||||||
|
|
||||||
|
enable_frappe_crm_data_synchronization: function (frm) {
|
||||||
|
const flag = frm.events.calculate_visiblity_flag(frm);
|
||||||
|
|
||||||
|
if (flag) {
|
||||||
|
frappe.show_alert(
|
||||||
|
__("Allowed Users is required for data synchronization from remote Frappe CRM site.")
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
make allowed_users field visible and mandatory if enable_frappe_crm_data_synchronization
|
||||||
|
is set and crm app is not installed.
|
||||||
|
*/
|
||||||
|
|
||||||
|
frm.set_df_property("allowed_users", "hidden", !flag);
|
||||||
|
frm.set_df_property("allowed_users", "reqd", flag);
|
||||||
|
},
|
||||||
|
|
||||||
|
calculate_visiblity_flag: function (frm) {
|
||||||
|
const crm_sync_enabled = frm.doc.enable_frappe_crm_data_synchronization;
|
||||||
|
const is_crm_installed = cint(frappe.utils.get_installed_apps().includes("crm"));
|
||||||
|
|
||||||
|
return crm_sync_enabled && !is_crm_installed;
|
||||||
|
},
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -120,9 +120,9 @@
|
|||||||
"fieldtype": "Column Break"
|
"fieldtype": "Column Break"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"depends_on": "eval:doc.enable_frappe_crm_data_synchronization === 1;",
|
|
||||||
"fieldname": "allowed_users",
|
"fieldname": "allowed_users",
|
||||||
"fieldtype": "Table MultiSelect",
|
"fieldtype": "Table MultiSelect",
|
||||||
|
"hidden": 1,
|
||||||
"label": "Allowed Users",
|
"label": "Allowed Users",
|
||||||
"options": "Frappe CRM Allowed User",
|
"options": "Frappe CRM Allowed User",
|
||||||
"permlevel": 1
|
"permlevel": 1
|
||||||
@@ -140,7 +140,7 @@
|
|||||||
"index_web_pages_for_search": 1,
|
"index_web_pages_for_search": 1,
|
||||||
"issingle": 1,
|
"issingle": 1,
|
||||||
"links": [],
|
"links": [],
|
||||||
"modified": "2026-06-22 01:26:13.474915",
|
"modified": "2026-07-01 01:09:16.461470",
|
||||||
"modified_by": "Administrator",
|
"modified_by": "Administrator",
|
||||||
"module": "CRM",
|
"module": "CRM",
|
||||||
"name": "CRM Settings",
|
"name": "CRM Settings",
|
||||||
|
|||||||
@@ -6,6 +6,8 @@ from frappe import _
|
|||||||
from frappe.custom.doctype.custom_field.custom_field import create_custom_fields
|
from frappe.custom.doctype.custom_field.custom_field import create_custom_fields
|
||||||
from frappe.model.document import Document
|
from frappe.model.document import Document
|
||||||
|
|
||||||
|
from erpnext.crm.frappe_crm_api import is_crm_installed
|
||||||
|
|
||||||
|
|
||||||
class CRMSettings(Document):
|
class CRMSettings(Document):
|
||||||
# begin: auto-generated types
|
# begin: auto-generated types
|
||||||
@@ -46,13 +48,16 @@ class CRMSettings(Document):
|
|||||||
)
|
)
|
||||||
|
|
||||||
def validate_allowed_users(self):
|
def validate_allowed_users(self):
|
||||||
if self.enable_frappe_crm_data_synchronization and not self.allowed_users:
|
if self.enable_frappe_crm_data_synchronization and not (is_crm_installed() or self.allowed_users):
|
||||||
frappe.throw(
|
frappe.throw(
|
||||||
_(
|
_(
|
||||||
"Please add atleast one user on Allowed Users to allow Data Synchronization from Frappe CRM site."
|
"Please add atleast one user on Allowed Users to allow Data Synchronization from Frappe CRM site."
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
if self.enable_frappe_crm_data_synchronization and is_crm_installed() and self.allowed_users:
|
||||||
|
frappe.throw(_("Allowed Users is not required as Frappe CRM is already installed on the site."))
|
||||||
|
|
||||||
def before_save(self):
|
def before_save(self):
|
||||||
self.clear_allowed_users()
|
self.clear_allowed_users()
|
||||||
|
|
||||||
|
|||||||
@@ -150,7 +150,9 @@ def create_customer(customer_data=None):
|
|||||||
for field in CUSTOMER_ALLOWED_FIELDS:
|
for field in CUSTOMER_ALLOWED_FIELDS:
|
||||||
if customer_data.get(field) is not None:
|
if customer_data.get(field) is not None:
|
||||||
customer.set(field, customer_data.get(field))
|
customer.set(field, customer_data.get(field))
|
||||||
customer.insert(ignore_permissions=True)
|
|
||||||
|
# If CRM is installed on the site, User Permission cannot be ignored while saving Customer Records.
|
||||||
|
customer.insert(ignore_permissions=not is_crm_installed())
|
||||||
customer_name = customer.name
|
customer_name = customer.name
|
||||||
|
|
||||||
contacts = json.loads(customer_data.get("contacts"))
|
contacts = json.loads(customer_data.get("contacts"))
|
||||||
@@ -169,6 +171,10 @@ def validate_frappe_crm_sync():
|
|||||||
_("Frappe CRM data synchronization is not enabled on ERPNext. Contact System Manager of ERPNext.")
|
_("Frappe CRM data synchronization is not enabled on ERPNext. Contact System Manager of ERPNext.")
|
||||||
)
|
)
|
||||||
|
|
||||||
|
# Skip allowed_users validation if CRM is installed on the site.
|
||||||
|
if is_crm_installed():
|
||||||
|
return
|
||||||
|
|
||||||
allowed_users = [d.user for d in CRMSettings.allowed_users]
|
allowed_users = [d.user for d in CRMSettings.allowed_users]
|
||||||
|
|
||||||
if frappe.session.user not in allowed_users:
|
if frappe.session.user not in allowed_users:
|
||||||
@@ -178,3 +184,7 @@ def validate_frappe_crm_sync():
|
|||||||
),
|
),
|
||||||
exc=frappe.PermissionError,
|
exc=frappe.PermissionError,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def is_crm_installed():
|
||||||
|
return "crm" in frappe.get_installed_apps()
|
||||||
|
|||||||
Reference in New Issue
Block a user