[minor] Added 'Invite User' in Contact
diff --git a/erpnext/patches.txt b/erpnext/patches.txt
index 287d962..65c646a 100644
--- a/erpnext/patches.txt
+++ b/erpnext/patches.txt
@@ -218,9 +218,13 @@
erpnext.patches.v6_4.fix_modified_in_sales_order_and_purchase_order
erpnext.patches.v6_4.fix_duplicate_bins
erpnext.patches.v6_4.fix_sales_order_maintenance_status
+<<<<<<< HEAD
erpnext.patches.v6_4.email_digest_update
# delete shopping cart doctypes
execute:frappe.delete_doc_if_exists("DocType", "Applicable Territory")
execute:frappe.delete_doc_if_exists("DocType", "Shopping Cart Price List")
execute:frappe.delete_doc_if_exists("DocType", "Shopping Cart Taxes and Charges Master")
+=======
+erpnext.patches.v6_4.set_user_in_contact
+>>>>>>> [minor] Added 'Invite User' in Contact
diff --git a/erpnext/patches/v6_4/set_user_in_contact.py b/erpnext/patches/v6_4/set_user_in_contact.py
new file mode 100644
index 0000000..509114b
--- /dev/null
+++ b/erpnext/patches/v6_4/set_user_in_contact.py
@@ -0,0 +1,5 @@
+import frappe
+
+def execute():
+ frappe.db.sql("""update tabContact, tabUser set tabContact.user = tabUser.name
+ where tabContact.email_id = tabUser.email""")
diff --git a/erpnext/utilities/doctype/contact/contact.js b/erpnext/utilities/doctype/contact/contact.js
index e8aae14..7b64b76 100644
--- a/erpnext/utilities/doctype/contact/contact.js
+++ b/erpnext/utilities/doctype/contact/contact.js
@@ -4,11 +4,28 @@
{% include 'controllers/js/contact_address_common.js' %};
cur_frm.email_field = "email_id";
-frappe.ui.form.on("Contact", "validate", function(frm) {
- // clear linked customer / supplier / sales partner on saving...
- $.each(["Customer", "Supplier", "Sales Partner"], function(i, doctype) {
- var name = frm.doc[doctype.toLowerCase().replace(/ /g, "_")];
- if(name && locals[doctype] && locals[doctype][name])
- frappe.model.remove_from_locals(doctype, name);
- });
+frappe.ui.form.on("Contact", {
+ refresh: function(frm) {
+ if(!frm.doc.user && !frm.is_new() && frm.perm[0].write) {
+ frm.add_custom_button(__("Invite as User"), function() {
+ frappe.call({
+ method: "erpnext.utilities.doctype.contact.contact.invite_user",
+ args: {
+ contact: frm.doc.name
+ },
+ callback: function(r) {
+ frm.set_value("user", r.message);
+ }
+ });
+ });
+ }
+ },
+ validate: function(frm) {
+ // clear linked customer / supplier / sales partner on saving...
+ $.each(["Customer", "Supplier", "Sales Partner"], function(i, doctype) {
+ var name = frm.doc[doctype.toLowerCase().replace(/ /g, "_")];
+ if(name && locals[doctype] && locals[doctype][name])
+ frappe.model.remove_from_locals(doctype, name);
+ });
+ }
});
diff --git a/erpnext/utilities/doctype/contact/contact.json b/erpnext/utilities/doctype/contact/contact.json
index dac13c2..d50313f 100644
--- a/erpnext/utilities/doctype/contact/contact.json
+++ b/erpnext/utilities/doctype/contact/contact.json
@@ -80,22 +80,23 @@
"allow_on_submit": 0,
"bold": 0,
"collapsible": 0,
- "fieldname": "user",
- "fieldtype": "Link",
+ "fieldname": "email_id",
+ "fieldtype": "Data",
"hidden": 0,
"ignore_user_permissions": 0,
"in_filter": 0,
"in_list_view": 0,
- "label": "User Id",
+ "label": "Email Id",
"no_copy": 0,
- "options": "User",
+ "oldfieldname": "email_id",
+ "oldfieldtype": "Data",
+ "options": "Email",
"permlevel": 0,
- "precision": "",
"print_hide": 0,
"read_only": 0,
"report_hide": 0,
"reqd": 0,
- "search_index": 0,
+ "search_index": 1,
"set_only_once": 0,
"unique": 0
},
@@ -147,30 +148,6 @@
"allow_on_submit": 0,
"bold": 0,
"collapsible": 0,
- "fieldname": "email_id",
- "fieldtype": "Data",
- "hidden": 0,
- "ignore_user_permissions": 0,
- "in_filter": 0,
- "in_list_view": 0,
- "label": "Email Id",
- "no_copy": 0,
- "oldfieldname": "email_id",
- "oldfieldtype": "Data",
- "options": "Email",
- "permlevel": 0,
- "print_hide": 0,
- "read_only": 0,
- "report_hide": 0,
- "reqd": 0,
- "search_index": 1,
- "set_only_once": 0,
- "unique": 0
- },
- {
- "allow_on_submit": 0,
- "bold": 0,
- "collapsible": 0,
"fieldname": "phone",
"fieldtype": "Data",
"hidden": 0,
@@ -216,6 +193,29 @@
"allow_on_submit": 0,
"bold": 0,
"collapsible": 0,
+ "fieldname": "user",
+ "fieldtype": "Link",
+ "hidden": 0,
+ "ignore_user_permissions": 0,
+ "in_filter": 0,
+ "in_list_view": 0,
+ "label": "User Id",
+ "no_copy": 0,
+ "options": "User",
+ "permlevel": 0,
+ "precision": "",
+ "print_hide": 0,
+ "read_only": 0,
+ "report_hide": 0,
+ "reqd": 0,
+ "search_index": 0,
+ "set_only_once": 0,
+ "unique": 0
+ },
+ {
+ "allow_on_submit": 0,
+ "bold": 0,
+ "collapsible": 0,
"depends_on": "",
"fieldname": "customer",
"fieldtype": "Link",
@@ -494,7 +494,7 @@
"is_submittable": 0,
"issingle": 0,
"istable": 0,
- "modified": "2015-10-07 00:26:20.667566",
+ "modified": "2015-10-07 00:38:08.152183",
"modified_by": "Administrator",
"module": "Utilities",
"name": "Contact",
diff --git a/erpnext/utilities/doctype/contact/contact.py b/erpnext/utilities/doctype/contact/contact.py
index 314014f..bfab79f 100644
--- a/erpnext/utilities/doctype/contact/contact.py
+++ b/erpnext/utilities/doctype/contact/contact.py
@@ -3,7 +3,7 @@
from __future__ import unicode_literals
import frappe
-from frappe.utils import cstr, extract_email_id
+from frappe.utils import cstr
from erpnext.controllers.status_updater import StatusUpdater
@@ -22,6 +22,11 @@
def validate(self):
self.set_status()
self.validate_primary_contact()
+ self.set_user()
+
+ def set_user(self):
+ if not self.user and self.email_id:
+ self.user = frappe.db.get_value("User", {"email": self.email_id})
def validate_primary_contact(self):
if self.is_primary_contact == 1:
@@ -54,6 +59,21 @@
self.name)
@frappe.whitelist()
+def invite_user(contact):
+ contact = frappe.get_doc("Contact", contact)
+ 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)
+
+ return user.name
+
+@frappe.whitelist()
def get_contact_details(contact):
contact = frappe.get_doc("Contact", contact)
out = {