fix: invite contact as user
This commit is contained in:
parent
d0ea79daf2
commit
bbd42839e3
2 changed files with 19 additions and 14 deletions
|
|
@ -21,7 +21,12 @@ frappe.ui.form.on("Contact", {
|
|||
}
|
||||
}
|
||||
|
||||
if (!frm.doc.user && !frm.is_new() && frm.perm[0].write) {
|
||||
if (
|
||||
!frm.doc.user &&
|
||||
!frm.is_new() &&
|
||||
frm.perm[0].write &&
|
||||
frappe.boot.user.can_create.includes("User")
|
||||
) {
|
||||
frm.add_custom_button(__("Invite as User"), function () {
|
||||
return frappe.call({
|
||||
method: "frappe.contacts.doctype.contact.contact.invite_user",
|
||||
|
|
|
|||
|
|
@ -194,25 +194,25 @@ def get_default_contact(doctype, name):
|
|||
|
||||
|
||||
@frappe.whitelist()
|
||||
def invite_user(contact):
|
||||
def invite_user(contact: str):
|
||||
contact = frappe.get_doc("Contact", contact)
|
||||
contact.check_permission()
|
||||
|
||||
if not contact.email_id:
|
||||
frappe.throw(_("Please set Email Address"))
|
||||
|
||||
if contact.has_permission("write"):
|
||||
user = frappe.get_doc(
|
||||
{
|
||||
"doctype": "User",
|
||||
"first_name": contact.first_name,
|
||||
"last_name": contact.last_name,
|
||||
"email": contact.email_id,
|
||||
"user_type": "Website User",
|
||||
"send_welcome_email": 1,
|
||||
}
|
||||
).insert(ignore_permissions=True)
|
||||
user = frappe.get_doc(
|
||||
{
|
||||
"doctype": "User",
|
||||
"first_name": contact.first_name,
|
||||
"last_name": contact.last_name,
|
||||
"email": contact.email_id,
|
||||
"user_type": "Website User",
|
||||
"send_welcome_email": 1,
|
||||
}
|
||||
).insert()
|
||||
|
||||
return user.name
|
||||
return user.name
|
||||
|
||||
|
||||
@frappe.whitelist()
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue