addchild will never save added doc

This commit is contained in:
Anand Doshi 2012-12-24 17:02:38 +05:30
parent dfbc02ed2a
commit e7bad04407
7 changed files with 17 additions and 19 deletions

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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