allow for cloning other children

This commit is contained in:
pratu16x7 2017-06-27 14:01:58 +05:30
parent f04502632c
commit e112c71b86

View file

@ -248,7 +248,16 @@ _f.Frm.prototype.clear_table = function(fieldname) {
_f.Frm.prototype.add_child = function(fieldname, values) {
var doc = frappe.model.add_child(this.doc, frappe.meta.get_docfield(this.doctype, fieldname).options, fieldname);
if(values) {
$.extend(doc, values);
// Deep clone
var d = JSON.parse(JSON.stringify(values));
// Values of unique keys should not be overridden
var unique_keys = ["idx", "name"];
unique_keys.map((key) => {
d[key] && delete d[key];
});
$.extend(doc, d);
}
return doc;
}