Explorar el Código

[fix] dont update modified timestamp if called from post save methods

version-14
Rushabh Mehta hace 9 años
padre
commit
7c870d6ba4
Se han modificado 8 ficheros con 18 adiciones y 16 borrados
  1. +1
    -1
      frappe/__init__.py
  2. +2
    -2
      frappe/core/doctype/communication/email.py
  3. +0
    -5
      frappe/desk/form/save.py
  4. +3
    -1
      frappe/model/base_document.py
  5. +5
    -0
      frappe/model/document.py
  6. +2
    -2
      frappe/model/meta.py
  7. +4
    -4
      frappe/tests/test_document.py
  8. +1
    -1
      frappe/utils/nestedset.py

+ 1
- 1
frappe/__init__.py Ver fichero

@@ -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,


+ 2
- 2
frappe/core/doctype/communication/email.py Ver fichero

@@ -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)


+ 0
- 5
frappe/desk/form/save.py Ver fichero

@@ -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'))


+ 3
- 1
frappe/model/base_document.py Ver fichero

@@ -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)



+ 5
- 0
frappe/model/document.py Ver fichero

@@ -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):


+ 2
- 2
frappe/model/meta.py Ver fichero

@@ -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))


+ 4
- 4
frappe/tests/test_document.py Ver fichero

@@ -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('<', '&lt;').replace('>', '&gt;')
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 = '<div>Test</div>'
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)
@@ -184,7 +184,7 @@ class TestDocument(unittest.TestCase):
escaped_xss = '<div style="color: red;">Test</div>'
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)


+ 1
- 1
frappe/utils/nestedset.py Ver fichero

@@ -44,7 +44,7 @@ def update_nsm(doc):
doc.set(opf, p)
frappe.db.set_value(doc.doctype, doc.name, opf, p or '')

doc.load_from_db()
doc.reload()

def update_add_node(doc, parent, parent_field):
"""


Cargando…
Cancelar
Guardar