From 788887367203e5074af3a41798dec4ee7e7aee58 Mon Sep 17 00:00:00 2001 From: Himanshu Warekar Date: Tue, 15 Oct 2019 14:54:01 +0530 Subject: [PATCH 01/90] feat: allow email append to for other doctypes --- .../doctype/customize_form/customize_form.json | 9 ++++++++- .../custom/doctype/customize_form/customize_form.py | 3 ++- frappe/email/doctype/email_account/email_account.py | 12 +++++++++++- 3 files changed, 21 insertions(+), 3 deletions(-) diff --git a/frappe/custom/doctype/customize_form/customize_form.json b/frappe/custom/doctype/customize_form/customize_form.json index 0b1df62f9d..4778bf524f 100644 --- a/frappe/custom/doctype/customize_form/customize_form.json +++ b/frappe/custom/doctype/customize_form/customize_form.json @@ -20,6 +20,7 @@ "allow_auto_repeat", "allow_import", "image_view", + "allow_in_email_append_to", "column_break_5", "title_field", "image_field", @@ -174,13 +175,19 @@ "fieldname": "allow_import", "fieldtype": "Check", "label": "Allow Import (via Data Import Tool)" + }, + { + "default": "0", + "fieldname": "allow_in_email_append_to", + "fieldtype": "Check", + "label": "Allow in Email Append To" } ], "hide_toolbar": 1, "icon": "fa fa-glass", "idx": 1, "issingle": 1, - "modified": "2019-10-08 11:16:36.698006", + "modified": "2019-10-15 14:20:51.272870", "modified_by": "Administrator", "module": "Custom", "name": "Customize Form", diff --git a/frappe/custom/doctype/customize_form/customize_form.py b/frappe/custom/doctype/customize_form/customize_form.py index b851d40b83..190d4cb567 100644 --- a/frappe/custom/doctype/customize_form/customize_form.py +++ b/frappe/custom/doctype/customize_form/customize_form.py @@ -31,7 +31,8 @@ doctype_properties = { 'track_changes': 'Check', 'track_views': 'Check', 'allow_auto_repeat': 'Check', - 'allow_import': 'Check' + 'allow_import': 'Check', + 'allow_in_email_append_to': 'Check' } docfield_properties = { diff --git a/frappe/email/doctype/email_account/email_account.py b/frappe/email/doctype/email_account/email_account.py index f10f08664c..73e85659b3 100755 --- a/frappe/email/doctype/email_account/email_account.py +++ b/frappe/email/doctype/email_account/email_account.py @@ -652,7 +652,17 @@ class EmailAccount(Document): @frappe.whitelist() def get_append_to(doctype=None, txt=None, searchfield=None, start=None, page_len=None, filters=None): if not txt: txt = "" - return [[d] for d in frappe.get_hooks("email_append_to") if txt in d] + + email_append_to_list = frappe.get_hooks("email_append_to") + custom_email_append_to_list = frappe.get_list("Property Setter", filters={ + "property": "allow_in_email_append_to", + "value": 1 + }, fields=["doc_type"]) + + for doctype in custom_email_append_to_list: + email_append_to_list.append(doctype.doc_type) + + return [[d] for d in set(email_append_to_list) if txt in d] def test_internet(host="8.8.8.8", port=53, timeout=3): """Returns True if internet is connected From f207d98d784ac7ab2f2b2882fbb5640e273c4120 Mon Sep 17 00:00:00 2001 From: Himanshu Warekar Date: Tue, 15 Oct 2019 15:21:42 +0530 Subject: [PATCH 02/90] fix: check if subject and status exists --- frappe/custom/doctype/customize_form/customize_form.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/frappe/custom/doctype/customize_form/customize_form.py b/frappe/custom/doctype/customize_form/customize_form.py index 190d4cb567..57d0251f72 100644 --- a/frappe/custom/doctype/customize_form/customize_form.py +++ b/frappe/custom/doctype/customize_form/customize_form.py @@ -165,6 +165,7 @@ class CustomizeForm(Document): self.flags.update_db = False self.flags.rebuild_doctype_for_global_search = False + self.check_email_append_to() self.set_property_setters() self.update_custom_fields() self.set_name_translation() @@ -249,6 +250,13 @@ class CustomizeForm(Document): self.make_property_setter(property=property, value=df.get(property), property_type=docfield_properties[property], fieldname=df.fieldname) + def check_email_append_to(self): + meta = frappe.get_meta(self.doc_type) + + if self.allow_in_email_append_to and not (meta.has_field("subject") and meta.has_field("status")): + frappe.throw(_("Add custom fields for Subject and Status in Document Type \ + {0} to enable Email Append To").format(self.doc_type)) + def update_custom_fields(self): for i, df in enumerate(self.get("fields")): if df.get("is_custom_field"): From 93e64e4ce659c5c0919694b8ff7927bd6486da5c Mon Sep 17 00:00:00 2001 From: Himanshu Warekar Date: Sat, 26 Oct 2019 18:14:47 +0530 Subject: [PATCH 03/90] fix: check if meta has subject and status --- .../doctype/email_account/email_account.py | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/frappe/email/doctype/email_account/email_account.py b/frappe/email/doctype/email_account/email_account.py index 73e85659b3..703835e87b 100755 --- a/frappe/email/doctype/email_account/email_account.py +++ b/frappe/email/doctype/email_account/email_account.py @@ -653,16 +653,20 @@ class EmailAccount(Document): def get_append_to(doctype=None, txt=None, searchfield=None, start=None, page_len=None, filters=None): if not txt: txt = "" + if frappe.cache().hget("email_append_to", "email_append_to_dts"): + return frappe.cache().hget("email_append_to", "email_append_to_dts") + email_append_to_list = frappe.get_hooks("email_append_to") - custom_email_append_to_list = frappe.get_list("Property Setter", filters={ - "property": "allow_in_email_append_to", - "value": 1 - }, fields=["doc_type"]) - for doctype in custom_email_append_to_list: - email_append_to_list.append(doctype.doc_type) + for dt in frappe.get_list("DocType", filters={"istable": 0, "issingle": 0}): + meta = frappe.get_meta(dt.name) + if meta.allow_in_email_append_to and meta.has_field("subject") and meta.has_field("status"): + email_append_to_list.append(dt.name) - return [[d] for d in set(email_append_to_list) if txt in d] + email_append = [[d] for d in set(email_append_to_list) if txt in d] + frappe.cache().hset("email_append_to", "email_append_to_dts", email_append) + + return email_append def test_internet(host="8.8.8.8", port=53, timeout=3): """Returns True if internet is connected From 7e7c14e2e72652a2d6641596543848ecf59bc7ce Mon Sep 17 00:00:00 2001 From: Himanshu Warekar Date: Thu, 21 Nov 2019 12:21:30 +0530 Subject: [PATCH 04/90] fix: statushsould have open and closed in options --- .../doctype/customize_form/customize_form.py | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/frappe/custom/doctype/customize_form/customize_form.py b/frappe/custom/doctype/customize_form/customize_form.py index 57d0251f72..7f853324b5 100644 --- a/frappe/custom/doctype/customize_form/customize_form.py +++ b/frappe/custom/doctype/customize_form/customize_form.py @@ -253,9 +253,17 @@ class CustomizeForm(Document): def check_email_append_to(self): meta = frappe.get_meta(self.doc_type) - if self.allow_in_email_append_to and not (meta.has_field("subject") and meta.has_field("status")): - frappe.throw(_("Add custom fields for Subject and Status in Document Type \ - {0} to enable Email Append To").format(self.doc_type)) + if self.allow_in_email_append_to: + if not meta.has_field("subject"): + frappe.throw(_("Add custom fields for Subject in Document Type {0} to enable Email Append To").format(self.doc_type)) + + if not meta.has_field("status"): + frappe.throw(_("Add custom fields for Status in Document Type {0} to enable Email Append To").format(self.doc_type)) + else: + status = meta.get_field("status") + for option in ["Open", "Closed"]: + if not option in status.options: + frappe.throw(_("Status field should have status {0} in options").format(option)) def update_custom_fields(self): for i, df in enumerate(self.get("fields")): From 12c1d6cc57533107d27df3937b230f349c9f8aa3 Mon Sep 17 00:00:00 2001 From: Himanshu Warekar Date: Thu, 21 Nov 2019 13:55:11 +0530 Subject: [PATCH 05/90] fix: check if property exists --- frappe/email/doctype/email_account/email_account.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frappe/email/doctype/email_account/email_account.py b/frappe/email/doctype/email_account/email_account.py index 703835e87b..e1f5a2adeb 100755 --- a/frappe/email/doctype/email_account/email_account.py +++ b/frappe/email/doctype/email_account/email_account.py @@ -660,7 +660,7 @@ def get_append_to(doctype=None, txt=None, searchfield=None, start=None, page_len for dt in frappe.get_list("DocType", filters={"istable": 0, "issingle": 0}): meta = frappe.get_meta(dt.name) - if meta.allow_in_email_append_to and meta.has_field("subject") and meta.has_field("status"): + if meta.get("allow_in_email_append_to") and meta.allow_in_email_append_to: email_append_to_list.append(dt.name) email_append = [[d] for d in set(email_append_to_list) if txt in d] From 87eb7243fd61175b9f63e320ab31130a6612b0c0 Mon Sep 17 00:00:00 2001 From: Himanshu Warekar Date: Thu, 21 Nov 2019 15:31:30 +0530 Subject: [PATCH 06/90] fix: allow custom doctypes --- frappe/email/doctype/email_account/email_account.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frappe/email/doctype/email_account/email_account.py b/frappe/email/doctype/email_account/email_account.py index e1f5a2adeb..c45dab110d 100755 --- a/frappe/email/doctype/email_account/email_account.py +++ b/frappe/email/doctype/email_account/email_account.py @@ -660,7 +660,7 @@ def get_append_to(doctype=None, txt=None, searchfield=None, start=None, page_len for dt in frappe.get_list("DocType", filters={"istable": 0, "issingle": 0}): meta = frappe.get_meta(dt.name) - if meta.get("allow_in_email_append_to") and meta.allow_in_email_append_to: + if meta.custom or (meta.get("allow_in_email_append_to") and meta.allow_in_email_append_to): email_append_to_list.append(dt.name) email_append = [[d] for d in set(email_append_to_list) if txt in d] From 8c9918bc96ef630a9d75589474c6e8f8e66d5814 Mon Sep 17 00:00:00 2001 From: Himanshu Warekar Date: Thu, 12 Dec 2019 12:46:21 +0530 Subject: [PATCH 07/90] feat: allow document creation via email --- frappe/core/doctype/doctype/doctype.json | 28 ++++++++++- frappe/core/doctype/doctype/doctype.py | 46 +++++++++++++++++++ .../customize_form/customize_form.json | 28 +++++++++-- .../doctype/customize_form/customize_form.py | 24 +++------- frappe/database/mariadb/framework_mariadb.sql | 4 ++ .../database/postgres/framework_postgres.sql | 4 ++ .../doctype/email_account/email_account.py | 26 +++-------- 7 files changed, 118 insertions(+), 42 deletions(-) diff --git a/frappe/core/doctype/doctype/doctype.json b/frappe/core/doctype/doctype/doctype.json index 4e3f2fd84a..0fa90ac5df 100644 --- a/frappe/core/doctype/doctype/doctype.json +++ b/frappe/core/doctype/doctype/doctype.json @@ -35,6 +35,9 @@ "timeline_field", "nsm_parent_field", "max_attachments", + "subject_field", + "sender_field", + "status_field", "column_break_23", "hide_toolbar", "allow_copy", @@ -42,6 +45,7 @@ "allow_import", "allow_events_in_timeline", "allow_auto_repeat", + "email_append_to", "view_settings", "title_field", "search_fields", @@ -488,11 +492,33 @@ "fieldtype": "Table", "label": "Links", "options": "DocType Link" + }, + { + "fieldname": "subject_field", + "fieldtype": "Data", + "label": "Subject Field" + }, + { + "fieldname": "sender_field", + "fieldtype": "Data", + "label": "Sender Field" + }, + { + "default": "0", + "fieldname": "email_append_to", + "fieldtype": "Check", + "label": "Allow document creation via Email" + }, + { + "fieldname": "status_field", + "fieldtype": "Data", + "label": "Status Field" } ], "icon": "fa fa-bolt", "idx": 6, - "modified": "2019-11-25 17:24:03.690192", + "links": [], + "modified": "2019-12-12 12:05:39.317311", "modified_by": "Administrator", "module": "Core", "name": "DocType", diff --git a/frappe/core/doctype/doctype/doctype.py b/frappe/core/doctype/doctype/doctype.py index 1223d50878..35cbdfa992 100644 --- a/frappe/core/doctype/doctype/doctype.py +++ b/frappe/core/doctype/doctype/doctype.py @@ -93,6 +93,8 @@ class DocType(Document): if not self.is_new(): self.setup_fields_to_fetch() + check_email_append_to(self) + if self.default_print_format and not self.custom: frappe.throw(_('Standard DocType cannot have default print format, use Customize Form')) @@ -1144,3 +1146,47 @@ def check_if_fieldname_conflicts_with_methods(doctype, fieldname): def clear_linked_doctype_cache(): frappe.cache().delete_value('linked_doctypes_without_ignore_user_permissions_enabled') + +def check_email_append_to(doc): + if not doc.email_append_to: + return + + # Subject Field + doc.subject_field = doc.subject_field.strip() if doc.subject_field else None + subject_field = get_field(doc, doc.subject_field) + + if not (doc.subject_field or subject_field): + frappe.throw(_("Add Subject Field for creating documents from Email")) + + if subject_field.fieldtype not in ["Data", "Text", "Long Text", "Small Text", "Text Editor"]: + frappe.throw(_("Subject Field type should be Data, Text, Long Text, Small Text, Text Editor")) + + # Sender Field + doc.sender_field = doc.sender_field.strip() if doc.sender_field else None + sender_field = get_field(doc, doc.sender_field) + + if not (doc.sender_field or sender_field): + frappe.throw(_("Add Sender Field for creating documents from Email")) + + # Status Field + doc.status_field = doc.status_field.strip() if doc.status_field else None + status_field = get_field(doc, doc.status_field) + + if not (doc.status_field or status_field): + frappe.throw(_("Add Status Field for creating documents from Email")) + + if status_field.fieldtype != "Select": + frappe.throw(_("Status Field type should be Select")) + + for option in ["Open", "Closed"]: + if not option in status_field.options: + frappe.throw(_("Status field should have status Open and Closed in options")) + + +def get_field(doc, fieldname): + if not (doc or fieldname): + return + + for field in doc.fields: + if field.fieldname == fieldname: + return field diff --git a/frappe/custom/doctype/customize_form/customize_form.json b/frappe/custom/doctype/customize_form/customize_form.json index 4778bf524f..3e547fb22f 100644 --- a/frappe/custom/doctype/customize_form/customize_form.json +++ b/frappe/custom/doctype/customize_form/customize_form.json @@ -1,4 +1,5 @@ { + "actions": [], "autoname": "DL.####", "creation": "2013-01-29 17:55:08", "doctype": "DocType", @@ -20,11 +21,14 @@ "allow_auto_repeat", "allow_import", "image_view", - "allow_in_email_append_to", + "email_append_to", "column_break_5", "title_field", "image_field", "search_fields", + "subject_field", + "sender_field", + "status_field", "section_break_8", "sort_field", "column_break_10", @@ -176,18 +180,34 @@ "fieldtype": "Check", "label": "Allow Import (via Data Import Tool)" }, + { + "fieldname": "subject_field", + "fieldtype": "Data", + "label": "Subject Field" + }, + { + "fieldname": "sender_field", + "fieldtype": "Data", + "label": "Sender Field" + }, { "default": "0", - "fieldname": "allow_in_email_append_to", + "fieldname": "email_append_to", "fieldtype": "Check", - "label": "Allow in Email Append To" + "label": "Allow document creation via Email" + }, + { + "fieldname": "status_field", + "fieldtype": "Data", + "label": "Status Field" } ], "hide_toolbar": 1, "icon": "fa fa-glass", "idx": 1, "issingle": 1, - "modified": "2019-10-15 14:20:51.272870", + "links": [], + "modified": "2019-12-12 12:44:02.674456", "modified_by": "Administrator", "module": "Custom", "name": "Customize Form", diff --git a/frappe/custom/doctype/customize_form/customize_form.py b/frappe/custom/doctype/customize_form/customize_form.py index 7f853324b5..5e5a9f0c9f 100644 --- a/frappe/custom/doctype/customize_form/customize_form.py +++ b/frappe/custom/doctype/customize_form/customize_form.py @@ -12,7 +12,7 @@ from frappe import _ from frappe.utils import cint from frappe.model.document import Document from frappe.model import no_value_fields, core_doctypes_list -from frappe.core.doctype.doctype.doctype import validate_fields_for_doctype +from frappe.core.doctype.doctype.doctype import validate_fields_for_doctype, check_email_append_to from frappe.custom.doctype.custom_field.custom_field import create_custom_field from frappe.model.docfield import supports_translation @@ -32,7 +32,10 @@ doctype_properties = { 'track_views': 'Check', 'allow_auto_repeat': 'Check', 'allow_import': 'Check', - 'allow_in_email_append_to': 'Check' + 'email_append_to': 'Check', + 'subject_field': 'Data', + 'sender_field': 'Data', + 'status_field': 'Data' } docfield_properties = { @@ -165,7 +168,7 @@ class CustomizeForm(Document): self.flags.update_db = False self.flags.rebuild_doctype_for_global_search = False - self.check_email_append_to() + check_email_append_to(self) self.set_property_setters() self.update_custom_fields() self.set_name_translation() @@ -250,21 +253,6 @@ class CustomizeForm(Document): self.make_property_setter(property=property, value=df.get(property), property_type=docfield_properties[property], fieldname=df.fieldname) - def check_email_append_to(self): - meta = frappe.get_meta(self.doc_type) - - if self.allow_in_email_append_to: - if not meta.has_field("subject"): - frappe.throw(_("Add custom fields for Subject in Document Type {0} to enable Email Append To").format(self.doc_type)) - - if not meta.has_field("status"): - frappe.throw(_("Add custom fields for Status in Document Type {0} to enable Email Append To").format(self.doc_type)) - else: - status = meta.get_field("status") - for option in ["Open", "Closed"]: - if not option in status.options: - frappe.throw(_("Status field should have status {0} in options").format(option)) - def update_custom_fields(self): for i, df in enumerate(self.get("fields")): if df.get("is_custom_field"): diff --git a/frappe/database/mariadb/framework_mariadb.sql b/frappe/database/mariadb/framework_mariadb.sql index b1a769b189..10e2ef7e7d 100644 --- a/frappe/database/mariadb/framework_mariadb.sql +++ b/frappe/database/mariadb/framework_mariadb.sql @@ -215,6 +215,10 @@ CREATE TABLE `tabDocType` ( `allow_guest_to_view` int(1) NOT NULL DEFAULT 0, `route` varchar(255) DEFAULT NULL, `is_published_field` varchar(255) DEFAULT NULL, + `email_append_to` int(1) NOT NULL DEFAULT 0, + `subject_field` varchar(255) DEFAULT NULL, + `sender_field` varchar(255) DEFAULT NULL, + `status_field` varchar(255) DEFAULT NULL, PRIMARY KEY (`name`), KEY `parent` (`parent`) ) ENGINE=InnoDB ROW_FORMAT=COMPRESSED CHARACTER SET=utf8mb4 COLLATE=utf8mb4_unicode_ci; diff --git a/frappe/database/postgres/framework_postgres.sql b/frappe/database/postgres/framework_postgres.sql index cd2f02d8e4..c89c9a8b16 100644 --- a/frappe/database/postgres/framework_postgres.sql +++ b/frappe/database/postgres/framework_postgres.sql @@ -220,6 +220,10 @@ CREATE TABLE "tabDocType" ( "allow_guest_to_view" smallint NOT NULL DEFAULT 0, "route" varchar(255) DEFAULT NULL, "is_published_field" varchar(255) DEFAULT NULL, + `email_append_to` smallint NOT NULL DEFAULT 0, + `subject_field` varchar(255) DEFAULT NULL, + `sender_field` varchar(255) DEFAULT NULL, + `status_field` varchar(255) DEFAULT NULL, PRIMARY KEY ("name") ) ; diff --git a/frappe/email/doctype/email_account/email_account.py b/frappe/email/doctype/email_account/email_account.py index 4dde4826bf..b520c92399 100755 --- a/frappe/email/doctype/email_account/email_account.py +++ b/frappe/email/doctype/email_account/email_account.py @@ -419,42 +419,30 @@ class EmailAccount(Document): If no thread id is found and `append_to` is set for the email account, it will create a new parent transaction (e.g. Issue)""" - parent = None - - parent = self.find_parent_from_in_reply_to(communication, email) + parent = self.find_parent_from_in_reply_to(communication, email) or None if not parent and self.append_to: self.set_sender_field_and_subject_field() - - if not parent and self.append_to: parent = self.find_parent_based_on_subject_and_sender(communication, email) - if not parent and self.append_to and self.append_to!="Communication": - parent = self.create_new_parent(communication, email) + if self.append_to!="Communication": + parent = self.create_new_parent(communication, email) if parent: communication.reference_doctype = parent.doctype communication.reference_name = parent.name # check if message is notification and disable notifications for this message - isnotification = email.mail.get("isnotification") - if isnotification: - if "notification" in isnotification: - communication.unread_notification_sent = 1 + if email.mail.get("isnotification") and "notification" in email.mail.get("isnotification"): + communication.unread_notification_sent = 1 def set_sender_field_and_subject_field(self): '''Identify the sender and subject fields from the `append_to` DocType''' # set subject_field and sender_field - meta_module = frappe.get_meta_module(self.append_to) meta = frappe.get_meta(self.append_to) - self.subject_field = getattr(meta_module, "subject_field", "subject") - if not meta.get_field(self.subject_field): - self.subject_field = None - - self.sender_field = getattr(meta_module, "sender_field", "sender") - if not meta.get_field(self.sender_field): - self.sender_field = None + self.subject_field = meta.subject_field if meta.subject_field else None + self.sender_field = meta.sender_field if meta.sender_field else None def find_parent_based_on_subject_and_sender(self, communication, email): '''Find parent document based on subject and sender match''' From ec89d275a2bad2de14c7d4249cd17dc7b9a69dd4 Mon Sep 17 00:00:00 2001 From: Himanshu Warekar Date: Thu, 12 Dec 2019 15:04:56 +0530 Subject: [PATCH 08/90] feat: remove hooks for email_append_to --- .../doctype/communication/communication.json | 8 ++++++- frappe/desk/doctype/event/event.json | 15 +++++++++++- frappe/desk/doctype/todo/todo.json | 10 ++++++-- frappe/desk/doctype/todo/todo.py | 2 -- .../doctype/email_account/email_account.py | 23 +++++++++++-------- 5 files changed, 42 insertions(+), 16 deletions(-) diff --git a/frappe/core/doctype/communication/communication.json b/frappe/core/doctype/communication/communication.json index 5e34804b93..3418fc073b 100644 --- a/frappe/core/doctype/communication/communication.json +++ b/frappe/core/doctype/communication/communication.json @@ -1,9 +1,11 @@ { + "actions": [], "allow_import": 1, "creation": "2013-01-29 10:47:14", "description": "Keeps track of all communications", "doctype": "DocType", "document_type": "Setup", + "email_append_to": 1, "engine": "InnoDB", "field_order": [ "subject", @@ -383,7 +385,8 @@ ], "icon": "fa fa-comment", "idx": 1, - "modified": "2019-10-09 14:22:27.664645", + "links": [], + "modified": "2019-12-12 13:01:23.716052", "modified_by": "Administrator", "module": "Core", "name": "Communication", @@ -430,8 +433,11 @@ } ], "search_fields": "subject", + "sender_field": "sender", "sort_field": "modified", "sort_order": "DESC", + "status_field": "status", + "subject_field": "subject", "title_field": "subject", "track_changes": 1, "track_seen": 1 diff --git a/frappe/desk/doctype/event/event.json b/frappe/desk/doctype/event/event.json index 032030ddef..8a0372b13f 100644 --- a/frappe/desk/doctype/event/event.json +++ b/frappe/desk/doctype/event/event.json @@ -1,9 +1,11 @@ { + "actions": [], "allow_import": 1, "autoname": "EV.#####", "creation": "2013-06-10 13:17:47", "doctype": "DocType", "document_type": "Document", + "email_append_to": 1, "engine": "InnoDB", "field_order": [ "details", @@ -17,6 +19,7 @@ "starts_on", "ends_on", "status", + "sender", "all_day", "sync_with_google_calendar", "sb_00", @@ -262,11 +265,18 @@ "fieldtype": "Check", "label": "Pulled from Google Calendar", "read_only": 1 + }, + { + "fieldname": "sender", + "fieldtype": "Data", + "label": "Sender", + "read_only": 1 } ], "icon": "fa fa-calendar", "idx": 1, - "modified": "2019-08-08 16:01:19.489396", + "links": [], + "modified": "2019-12-12 12:58:36.621861", "modified_by": "Administrator", "module": "Desk", "name": "Event", @@ -297,8 +307,11 @@ } ], "read_only": 1, + "sender_field": "sender", "sort_field": "modified", "sort_order": "DESC", + "status_field": "status", + "subject_field": "subject", "title_field": "subject", "track_changes": 1, "track_seen": 1, diff --git a/frappe/desk/doctype/todo/todo.json b/frappe/desk/doctype/todo/todo.json index 508720a488..f80a785ccd 100644 --- a/frappe/desk/doctype/todo/todo.json +++ b/frappe/desk/doctype/todo/todo.json @@ -1,8 +1,10 @@ { + "actions": [], "autoname": "hash", "creation": "2012-07-03 13:30:35", "doctype": "DocType", "document_type": "Setup", + "email_append_to": 1, "engine": "InnoDB", "field_order": [ "description_and_status", @@ -154,7 +156,8 @@ ], "icon": "fa fa-check", "idx": 2, - "modified": "2019-09-10 14:34:59.161750", + "links": [], + "modified": "2019-12-12 12:53:17.565139", "modified_by": "Administrator", "module": "Desk", "name": "ToDo", @@ -185,9 +188,12 @@ ], "quick_entry": 1, "search_fields": "description, reference_type, reference_name", + "sender_field": "sender", "sort_field": "modified", "sort_order": "DESC", + "status_field": "status", + "subject_field": "description", "title_field": "description", "track_changes": 1, "track_seen": 1 -} +} \ No newline at end of file diff --git a/frappe/desk/doctype/todo/todo.py b/frappe/desk/doctype/todo/todo.py index 5d04f412c0..034afd3184 100644 --- a/frappe/desk/doctype/todo/todo.py +++ b/frappe/desk/doctype/todo/todo.py @@ -8,8 +8,6 @@ import json from frappe.model.document import Document from frappe.utils import get_fullname -subject_field = "description" -sender_field = "sender" exclude_from_linked_with = True class ToDo(Document): diff --git a/frappe/email/doctype/email_account/email_account.py b/frappe/email/doctype/email_account/email_account.py index b520c92399..626ecbf378 100755 --- a/frappe/email/doctype/email_account/email_account.py +++ b/frappe/email/doctype/email_account/email_account.py @@ -637,21 +637,24 @@ class EmailAccount(Document): frappe.throw(_("Automatic Linking can be activated only for one Email Account.")) @frappe.whitelist() -def get_append_to(doctype=None, txt=None, searchfield=None, start=None, page_len=None, filters=None): - if not txt: txt = "" +def get_append_to(doctype=None, txt=None, searchfield=None, start=None, page_len=None, filters=None, reset_cache=False): - if frappe.cache().hget("email_append_to", "email_append_to_dts"): - return frappe.cache().hget("email_append_to", "email_append_to_dts") + if frappe.cache().hget("email_append_to", "email_append_to_doctypes") and not reset_cache: + return frappe.cache().hget("email_append_to", "email_append_to_doctypes") - email_append_to_list = frappe.get_hooks("email_append_to") + txt = txt if txt else "" + email_append_to_list = [] - for dt in frappe.get_list("DocType", filters={"istable": 0, "issingle": 0}): - meta = frappe.get_meta(dt.name) - if meta.custom or (meta.get("allow_in_email_append_to") and meta.allow_in_email_append_to): + for dt in frappe.get_all("DocType", filters={"istable": 0, "issingle": 0}, fields=["name", "email_append_to"]): + if dt.get("email_append_to") and dt.email_append_to: email_append_to_list.append(dt.name) + else: + meta = frappe.get_meta(dt.name) + if meta.get("email_append_to") and meta.email_append_to: + email_append_to_list.append(dt.name) - email_append = [[d] for d in set(email_append_to_list) if txt in d] - frappe.cache().hset("email_append_to", "email_append_to_dts", email_append) + email_append_to = [[d] for d in set(email_append_to_list) if txt in d] + frappe.cache().hset("email_append_to", "email_append_to_doctypes", email_append_to) return email_append From b98ea6415016d5f4f08c6d15ec57f5b65506eab0 Mon Sep 17 00:00:00 2001 From: Himanshu Warekar Date: Thu, 12 Dec 2019 19:23:22 +0530 Subject: [PATCH 09/90] fix: remove status field --- frappe/core/doctype/doctype/doctype.json | 8 +------- frappe/core/doctype/doctype/doctype.py | 14 -------------- .../doctype/customize_form/customize_form.json | 8 +------- .../doctype/customize_form/customize_form.py | 3 +-- 4 files changed, 3 insertions(+), 30 deletions(-) diff --git a/frappe/core/doctype/doctype/doctype.json b/frappe/core/doctype/doctype/doctype.json index 0fa90ac5df..9a8177d3a3 100644 --- a/frappe/core/doctype/doctype/doctype.json +++ b/frappe/core/doctype/doctype/doctype.json @@ -37,7 +37,6 @@ "max_attachments", "subject_field", "sender_field", - "status_field", "column_break_23", "hide_toolbar", "allow_copy", @@ -508,17 +507,12 @@ "fieldname": "email_append_to", "fieldtype": "Check", "label": "Allow document creation via Email" - }, - { - "fieldname": "status_field", - "fieldtype": "Data", - "label": "Status Field" } ], "icon": "fa fa-bolt", "idx": 6, "links": [], - "modified": "2019-12-12 12:05:39.317311", + "modified": "2019-12-12 19:16:50.130503", "modified_by": "Administrator", "module": "Core", "name": "DocType", diff --git a/frappe/core/doctype/doctype/doctype.py b/frappe/core/doctype/doctype/doctype.py index 35cbdfa992..5610fa4f89 100644 --- a/frappe/core/doctype/doctype/doctype.py +++ b/frappe/core/doctype/doctype/doctype.py @@ -1168,20 +1168,6 @@ def check_email_append_to(doc): if not (doc.sender_field or sender_field): frappe.throw(_("Add Sender Field for creating documents from Email")) - # Status Field - doc.status_field = doc.status_field.strip() if doc.status_field else None - status_field = get_field(doc, doc.status_field) - - if not (doc.status_field or status_field): - frappe.throw(_("Add Status Field for creating documents from Email")) - - if status_field.fieldtype != "Select": - frappe.throw(_("Status Field type should be Select")) - - for option in ["Open", "Closed"]: - if not option in status_field.options: - frappe.throw(_("Status field should have status Open and Closed in options")) - def get_field(doc, fieldname): if not (doc or fieldname): diff --git a/frappe/custom/doctype/customize_form/customize_form.json b/frappe/custom/doctype/customize_form/customize_form.json index 3e547fb22f..49e8dee366 100644 --- a/frappe/custom/doctype/customize_form/customize_form.json +++ b/frappe/custom/doctype/customize_form/customize_form.json @@ -28,7 +28,6 @@ "search_fields", "subject_field", "sender_field", - "status_field", "section_break_8", "sort_field", "column_break_10", @@ -195,11 +194,6 @@ "fieldname": "email_append_to", "fieldtype": "Check", "label": "Allow document creation via Email" - }, - { - "fieldname": "status_field", - "fieldtype": "Data", - "label": "Status Field" } ], "hide_toolbar": 1, @@ -207,7 +201,7 @@ "idx": 1, "issingle": 1, "links": [], - "modified": "2019-12-12 12:44:02.674456", + "modified": "2019-12-12 19:17:08.426469", "modified_by": "Administrator", "module": "Custom", "name": "Customize Form", diff --git a/frappe/custom/doctype/customize_form/customize_form.py b/frappe/custom/doctype/customize_form/customize_form.py index 5e5a9f0c9f..4c5fe76bed 100644 --- a/frappe/custom/doctype/customize_form/customize_form.py +++ b/frappe/custom/doctype/customize_form/customize_form.py @@ -34,8 +34,7 @@ doctype_properties = { 'allow_import': 'Check', 'email_append_to': 'Check', 'subject_field': 'Data', - 'sender_field': 'Data', - 'status_field': 'Data' + 'sender_field': 'Data' } docfield_properties = { From 78f506226a12aa4cf32d769293cdb41d1ec994b4 Mon Sep 17 00:00:00 2001 From: Himanshu Warekar Date: Thu, 12 Dec 2019 21:14:26 +0530 Subject: [PATCH 10/90] fix: return correct variable --- frappe/email/doctype/email_account/email_account.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frappe/email/doctype/email_account/email_account.py b/frappe/email/doctype/email_account/email_account.py index 626ecbf378..7d9c2bb8fb 100755 --- a/frappe/email/doctype/email_account/email_account.py +++ b/frappe/email/doctype/email_account/email_account.py @@ -656,7 +656,7 @@ def get_append_to(doctype=None, txt=None, searchfield=None, start=None, page_len email_append_to = [[d] for d in set(email_append_to_list) if txt in d] frappe.cache().hset("email_append_to", "email_append_to_doctypes", email_append_to) - return email_append + return email_append_to def test_internet(host="8.8.8.8", port=53, timeout=3): """Returns True if internet is connected From 2fe3430e743a2d4311018b02bc5d8737fc2b9ecc Mon Sep 17 00:00:00 2001 From: Himanshu Warekar Date: Fri, 27 Dec 2019 14:30:24 +0530 Subject: [PATCH 11/90] fix: create a new section for email append to --- frappe/core/doctype/doctype/doctype.js | 12 +++++++++++- frappe/core/doctype/doctype/doctype.json | 17 +++++++++++++---- .../doctype/customize_form/customize_form.js | 9 +++++++++ .../doctype/customize_form/customize_form.json | 17 ++++++++++++++--- 4 files changed, 47 insertions(+), 8 deletions(-) diff --git a/frappe/core/doctype/doctype/doctype.js b/frappe/core/doctype/doctype/doctype.js index 9a19185cfc..379f7cdd9e 100644 --- a/frappe/core/doctype/doctype/doctype.js +++ b/frappe/core/doctype/doctype/doctype.js @@ -53,7 +53,17 @@ frappe.ui.form.on('DocType', { frm.events.autoname(frm); }, - autoname(frm) { + email_append_to: function (frm) { + frm.set_df_property("subject_field", "reqd", 0); + frm.set_df_property("sender_field", "reqd", 0); + + if (frm.doc.email_append_to) { + frm.set_df_property("subject_field", "reqd", 1); + frm.set_df_property("sender_field", "reqd", 1); + } + }, + + autoname: function(frm) { frm.set_df_property('fields', 'reqd', frm.doc.autoname !== 'Prompt'); } }) diff --git a/frappe/core/doctype/doctype/doctype.json b/frappe/core/doctype/doctype/doctype.json index 9a8177d3a3..59fd55c402 100644 --- a/frappe/core/doctype/doctype/doctype.json +++ b/frappe/core/doctype/doctype/doctype.json @@ -35,8 +35,6 @@ "timeline_field", "nsm_parent_field", "max_attachments", - "subject_field", - "sender_field", "column_break_23", "hide_toolbar", "allow_copy", @@ -44,7 +42,6 @@ "allow_import", "allow_events_in_timeline", "allow_auto_repeat", - "email_append_to", "view_settings", "title_field", "search_fields", @@ -57,6 +54,10 @@ "color", "show_preview_popup", "show_name_in_global_search", + "email_settings_sb", + "email_append_to", + "subject_field", + "sender_field", "sb2", "permissions", "restrict_to_domain", @@ -493,11 +494,13 @@ "options": "DocType Link" }, { + "depends_on": "email_append_to", "fieldname": "subject_field", "fieldtype": "Data", "label": "Subject Field" }, { + "depends_on": "email_append_to", "fieldname": "sender_field", "fieldtype": "Data", "label": "Sender Field" @@ -507,12 +510,18 @@ "fieldname": "email_append_to", "fieldtype": "Check", "label": "Allow document creation via Email" + }, + { + "collapsible": 1, + "fieldname": "email_settings_sb", + "fieldtype": "Section Break", + "label": "Email Settings" } ], "icon": "fa fa-bolt", "idx": 6, "links": [], - "modified": "2019-12-12 19:16:50.130503", + "modified": "2019-12-27 13:28:06.201814", "modified_by": "Administrator", "module": "Core", "name": "DocType", diff --git a/frappe/custom/doctype/customize_form/customize_form.js b/frappe/custom/doctype/customize_form/customize_form.js index f1eadaaf2e..4ade51ae5b 100644 --- a/frappe/custom/doctype/customize_form/customize_form.js +++ b/frappe/custom/doctype/customize_form/customize_form.js @@ -132,6 +132,15 @@ frappe.ui.form.on("Customize Form", { }, + email_append_to: function(frm) { + frm.set_df_property("subject_field", "reqd", 0); + frm.set_df_property("sender_field", "reqd", 0); + + if (frm.doc.email_append_to) { + frm.set_df_property("subject_field", "reqd", 1); + frm.set_df_property("sender_field", "reqd", 1); + } + } }); frappe.ui.form.on("Customize Form Field", { diff --git a/frappe/custom/doctype/customize_form/customize_form.json b/frappe/custom/doctype/customize_form/customize_form.json index 49e8dee366..f719add96c 100644 --- a/frappe/custom/doctype/customize_form/customize_form.json +++ b/frappe/custom/doctype/customize_form/customize_form.json @@ -26,12 +26,14 @@ "title_field", "image_field", "search_fields", - "subject_field", - "sender_field", "section_break_8", "sort_field", "column_break_10", "sort_order", + "section_break_23", + "subject_field", + "cb_01", + "sender_field", "fields_section_break", "fields" ], @@ -194,6 +196,15 @@ "fieldname": "email_append_to", "fieldtype": "Check", "label": "Allow document creation via Email" + }, + { + "depends_on": "doc_type", + "fieldname": "section_break_23", + "fieldtype": "Section Break" + }, + { + "fieldname": "cb_01", + "fieldtype": "Column Break" } ], "hide_toolbar": 1, @@ -201,7 +212,7 @@ "idx": 1, "issingle": 1, "links": [], - "modified": "2019-12-12 19:17:08.426469", + "modified": "2019-12-27 14:29:49.097980", "modified_by": "Administrator", "module": "Custom", "name": "Customize Form", From 9543b7d4afca27c4e7f618d3f65b3e4fe6541c52 Mon Sep 17 00:00:00 2001 From: Himanshu Warekar Date: Fri, 27 Dec 2019 14:48:46 +0530 Subject: [PATCH 12/90] fix: remove status field --- .../doctype/communication/communication.json | 3 +-- frappe/database/mariadb/framework_mariadb.sql | 1 - frappe/database/postgres/framework_postgres.sql | 1 - frappe/desk/doctype/event/event.json | 3 +-- frappe/desk/doctype/todo/todo.json | 3 +-- .../email/doctype/email_account/email_account.py | 16 ++++++---------- 6 files changed, 9 insertions(+), 18 deletions(-) diff --git a/frappe/core/doctype/communication/communication.json b/frappe/core/doctype/communication/communication.json index 3418fc073b..ae6fb164ec 100644 --- a/frappe/core/doctype/communication/communication.json +++ b/frappe/core/doctype/communication/communication.json @@ -386,7 +386,7 @@ "icon": "fa fa-comment", "idx": 1, "links": [], - "modified": "2019-12-12 13:01:23.716052", + "modified": "2019-12-27 14:44:04.880373", "modified_by": "Administrator", "module": "Core", "name": "Communication", @@ -436,7 +436,6 @@ "sender_field": "sender", "sort_field": "modified", "sort_order": "DESC", - "status_field": "status", "subject_field": "subject", "title_field": "subject", "track_changes": 1, diff --git a/frappe/database/mariadb/framework_mariadb.sql b/frappe/database/mariadb/framework_mariadb.sql index 10e2ef7e7d..bf9e0e33c8 100644 --- a/frappe/database/mariadb/framework_mariadb.sql +++ b/frappe/database/mariadb/framework_mariadb.sql @@ -218,7 +218,6 @@ CREATE TABLE `tabDocType` ( `email_append_to` int(1) NOT NULL DEFAULT 0, `subject_field` varchar(255) DEFAULT NULL, `sender_field` varchar(255) DEFAULT NULL, - `status_field` varchar(255) DEFAULT NULL, PRIMARY KEY (`name`), KEY `parent` (`parent`) ) ENGINE=InnoDB ROW_FORMAT=COMPRESSED CHARACTER SET=utf8mb4 COLLATE=utf8mb4_unicode_ci; diff --git a/frappe/database/postgres/framework_postgres.sql b/frappe/database/postgres/framework_postgres.sql index c89c9a8b16..6bd20d241b 100644 --- a/frappe/database/postgres/framework_postgres.sql +++ b/frappe/database/postgres/framework_postgres.sql @@ -223,7 +223,6 @@ CREATE TABLE "tabDocType" ( `email_append_to` smallint NOT NULL DEFAULT 0, `subject_field` varchar(255) DEFAULT NULL, `sender_field` varchar(255) DEFAULT NULL, - `status_field` varchar(255) DEFAULT NULL, PRIMARY KEY ("name") ) ; diff --git a/frappe/desk/doctype/event/event.json b/frappe/desk/doctype/event/event.json index 8a0372b13f..59ba7689db 100644 --- a/frappe/desk/doctype/event/event.json +++ b/frappe/desk/doctype/event/event.json @@ -276,7 +276,7 @@ "icon": "fa fa-calendar", "idx": 1, "links": [], - "modified": "2019-12-12 12:58:36.621861", + "modified": "2019-12-27 14:45:51.332025", "modified_by": "Administrator", "module": "Desk", "name": "Event", @@ -310,7 +310,6 @@ "sender_field": "sender", "sort_field": "modified", "sort_order": "DESC", - "status_field": "status", "subject_field": "subject", "title_field": "subject", "track_changes": 1, diff --git a/frappe/desk/doctype/todo/todo.json b/frappe/desk/doctype/todo/todo.json index f80a785ccd..cb6dc2fc03 100644 --- a/frappe/desk/doctype/todo/todo.json +++ b/frappe/desk/doctype/todo/todo.json @@ -157,7 +157,7 @@ "icon": "fa fa-check", "idx": 2, "links": [], - "modified": "2019-12-12 12:53:17.565139", + "modified": "2019-12-27 14:45:25.161055", "modified_by": "Administrator", "module": "Desk", "name": "ToDo", @@ -191,7 +191,6 @@ "sender_field": "sender", "sort_field": "modified", "sort_order": "DESC", - "status_field": "status", "subject_field": "description", "title_field": "description", "track_changes": 1, diff --git a/frappe/email/doctype/email_account/email_account.py b/frappe/email/doctype/email_account/email_account.py index 0bd4beed0b..74285e2182 100755 --- a/frappe/email/doctype/email_account/email_account.py +++ b/frappe/email/doctype/email_account/email_account.py @@ -637,24 +637,20 @@ class EmailAccount(Document): frappe.throw(_("Automatic Linking can be activated only for one Email Account.")) @frappe.whitelist() -def get_append_to(doctype=None, txt=None, searchfield=None, start=None, page_len=None, filters=None, reset_cache=False): - - if frappe.cache().hget("email_append_to", "email_append_to_doctypes") and not reset_cache: - return frappe.cache().hget("email_append_to", "email_append_to_doctypes") - +def get_append_to(doctype=None, txt=None, searchfield=None, start=None, page_len=None, filters=None): txt = txt if txt else "" email_append_to_list = [] + # Set Email Append To DocTypes via DocType for dt in frappe.get_all("DocType", filters={"istable": 0, "issingle": 0}, fields=["name", "email_append_to"]): if dt.get("email_append_to") and dt.email_append_to: email_append_to_list.append(dt.name) - else: - meta = frappe.get_meta(dt.name) - if meta.get("email_append_to") and meta.email_append_to: - email_append_to_list.append(dt.name) + + # Set Email Append To DocTypes set via Customize Form + for dt in frappe.get_list("Property Setter", filters={"property": "email_append_to", "value": 1}, fields=["doc_type"]): + email_append_to_list.append(dt.doc_type) email_append_to = [[d] for d in set(email_append_to_list) if txt in d] - frappe.cache().hset("email_append_to", "email_append_to_doctypes", email_append_to) return email_append_to From 3b517023dfd767f7ac96c7a89bcd59bf7e8f8bfc Mon Sep 17 00:00:00 2001 From: Himanshu Warekar Date: Mon, 13 Jan 2020 17:10:45 +0530 Subject: [PATCH 13/90] feat: make sender_field mandatory --- frappe/core/doctype/doctype/doctype.js | 2 -- frappe/core/doctype/doctype/doctype.py | 15 +++++++++------ 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/frappe/core/doctype/doctype/doctype.js b/frappe/core/doctype/doctype/doctype.js index 379f7cdd9e..844d49ed21 100644 --- a/frappe/core/doctype/doctype/doctype.js +++ b/frappe/core/doctype/doctype/doctype.js @@ -54,11 +54,9 @@ frappe.ui.form.on('DocType', { }, email_append_to: function (frm) { - frm.set_df_property("subject_field", "reqd", 0); frm.set_df_property("sender_field", "reqd", 0); if (frm.doc.email_append_to) { - frm.set_df_property("subject_field", "reqd", 1); frm.set_df_property("sender_field", "reqd", 1); } }, diff --git a/frappe/core/doctype/doctype/doctype.py b/frappe/core/doctype/doctype/doctype.py index b8e0bbbe7b..9a4b09b24b 100644 --- a/frappe/core/doctype/doctype/doctype.py +++ b/frappe/core/doctype/doctype/doctype.py @@ -1155,18 +1155,21 @@ def check_email_append_to(doc): doc.subject_field = doc.subject_field.strip() if doc.subject_field else None subject_field = get_field(doc, doc.subject_field) - if not (doc.subject_field or subject_field): - frappe.throw(_("Add Subject Field for creating documents from Email")) + if doc.subject_field and not subject_field: + frappe.throw(_("Select a valid Subject field for creating documents from Email")) - if subject_field.fieldtype not in ["Data", "Text", "Long Text", "Small Text", "Text Editor"]: + if subject_field and subject_field.fieldtype not in ["Data", "Text", "Long Text", "Small Text", "Text Editor"]: frappe.throw(_("Subject Field type should be Data, Text, Long Text, Small Text, Text Editor")) - # Sender Field + # Sender Field is mandatory doc.sender_field = doc.sender_field.strip() if doc.sender_field else None sender_field = get_field(doc, doc.sender_field) - if not (doc.sender_field or sender_field): - frappe.throw(_("Add Sender Field for creating documents from Email")) + if doc.sender_field and not sender_field: + frappe.throw(_("Select a valid Sender Field for creating documents from Email")) + + if not sender_field.options == "Email": + frappe.throw(_("Sender Field should have Email in options")) def get_field(doc, fieldname): From f62f80f33c0ceced29e9c245ba37ad74245b4c6e Mon Sep 17 00:00:00 2001 From: Himanshu Warekar Date: Mon, 13 Jan 2020 23:54:47 +0530 Subject: [PATCH 14/90] fix: check if meta hasattr for subject and email --- frappe/email/doctype/email_account/email_account.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/frappe/email/doctype/email_account/email_account.py b/frappe/email/doctype/email_account/email_account.py index ef8fb0ab28..ad11a50b29 100755 --- a/frappe/email/doctype/email_account/email_account.py +++ b/frappe/email/doctype/email_account/email_account.py @@ -432,7 +432,7 @@ class EmailAccount(Document): self.set_sender_field_and_subject_field() parent = self.find_parent_based_on_subject_and_sender(communication, email) - if self.append_to!="Communication": + if not self.append_to == "Communication": parent = self.create_new_parent(communication, email) if parent: @@ -447,9 +447,14 @@ class EmailAccount(Document): '''Identify the sender and subject fields from the `append_to` DocType''' # set subject_field and sender_field meta = frappe.get_meta(self.append_to) + self.subject_field = None + self.sender_field = None - self.subject_field = meta.subject_field if meta.subject_field else None - self.sender_field = meta.sender_field if meta.sender_field else None + if hasattr(meta, "subject_field"): + self.subject_field = meta.subject_field + + if hasattr(meta, "sender_field"): + self.sender_field = meta.sender_field def find_parent_based_on_subject_and_sender(self, communication, email): '''Find parent document based on subject and sender match''' From 84d740af100723bdff63099c509b09d6759b0705 Mon Sep 17 00:00:00 2001 From: Himanshu Warekar Date: Tue, 14 Jan 2020 17:18:29 +0530 Subject: [PATCH 15/90] fix: add Email in options --- frappe/custom/doctype/customize_form/test_customize_form.py | 2 +- frappe/desk/doctype/todo/todo.json | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/frappe/custom/doctype/customize_form/test_customize_form.py b/frappe/custom/doctype/customize_form/test_customize_form.py index 1cd71ea05d..cace25a03d 100644 --- a/frappe/custom/doctype/customize_form/test_customize_form.py +++ b/frappe/custom/doctype/customize_form/test_customize_form.py @@ -46,7 +46,7 @@ class TestCustomizeForm(unittest.TestCase): d = self.get_customize_form("Event") self.assertEquals(d.doc_type, "Event") - self.assertEquals(len(d.get("fields")), 35) + self.assertEquals(len(d.get("fields")), 36) d = self.get_customize_form("Event") self.assertEquals(d.doc_type, "Event") diff --git a/frappe/desk/doctype/todo/todo.json b/frappe/desk/doctype/todo/todo.json index cb6dc2fc03..15e0e4abe1 100644 --- a/frappe/desk/doctype/todo/todo.json +++ b/frappe/desk/doctype/todo/todo.json @@ -144,7 +144,8 @@ "fieldname": "sender", "fieldtype": "Data", "hidden": 1, - "label": "Sender" + "label": "Sender", + "options": "Email" }, { "fieldname": "assignment_rule", @@ -157,7 +158,7 @@ "icon": "fa fa-check", "idx": 2, "links": [], - "modified": "2019-12-27 14:45:25.161055", + "modified": "2020-01-14 17:04:36.971002", "modified_by": "Administrator", "module": "Desk", "name": "ToDo", From b2d70447fd8aa49c35924d7db28fe4a7bbba0fc6 Mon Sep 17 00:00:00 2001 From: Himanshu Warekar Date: Tue, 14 Jan 2020 22:20:05 +0530 Subject: [PATCH 16/90] fix: update event json and check attr --- frappe/core/doctype/doctype/doctype.py | 2 +- frappe/desk/doctype/event/event.json | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/frappe/core/doctype/doctype/doctype.py b/frappe/core/doctype/doctype/doctype.py index 9a4b09b24b..a60acaaeb8 100644 --- a/frappe/core/doctype/doctype/doctype.py +++ b/frappe/core/doctype/doctype/doctype.py @@ -1148,7 +1148,7 @@ def clear_linked_doctype_cache(): frappe.cache().delete_value('linked_doctypes_without_ignore_user_permissions_enabled') def check_email_append_to(doc): - if not doc.email_append_to: + if not hasattr(doc, "email_append_to") or not doc.email_append_to: return # Subject Field diff --git a/frappe/desk/doctype/event/event.json b/frappe/desk/doctype/event/event.json index 59ba7689db..5768f00f32 100644 --- a/frappe/desk/doctype/event/event.json +++ b/frappe/desk/doctype/event/event.json @@ -270,13 +270,14 @@ "fieldname": "sender", "fieldtype": "Data", "label": "Sender", + "options": "Email", "read_only": 1 } ], "icon": "fa fa-calendar", "idx": 1, "links": [], - "modified": "2019-12-27 14:45:51.332025", + "modified": "2020-01-14 21:47:15.825287", "modified_by": "Administrator", "module": "Desk", "name": "Event", From 858784d558fab178ff82db1e3d3385c8e836e950 Mon Sep 17 00:00:00 2001 From: Himanshu Warekar Date: Sun, 19 Jan 2020 12:07:21 +0530 Subject: [PATCH 17/90] chore: revert code changes --- .../email/doctype/email_account/email_account.py | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/frappe/email/doctype/email_account/email_account.py b/frappe/email/doctype/email_account/email_account.py index ad11a50b29..e4a3b41a56 100755 --- a/frappe/email/doctype/email_account/email_account.py +++ b/frappe/email/doctype/email_account/email_account.py @@ -426,22 +426,28 @@ class EmailAccount(Document): If no thread id is found and `append_to` is set for the email account, it will create a new parent transaction (e.g. Issue)""" - parent = self.find_parent_from_in_reply_to(communication, email) or None + parent = None + + parent = self.find_parent_from_in_reply_to(communication, email) if not parent and self.append_to: self.set_sender_field_and_subject_field() + + if not parent and self.append_to: parent = self.find_parent_based_on_subject_and_sender(communication, email) - if not self.append_to == "Communication": - parent = self.create_new_parent(communication, email) + if not parent and self.append_to and self.append_to!="Communication": + parent = self.create_new_parent(communication, email) if parent: communication.reference_doctype = parent.doctype communication.reference_name = parent.name # check if message is notification and disable notifications for this message - if email.mail.get("isnotification") and "notification" in email.mail.get("isnotification"): - communication.unread_notification_sent = 1 + isnotification = email.mail.get("isnotification") + if isnotification: + if "notification" in isnotification: + communication.unread_notification_sent = 1 def set_sender_field_and_subject_field(self): '''Identify the sender and subject fields from the `append_to` DocType''' From 230073ebf2131bfb6f176352416659703146f0d5 Mon Sep 17 00:00:00 2001 From: Himanshu Warekar Date: Sun, 19 Jan 2020 14:54:18 +0530 Subject: [PATCH 18/90] fix: change to quotes in postgres.sql file --- frappe/database/postgres/framework_postgres.sql | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/frappe/database/postgres/framework_postgres.sql b/frappe/database/postgres/framework_postgres.sql index 16114f8cf8..26760dbcc9 100644 --- a/frappe/database/postgres/framework_postgres.sql +++ b/frappe/database/postgres/framework_postgres.sql @@ -222,9 +222,9 @@ CREATE TABLE "tabDocType" ( "allow_guest_to_view" smallint NOT NULL DEFAULT 0, "route" varchar(255) DEFAULT NULL, "is_published_field" varchar(255) DEFAULT NULL, - `email_append_to` smallint NOT NULL DEFAULT 0, - `subject_field` varchar(255) DEFAULT NULL, - `sender_field` varchar(255) DEFAULT NULL, + "email_append_to" smallint NOT NULL DEFAULT 0, + "subject_field" varchar(255) DEFAULT NULL, + "sender_field" varchar(255) DEFAULT NULL, PRIMARY KEY ("name") ) ; From 91f023edbe1bd5e0e4b6711768a2ad9fdb71f440 Mon Sep 17 00:00:00 2001 From: Rohan Bansal Date: Mon, 2 Mar 2020 16:06:03 +0530 Subject: [PATCH 19/90] feat: include custom JS and CSS files in web form --- frappe/utils/boilerplate.py | 4 +++ frappe/website/doctype/web_form/web_form.py | 40 ++++++++++++++------- 2 files changed, 32 insertions(+), 12 deletions(-) diff --git a/frappe/utils/boilerplate.py b/frappe/utils/boilerplate.py index b81d802a07..e65fa44253 100755 --- a/frappe/utils/boilerplate.py +++ b/frappe/utils/boilerplate.py @@ -151,6 +151,10 @@ app_license = "{app_license}" # web_include_css = "/assets/{app_name}/css/{app_name}.css" # web_include_js = "/assets/{app_name}/js/{app_name}.js" +# include js, css files in header of web form +# webform_include_js = {"doctype": "public/js/doctype.js"} +# webform_include_css = {"doctype": "public/css/doctype.css"} + # include js in page # page_js = {{"page" : "public/js/file.js"}} diff --git a/frappe/website/doctype/web_form/web_form.py b/frappe/website/doctype/web_form/web_form.py index ae2c27c420..a188503ea3 100644 --- a/frappe/website/doctype/web_form/web_form.py +++ b/frappe/website/doctype/web_form/web_form.py @@ -2,18 +2,23 @@ # For license information, please see license.txt from __future__ import unicode_literals -import frappe, json, os -from frappe.website.website_generator import WebsiteGenerator + +import json +import os + +from six import iteritems +from six.moves.urllib.parse import urlencode + +import frappe from frappe import _, scrub +from frappe.core.doctype.file.file import get_max_file_size, remove_file_by_url +from frappe.custom.doctype.customize_form.customize_form import docfield_properties +from frappe.desk.form.meta import get_code_files_via_hooks +from frappe.integrations.utils import get_payment_gateway_controller +from frappe.modules.utils import export_module_json, get_doc_module from frappe.utils import cstr from frappe.website.utils import get_comment_list -from frappe.custom.doctype.customize_form.customize_form import docfield_properties -from frappe.core.doctype.file.file import get_max_file_size -from frappe.core.doctype.file.file import remove_file_by_url -from frappe.modules.utils import export_module_json, get_doc_module -from six.moves.urllib.parse import urlencode -from frappe.integrations.utils import get_payment_gateway_controller -from six import iteritems +from frappe.website.website_generator import WebsiteGenerator class WebForm(WebsiteGenerator): @@ -237,11 +242,23 @@ def get_context(context): js_path = os.path.join(os.path.dirname(self.web_form_module.__file__), scrub(self.name) + '.js') if os.path.exists(js_path): - context.script = frappe.render_template(open(js_path, 'r').read(), context) + script = frappe.render_template(open(js_path, 'r').read(), context) + + for path in get_code_files_via_hooks("webform_include_js", context.doc_type): + custom_js = frappe.render_template(open(path, 'r').read(), context) + script = "\n\n".join([script, custom_js]) + + context.script = script css_path = os.path.join(os.path.dirname(self.web_form_module.__file__), scrub(self.name) + '.css') if os.path.exists(css_path): - context.style = open(css_path, 'r').read() + style = open(css_path, 'r').read() + + for path in get_code_files_via_hooks("webform_include_css", context.doc_type): + custom_css = open(path, 'r').read() + style = "\n\n".join([style, custom_css]) + + context.style = style def get_layout(self): layout = [] @@ -589,4 +606,3 @@ def get_link_options(web_form_name, doctype, allow_read_on_all_link_options=Fals else: raise frappe.PermissionError('Not Allowed, {0}'.format(doctype)) - From 7e6a22ac72a64b90daa84992acb9b39c10dd3163 Mon Sep 17 00:00:00 2001 From: prssanna Date: Fri, 6 Mar 2020 21:54:17 +0530 Subject: [PATCH 20/90] feat: add button to go to list in customize form --- frappe/custom/doctype/customize_form/customize_form.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/frappe/custom/doctype/customize_form/customize_form.js b/frappe/custom/doctype/customize_form/customize_form.js index 63b094615a..5c9fa37ef5 100644 --- a/frappe/custom/doctype/customize_form/customize_form.js +++ b/frappe/custom/doctype/customize_form/customize_form.js @@ -85,6 +85,10 @@ frappe.ui.form.on("Customize Form", { if(frm.doc.doc_type) { frappe.customize_form.set_primary_action(frm); + frm.add_custom_button(__('Go to {0} List', [frm.doc.doc_type]), function() { + frappe.set_route('List', frm.doc.doc_type); + }); + frm.add_custom_button(__('Refresh Form'), function() { frm.script_manager.trigger("doc_type"); }, "fa fa-refresh", "btn-default"); From 1f82f051efb258eb8925ab23eea6eb66b05bc927 Mon Sep 17 00:00:00 2001 From: Himanshu Warekar Date: Fri, 13 Mar 2020 19:56:12 +0530 Subject: [PATCH 21/90] fix: mve email_append_to to a section --- frappe/custom/doctype/customize_form/customize_form.js | 10 ---------- .../custom/doctype/customize_form/customize_form.json | 9 ++++++--- frappe/email/doctype/email_account/email_account.py | 6 +++--- 3 files changed, 9 insertions(+), 16 deletions(-) diff --git a/frappe/custom/doctype/customize_form/customize_form.js b/frappe/custom/doctype/customize_form/customize_form.js index 858cf565be..444d9dc495 100644 --- a/frappe/custom/doctype/customize_form/customize_form.js +++ b/frappe/custom/doctype/customize_form/customize_form.js @@ -139,16 +139,6 @@ frappe.ui.form.on("Customize Form", { }, 1000); } - }, - - email_append_to: function(frm) { - frm.set_df_property("subject_field", "reqd", 0); - frm.set_df_property("sender_field", "reqd", 0); - - if (frm.doc.email_append_to) { - frm.set_df_property("subject_field", "reqd", 1); - frm.set_df_property("sender_field", "reqd", 1); - } } }); diff --git a/frappe/custom/doctype/customize_form/customize_form.json b/frappe/custom/doctype/customize_form/customize_form.json index f719add96c..bfc31d60e6 100644 --- a/frappe/custom/doctype/customize_form/customize_form.json +++ b/frappe/custom/doctype/customize_form/customize_form.json @@ -21,7 +21,6 @@ "allow_auto_repeat", "allow_import", "image_view", - "email_append_to", "column_break_5", "title_field", "image_field", @@ -31,6 +30,7 @@ "column_break_10", "sort_order", "section_break_23", + "email_append_to", "subject_field", "cb_01", "sender_field", @@ -182,14 +182,17 @@ "label": "Allow Import (via Data Import Tool)" }, { + "depends_on": "email_append_to", "fieldname": "subject_field", "fieldtype": "Data", "label": "Subject Field" }, { + "depends_on": "email_append_to", "fieldname": "sender_field", "fieldtype": "Data", - "label": "Sender Field" + "label": "Sender Field", + "mandatory_depends_on": "email_append_to" }, { "default": "0", @@ -212,7 +215,7 @@ "idx": 1, "issingle": 1, "links": [], - "modified": "2019-12-27 14:29:49.097980", + "modified": "2020-03-13 19:54:39.652134", "modified_by": "Administrator", "module": "Custom", "name": "Customize Form", diff --git a/frappe/email/doctype/email_account/email_account.py b/frappe/email/doctype/email_account/email_account.py index cddc5dd25d..c0a198f5e5 100755 --- a/frappe/email/doctype/email_account/email_account.py +++ b/frappe/email/doctype/email_account/email_account.py @@ -678,9 +678,9 @@ def get_append_to(doctype=None, txt=None, searchfield=None, start=None, page_len email_append_to_list = [] # Set Email Append To DocTypes via DocType - for dt in frappe.get_all("DocType", filters={"istable": 0, "issingle": 0}, fields=["name", "email_append_to"]): - if dt.get("email_append_to") and dt.email_append_to: - email_append_to_list.append(dt.name) + filters = {"istable": 0, "issingle": 0, "email_append_to": 1} + for dt in frappe.get_all("DocType", filters=filters, fields=["name", "email_append_to"]): + email_append_to_list.append(dt.name) # Set Email Append To DocTypes set via Customize Form for dt in frappe.get_list("Property Setter", filters={"property": "email_append_to", "value": 1}, fields=["doc_type"]): From 7b7d55860477225e85bfa315eede31980a831274 Mon Sep 17 00:00:00 2001 From: Gavin D'souza Date: Fri, 20 Mar 2020 18:10:54 +0530 Subject: [PATCH 22/90] feat: add validate_phone api to window to validate phone numbers --- frappe/public/js/frappe/utils/datatype.js | 4 ++++ frappe/public/js/frappe/utils/utils.js | 3 +++ 2 files changed, 7 insertions(+) diff --git a/frappe/public/js/frappe/utils/datatype.js b/frappe/public/js/frappe/utils/datatype.js index 0f73526e04..16f87b872f 100644 --- a/frappe/public/js/frappe/utils/datatype.js +++ b/frappe/public/js/frappe/utils/datatype.js @@ -44,6 +44,10 @@ window.validate_email = function(txt) { return frappe.utils.validate_type(txt, "email"); }; +window.validate_phone = function(txt) { + return frappe.utils.validate_type(txt, "phone"); +}; + window.nth = function(number) { number = cint(number); var s = 'th'; diff --git a/frappe/public/js/frappe/utils/utils.js b/frappe/public/js/frappe/utils/utils.js index 278c80897e..1af37c1f60 100644 --- a/frappe/public/js/frappe/utils/utils.js +++ b/frappe/public/js/frappe/utils/utils.js @@ -232,6 +232,9 @@ Object.assign(frappe.utils, { var regExp; switch ( type ) { + case "phone": + regExp = /^([0-9\ \+\_\-\,\.\*\#\(\)]){1,20}$/; + break; case "number": regExp = /^-?(?:\d+|\d{1,3}(?:,\d{3})+)?(?:\.\d+)?$/; break; From 64150d471721d4ef8ac40ad3b09bf722db5a880d Mon Sep 17 00:00:00 2001 From: prssanna Date: Fri, 20 Mar 2020 21:13:35 +0530 Subject: [PATCH 23/90] fix: fix dropdown caret spacing in list sidebar --- frappe/public/js/frappe/list/list_sidebar.html | 2 +- frappe/public/js/frappe/list/list_sidebar_group_by.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/frappe/public/js/frappe/list/list_sidebar.html b/frappe/public/js/frappe/list/list_sidebar.html index f8e868da20..90189ccdea 100644 --- a/frappe/public/js/frappe/list/list_sidebar.html +++ b/frappe/public/js/frappe/list/list_sidebar.html @@ -64,7 +64,7 @@