fix: create crm user on accepting invite

(cherry picked from commit 03abe0b5cd24e3a9e7bcdfdb17f701b53026db4f)

# Conflicts:
#	crm/api/__init__.py
This commit is contained in:
Shariq Ansari 2025-06-17 17:33:57 +05:30 committed by Mergify
parent f1935156ec
commit eb7ded961a
3 changed files with 26 additions and 6 deletions

View File

@ -70,7 +70,7 @@ def check_app_permission():
roles = frappe.get_roles()
if any(
role in ["System Manager", "Sales User", "Sales Manager", "Sales Master Manager"] for role in roles
role in ["System Manager", "Sales User", "Sales Manager"] for role in roles
):
return True
@ -98,7 +98,15 @@ def accept_invitation(key: str | None = None):
@frappe.whitelist()
def invite_by_email(emails: str, role: str):
<<<<<<< HEAD
frappe.only_for("Sales Manager")
=======
frappe.only_for(["Sales Manager", "System Manager"])
if role not in ["System Manager", "Sales Manager", "Sales User"]:
frappe.throw("Cannot invite for this role")
>>>>>>> 03abe0b5 (fix: create crm user on accepting invite)
if not emails:
return
email_string = validate_email_address(emails, throw=False)
@ -108,7 +116,10 @@ def invite_by_email(emails: str, role: str):
existing_members = frappe.db.get_all("User", filters={"email": ["in", email_list]}, pluck="email")
existing_invites = frappe.db.get_all(
"CRM Invitation",
filters={"email": ["in", email_list], "role": ["in", ["Sales Manager", "Sales User"]]},
filters={
"email": ["in", email_list],
"role": ["in", ["System Manager", "Sales Manager", "Sales User"]],
},
pluck="email",
)

View File

@ -27,7 +27,7 @@
"fieldtype": "Select",
"in_list_view": 1,
"label": "Role",
"options": "\nSales User\nSales Manager",
"options": "\nSales User\nSales Manager\nSystem Manager",
"reqd": 1
},
{
@ -66,7 +66,7 @@
],
"index_web_pages_for_search": 1,
"links": [],
"modified": "2024-09-03 14:59:29.450018",
"modified": "2025-06-17 17:20:18.935395",
"modified_by": "Administrator",
"module": "FCRM",
"name": "CRM Invitation",
@ -106,7 +106,8 @@
"share": 1
}
],
"row_format": "Dynamic",
"sort_field": "creation",
"sort_order": "DESC",
"states": []
}
}

View File

@ -35,7 +35,7 @@ class CRMInvitation(Document):
@frappe.whitelist()
def accept_invitation(self):
frappe.only_for("System Manager")
frappe.only_for(["System Manager", "Sales Manager"])
self.accept()
def accept(self):
@ -52,6 +52,14 @@ class CRMInvitation(Document):
self.accepted_at = frappe.utils.now()
self.save(ignore_permissions=True)
# create CRM User record
if not frappe.db.exists("CRM User", {"user": user.name}):
crm_user = frappe.get_doc(
doctype="CRM User",
user=user.name,
)
crm_user.insert(ignore_permissions=True)
def update_module_in_user(self, user, module):
block_modules = frappe.get_all(
"Module Def",