diff --git a/core/doctype/customize_form/customize_form.py b/core/doctype/customize_form/customize_form.py index 1a6daead69..32d251ed75 100644 --- a/core/doctype/customize_form/customize_form.py +++ b/core/doctype/customize_form/customize_form.py @@ -78,7 +78,8 @@ class DocType: for d in self.get_ref_doclist(): if d.doctype=='DocField': - new = addchild(self.doc, 'fields', 'Customize Form Field', 1, self.doclist) + new = addchild(self.doc, 'fields', 'Customize Form Field', + self.doclist) self.set( { 'list': self.docfield_properties, diff --git a/core/doctype/doctype/doctype.py b/core/doctype/doctype/doctype.py index 9626698e3f..9e7629f544 100644 --- a/core/doctype/doctype/doctype.py +++ b/core/doctype/doctype/doctype.py @@ -126,7 +126,7 @@ class DocType: temp_doclist = webnotes.model.doctype.get(self.doc.name) if 'file_list' not in [d.fieldname for d in temp_doclist if \ d.doctype=='DocField']: - new = self.doc.addchild('fields', 'DocField', 1, self.doclist) + new = self.doc.addchild('fields', 'DocField', self.doclist) new.label = 'File List' new.fieldtype = 'Text' new.fieldname = 'file_list' @@ -151,7 +151,7 @@ class DocType: max_idx = max_idx and max_idx or 0 if 'amended_from' not in [d.fieldname for d in temp_doclist if \ d.doctype=='DocField']: - new = self.doc.addchild('fields', 'DocField', 1, self.doclist) + new = self.doc.addchild('fields', 'DocField', self.doclist) new.label = 'Amended From' new.fieldtype = 'Link' new.fieldname = 'amended_from' diff --git a/core/doctype/doctype_mapper/doctype_mapper.py b/core/doctype/doctype_mapper/doctype_mapper.py index ba716e3c66..6d56ab47d6 100644 --- a/core/doctype/doctype_mapper/doctype_mapper.py +++ b/core/doctype/doctype_mapper/doctype_mapper.py @@ -97,7 +97,7 @@ class DocType: # Add a row in target table in 'To DocType' and returns obj if t['to_table'] != self.doc.to_doctype: - to_doc_obj = addchild(to_doc, t['to_field'], t['to_table'], 1, doclist) + to_doc_obj = addchild(to_doc, t['to_field'], t['to_table'], doclist) else: to_doc_obj = to_doc diff --git a/webnotes/model/__init__.py b/webnotes/model/__init__.py index 46ad008f30..c854b788bd 100644 --- a/webnotes/model/__init__.py +++ b/webnotes/model/__init__.py @@ -180,7 +180,7 @@ def copytables(srctype, src, srcfield, tartype, tar, tarfield, srcfields, tarfie l = [] data = webnotes.model.doc.getchildren(src.name, srctype, srcfield) for d in data: - newrow = webnotes.model.doc.addchild(tar, tarfield, tartype, local = 1) + newrow = webnotes.model.doc.addchild(tar, tarfield, tartype) newrow.idx = d.idx for i in range(len(srcfields)): diff --git a/webnotes/model/doc.py b/webnotes/model/doc.py index 1799877f52..89c08f49cd 100755 --- a/webnotes/model/doc.py +++ b/webnotes/model/doc.py @@ -449,6 +449,9 @@ class Document: make_autoname, keep_timestamps = keep_timestamps) if r: return r + + elif not webnotes.conn.exists(self.doctype, self.name): + webnotes.msgprint("""This document was updated before your change. Please refresh before saving.""", raise_exception=1) # save the values self._update_values(res.get('issingle'), @@ -575,7 +578,7 @@ class Document: return webnotes.doclist(doclist) - def addchild(self, fieldname, childtype = '', local=0, doclist=None): + def addchild(self, fieldname, childtype = '', doclist=None): """ Returns a child record of the give `childtype`. @@ -590,12 +593,8 @@ class Document: d.docstatus = 0; d.name = '' d.owner = webnotes.session['user'] + d.fields['__islocal'] = 1 # for Client to identify unsaved doc - if local: - d.fields['__islocal'] = 1 # for Client to identify unsaved doc - else: - d.save(new=1) - if doclist != None: doclist.append(d) @@ -612,7 +611,7 @@ class Document: return ret -def addchild(parent, fieldname, childtype = '', local=0, doclist=None): +def addchild(parent, fieldname, childtype = '', doclist=None): """ Create a child record to the parent doc. @@ -620,11 +619,11 @@ def addchild(parent, fieldname, childtype = '', local=0, doclist=None): Example:: c = Document('Contact','ABC') - d = addchild(c, 'contact_updates', 'Contact Update', local = 1) + d = addchild(c, 'contact_updates', 'Contact Update') d.last_updated = 'Phone call' d.save(1) """ - return parent.addchild(fieldname, childtype, local, doclist) + return parent.addchild(fieldname, childtype, doclist) # Naming # ------ diff --git a/webnotes/model/utils.py b/webnotes/model/utils.py index 10e2903346..80989db798 100644 --- a/webnotes/model/utils.py +++ b/webnotes/model/utils.py @@ -196,7 +196,7 @@ def to_html(doclist): return out -def round_doc(doc, precision_map): +def round_floats_in_doc(doc, precision_map): from webnotes.utils import flt for fieldname, precision in precision_map.items(): doc.fields[fieldname] = flt(doc.fields.get(fieldname), precision) diff --git a/webnotes/model/wrapper.py b/webnotes/model/wrapper.py index e59aca19f5..b9f1f74d93 100644 --- a/webnotes/model/wrapper.py +++ b/webnotes/model/wrapper.py @@ -86,7 +86,7 @@ class ModelWrapper: docs[i] = Document(fielddata=d) self.docs = self.doclist = webnotes.doclist(docs) - self.doc, self.children = docs[0], webnotes.doclist(docs[1:]) + self.doc, self.children = self.doclist[0], self.doclist[1:] if self.obj: self.obj.doclist = self.doclist self.obj.doc = self.doc @@ -225,9 +225,7 @@ class ModelWrapper: """ child_map = {} for d in self.children: - if (d.fields.has_key('parent') and d.fields.get('parent')) or \ - (d.fields.has_key("parentfield") and d.fields.get("parentfield")): - # if d.parent: + if d.fields.get("parent") or d.fields.get("parentfield"): d.parent = self.doc.name # rename if reqd d.parenttype = self.doc.doctype