diff --git a/frappe/__init__.py b/frappe/__init__.py index bda3944b69..14d9e7f7c5 100644 --- a/frappe/__init__.py +++ b/frappe/__init__.py @@ -95,7 +95,7 @@ def init(site, sites_path=None, new_site=False): local.realtime_log = [] local.flags = _dict({ "ran_schedulers": [], - "currenty_saving": _dict(), + "currently_saving": [], "redirect_location": "", "in_install_db": False, "in_install_app": False, diff --git a/frappe/core/doctype/communication/email.py b/frappe/core/doctype/communication/email.py index 9dc48edf41..aaf1e72dd6 100755 --- a/frappe/core/doctype/communication/email.py +++ b/frappe/core/doctype/communication/email.py @@ -148,10 +148,10 @@ def update_parent_status(doc): status_field = parent.meta.get_field("status") - if status_field and "Open" in (status_field.options or "").split("\n"): + if status_field: to_status = "Open" if doc.sent_or_received=="Received" else "Replied" - if to_status in status_field.options.splitlines(): + if to_status in (status_field.options or '').splitlines(): parent.db_set("status", to_status) update_mins_to_first_communication(parent, doc) diff --git a/frappe/desk/form/save.py b/frappe/desk/form/save.py index f5c542d1dd..945960e62b 100644 --- a/frappe/desk/form/save.py +++ b/frappe/desk/form/save.py @@ -12,8 +12,6 @@ def savedocs(doc, action): doc = frappe.get_doc(json.loads(doc)) set_local_name(doc) - frappe.local.flags.currently_saving = frappe._dict(doctype=doc.doctype, name=doc.name) - # action doc.docstatus = {"Save":0, "Submit": 1, "Update": 1, "Cancel": 2}[action] @@ -31,9 +29,6 @@ def savedocs(doc, action): run_onload(doc) frappe.get_user().update_recent(doc.doctype, doc.name) send_updated_docs(doc) - - frappe.local.flags.currently_saving = None - except Exception: if not frappe.local.message_log: frappe.msgprint(frappe._('Did not save')) diff --git a/frappe/model/base_document.py b/frappe/model/base_document.py index 1a4eef9295..382e03fcc8 100644 --- a/frappe/model/base_document.py +++ b/frappe/model/base_document.py @@ -350,7 +350,9 @@ class BaseDocument(object): def db_set(self, fieldname, value, update_modified=True): self.set(fieldname, value) - if update_modified: + if update_modified and (self.doctype, self.name) not in frappe.flags.currently_saving: + # don't update modified timestamp if called from post save methods + # like on_update or on_submit self.set("modified", now()) self.set("modified_by", frappe.session.user) diff --git a/frappe/model/document.py b/frappe/model/document.py index 371255b7a2..7233b8623e 100644 --- a/frappe/model/document.py +++ b/frappe/model/document.py @@ -374,6 +374,8 @@ class Document(BaseDocument): if not d.creation: d.creation = self.creation + frappe.flags.currently_saving.append((self.doctype, self.name)) + def set_docstatus(self): if self.docstatus==None: self.docstatus=0 @@ -720,6 +722,9 @@ class Document(BaseDocument): self.clear_cache() self.notify_update() + if (self.doctype, self.name) in frappe.flags.currently_saving: + frappe.flags.currently_saving.remove((self.doctype, self.name)) + self.latest = None def clear_cache(self): diff --git a/frappe/model/meta.py b/frappe/model/meta.py index aeb61f9c2b..bde0785dd0 100644 --- a/frappe/model/meta.py +++ b/frappe/model/meta.py @@ -61,9 +61,9 @@ class Meta(Document): super(Meta, self).__init__("DocType", doctype) self.process() - def load_from_db(self): + def reload(self): try: - super(Meta, self).load_from_db() + super(Meta, self).reload() except frappe.DoesNotExistError: if self.doctype=="DocType" and self.name in self.special_doctypes: self.__dict__.update(load_doctype_from_file(self.name)) diff --git a/frappe/tests/test_document.py b/frappe/tests/test_document.py index a3d82254cb..37cf0a3110 100644 --- a/frappe/tests/test_document.py +++ b/frappe/tests/test_document.py @@ -147,7 +147,7 @@ class TestDocument(unittest.TestCase): d.meta.get_field("starts_on").allow_on_submit = 0 # when comparing date(2014, 1, 1) and "2014-01-01" - d.load_from_db() + d.reload() d.starts_on = "2014-01-01" d.validate_update_after_submit() @@ -164,7 +164,7 @@ class TestDocument(unittest.TestCase): escaped_xss = xss.replace('<', '<').replace('>', '>') d.subject += xss d.save() - d.load_from_db() + d.reload() self.assertTrue(xss not in d.subject) self.assertTrue(escaped_xss in d.subject) @@ -174,7 +174,7 @@ class TestDocument(unittest.TestCase): escaped_xss = '