@@ -2,7 +2,7 @@ | |||||
{ | { | ||||
"creation": "2013-02-14 17:37:36", | "creation": "2013-02-14 17:37:36", | ||||
"docstatus": 0, | "docstatus": 0, | ||||
"modified": "2013-02-26 10:45:10", | |||||
"modified": "2013-03-01 10:18:03", | |||||
"modified_by": "Administrator", | "modified_by": "Administrator", | ||||
"owner": "Administrator" | "owner": "Administrator" | ||||
}, | }, | ||||
@@ -131,7 +131,7 @@ | |||||
"fieldname": "language", | "fieldname": "language", | ||||
"fieldtype": "Select", | "fieldtype": "Select", | ||||
"label": "Language", | "label": "Language", | ||||
"options": "\n\u0627\u0644\u0639\u0631\u0628\u064a\u0629\nenglish\nespa\u00f1ol\nfran\u00e7ais\n\u0939\u093f\u0902\u0926\u0940\nHrvatski\nnederlands\nportugu\u00eas\nportugu\u00eas brasileiro\n\u0441\u0440\u043f\u0441\u043a\u0438\n\u0ba4\u0bae\u0bbf\u0bb4\u0bcd\n\u0e44\u0e17\u0e22" | |||||
"options": "\n\u0627\u0644\u0639\u0631\u0628\u064a\u0629\nDeutsch\nenglish\nespa\u00f1ol\nfran\u00e7ais\n\u0939\u093f\u0902\u0926\u0940\nHrvatski\nnederlands\nportugu\u00eas\nportugu\u00eas brasileiro\n\u0441\u0440\u043f\u0441\u043a\u0438\n\u0ba4\u0bae\u0bbf\u0bb4\u0bcd\n\u0e44\u0e17\u0e22" | |||||
}, | }, | ||||
{ | { | ||||
"doctype": "DocField", | "doctype": "DocField", | ||||
@@ -652,6 +652,10 @@ _f.Frm.prototype.cleanup_refresh = function() { | |||||
var fn = me.meta.autoname.substr(6); | var fn = me.meta.autoname.substr(6); | ||||
cur_frm.toggle_display(fn, false); | cur_frm.toggle_display(fn, false); | ||||
} | } | ||||
if(me.meta.autoname=="naming_series:" && !me.doc.__islocal) { | |||||
cur_frm.toggle_display("naming_series", false); | |||||
} | |||||
} | } | ||||
// Resolve "depends_on" and show / hide accordingly | // Resolve "depends_on" and show / hide accordingly | ||||
@@ -64,6 +64,18 @@ $.extend(wn.meta, { | |||||
} | } | ||||
}, | }, | ||||
has_field: function(dt, fn) { | |||||
return wn.meta.docfield_map[dt][fn]; | |||||
}, | |||||
get_parentfield: function(parent_dt, child_dt) { | |||||
var df = wn.model.get("DocField", {parent:parent_dt, fieldtype:"Table", | |||||
options:child_dt}) | |||||
if(!df.length) | |||||
throw "parentfield not found for " + parent_dt + ", " + child_dt; | |||||
return df[0].fieldname; | |||||
}, | |||||
get_label: function(dt, fn, dn) { | get_label: function(dt, fn, dn) { | ||||
if(fn==="owner") { | if(fn==="owner") { | ||||
return "Owner"; | return "Owner"; | ||||
@@ -21,6 +21,7 @@ | |||||
// | // | ||||
wn.provide('wn.model'); | wn.provide('wn.model'); | ||||
wn.provide("wn.model.map_info"); | |||||
$.extend(wn.model, { | $.extend(wn.model, { | ||||
no_value_type: ['Section Break', 'Column Break', 'HTML', 'Table', | no_value_type: ['Section Break', 'Column Break', 'HTML', 'Table', | ||||
@@ -75,6 +76,9 @@ $.extend(wn.model, { | |||||
if(meta.__calendar_js) { | if(meta.__calendar_js) { | ||||
eval(meta.__calendar_js); | eval(meta.__calendar_js); | ||||
} | } | ||||
if(meta.__map_js) { | |||||
eval(meta.__map_js); | |||||
} | |||||
callback(r); | callback(r); | ||||
} | } | ||||
}); | }); | ||||
@@ -228,23 +232,90 @@ $.extend(wn.model, { | |||||
delete locals[doctype][name]; | delete locals[doctype][name]; | ||||
}, | }, | ||||
copy_doc: function(dt, dn, from_amend) { | |||||
get_no_copy_list: function(doctype) { | |||||
var no_copy_list = ['name','amended_from','amendment_date','cancel_reason']; | var no_copy_list = ['name','amended_from','amendment_date','cancel_reason']; | ||||
$.each(wn.model.get("DocField", {parent:doctype}), function(i, df) { | |||||
if(cint(df.no_copy)) no_copy_list.push(df.fieldname); | |||||
}) | |||||
return no_copy_list; | |||||
}, | |||||
copy_doc: function(dt, dn, from_amend) { | |||||
var no_copy_list = wn.model.get_no_copy_list(dt); | |||||
var newdoc = wn.model.get_new_doc(dt); | var newdoc = wn.model.get_new_doc(dt); | ||||
for(var key in locals[dt][dn]) { | for(var key in locals[dt][dn]) { | ||||
// dont copy name and blank fields | |||||
var df = wn.meta.get_docfield(dt, key); | |||||
// dont copy name and blank fields | |||||
if(key.substr(0,2)!='__' | if(key.substr(0,2)!='__' | ||||
&& !in_list(no_copy_list, key) | |||||
&& !(df && (!from_amend && cint(df.no_copy)==1))) { | |||||
&& !in_list(no_copy_list, key)) { | |||||
newdoc[key] = locals[dt][dn][key]; | newdoc[key] = locals[dt][dn][key]; | ||||
} | } | ||||
} | } | ||||
return newdoc; | return newdoc; | ||||
}, | }, | ||||
// args: source (doclist), target (doctype), table_map, field_map, callback | |||||
map: function(args) { | |||||
wn.model.with_doctype(args.target, function() { | |||||
var map_info = wn.model.map_info[args.target] | |||||
if(map_info) | |||||
map_info = map_info[args.source[0].doctype]; | |||||
if(!map_info) { | |||||
map_info = { | |||||
table_map: {}, | |||||
field_map: {} | |||||
} | |||||
} | |||||
// main | |||||
var target = wn.model.map_doc(args.source[0], args.target, map_info.field_map[args.target]); | |||||
// children | |||||
$.each(map_info.table_map, function(child_target, child_source) { | |||||
$.each($.map(args.source, function(d) | |||||
{ if(d.doctype==child_source) return d; else return null; }), function(i, d) { | |||||
var child = wn.model.map_doc(d, child_target, map_info.field_map[child_target]); | |||||
$.extend(child, { | |||||
parent: target.name, | |||||
parenttype: target.doctype, | |||||
parentfield: wn.meta.get_parentfield(target.doctype, child.doctype), | |||||
idx: i+1 | |||||
}); | |||||
}); | |||||
}); | |||||
if(args.callback) { | |||||
args.callback(target); | |||||
} else { | |||||
wn.set_route("Form", target.doctype, target.name); | |||||
} | |||||
}); | |||||
}, | |||||
// map a single doc to a new doc of given DocType and field_map | |||||
map_doc: function(source, doctype, field_map) { | |||||
var new_doc = wn.model.get_new_doc(doctype); | |||||
var no_copy_list = wn.model.get_no_copy_list(doctype); | |||||
if(!field_map) field_map = {}; | |||||
delete no_copy_list[no_copy_list.indexOf("name")]; | |||||
for(fieldname in wn.meta.docfield_map[doctype]) { | |||||
var df = wn.meta.docfield_map[doctype][fieldname]; | |||||
if(!df.no_copy) { | |||||
var source_key = field_map[df.fieldname] || df.fieldname; | |||||
if(source_key.substr(0,1)=="=") { | |||||
var value = source_key.substr(1); | |||||
} else { | |||||
var value = source[source_key]; | |||||
} | |||||
if(value!==undefined) { | |||||
new_doc[df.fieldname] = value; | |||||
} | |||||
} | |||||
} | |||||
return new_doc; | |||||
}, | |||||
delete_doc: function(doctype, docname, callback) { | delete_doc: function(doctype, docname, callback) { | ||||
wn.confirm("Permanently delete "+ docname + "?", function() { | wn.confirm("Permanently delete "+ docname + "?", function() { | ||||
wn.call({ | wn.call({ | ||||
@@ -57,7 +57,8 @@ wn.views.ListView = Class.extend({ | |||||
// additional fields | // additional fields | ||||
if(this.settings.add_fields) { | if(this.settings.add_fields) { | ||||
$.each(this.settings.add_fields, function(i, d) { | $.each(this.settings.add_fields, function(i, d) { | ||||
me.fields.push(d); | |||||
if(me.fields.indexOf(d)==-1) | |||||
me.fields.push(d); | |||||
}); | }); | ||||
} | } | ||||
}, | }, | ||||
@@ -369,7 +369,7 @@ wn.views.ReportView = wn.ui.Listing.extend({ | |||||
sort_by: me.sort_by_select.val(), | sort_by: me.sort_by_select.val(), | ||||
sort_order: me.sort_order_select.val(), | sort_order: me.sort_order_select.val(), | ||||
sort_by_next: me.sort_by_next_select.val(), | sort_by_next: me.sort_by_next_select.val(), | ||||
sort_order_next: me.sort_order_next_select.val() | |||||
sort_order_next: me.sort_order_next_select.val() | |||||
}) | }) | ||||
}, | }, | ||||
callback: function(r) { | callback: function(r) { | ||||
@@ -286,7 +286,7 @@ def generate_hash(): | |||||
import hashlib, time | import hashlib, time | ||||
return hashlib.sha224(str(time.time())).hexdigest() | return hashlib.sha224(str(time.time())).hexdigest() | ||||
def get_obj(dt = None, dn = None, doc=None, doclist=[], with_children = 0): | |||||
def get_obj(dt = None, dn = None, doc=None, doclist=[], with_children = True): | |||||
from webnotes.model.code import get_obj | from webnotes.model.code import get_obj | ||||
return get_obj(dt, dn, doc, doclist, with_children) | return get_obj(dt, dn, doc, doclist, with_children) | ||||
@@ -33,10 +33,13 @@ def get(doctype, name=None, filters=None): | |||||
return [d.fields for d in webnotes.bean(doctype, name).doclist] | return [d.fields for d in webnotes.bean(doctype, name).doclist] | ||||
@webnotes.whitelist() | @webnotes.whitelist() | ||||
def get_value(doctype, fieldname, filters=None): | |||||
def get_value(doctype, fieldname, filters=None, as_dict=True): | |||||
if not webnotes.has_permission(doctype): | |||||
webnotes.msgprint("No Permission", raise_exception=True) | |||||
if fieldname and fieldname.startswith("["): | if fieldname and fieldname.startswith("["): | ||||
fieldname = json.loads(fieldname) | fieldname = json.loads(fieldname) | ||||
return webnotes.conn.get_value(doctype, json.loads(filters), fieldname) | |||||
return webnotes.conn.get_value(doctype, json.loads(filters), fieldname, as_dict=as_dict) | |||||
@webnotes.whitelist() | @webnotes.whitelist() | ||||
def insert(doclist): | def insert(doclist): | ||||
@@ -278,6 +278,7 @@ class Bean: | |||||
webnotes.msgprint("Only submitted can be cancelled", raise_exception=1) | webnotes.msgprint("Only submitted can be cancelled", raise_exception=1) | ||||
self.to_docstatus = 2 | self.to_docstatus = 2 | ||||
self.prepare_for_save(1) | self.prepare_for_save(1) | ||||
self.run_method('before_cancel') | |||||
self.save_main() | self.save_main() | ||||
self.save_children() | self.save_children() | ||||
self.run_method('on_cancel') | self.run_method('on_cancel') | ||||
@@ -292,6 +293,7 @@ class Bean: | |||||
if self.ignore_permissions or webnotes.has_permission(self.doc.doctype, "write", self.doc): | if self.ignore_permissions or webnotes.has_permission(self.doc.doctype, "write", self.doc): | ||||
self.to_docstatus = 1 | self.to_docstatus = 1 | ||||
self.prepare_for_save(1) | self.prepare_for_save(1) | ||||
self.run_method('before_update_after_submit') | |||||
self.save_main() | self.save_main() | ||||
self.save_children() | self.save_children() | ||||
self.run_method('on_update_after_submit') | self.run_method('on_update_after_submit') | ||||
@@ -276,6 +276,7 @@ def add_code(doctype, doclist): | |||||
_add_code(scrub(doc.name) + '.css', '__css') | _add_code(scrub(doc.name) + '.css', '__css') | ||||
_add_code('%s_list.js' % scrub(doc.name), '__list_js') | _add_code('%s_list.js' % scrub(doc.name), '__list_js') | ||||
_add_code('%s_calendar.js' % scrub(doc.name), '__calendar_js') | _add_code('%s_calendar.js' % scrub(doc.name), '__calendar_js') | ||||
_add_code('%s_map.js' % scrub(doc.name), '__map_js') | |||||
add_embedded_js(doc) | add_embedded_js(doc) | ||||
def add_embedded_js(doc): | def add_embedded_js(doc): | ||||
@@ -182,9 +182,15 @@ def add_years(date, years): | |||||
def date_diff(string_ed_date, string_st_date): | def date_diff(string_ed_date, string_st_date): | ||||
return (getdate(string_ed_date) - getdate(string_st_date)).days | return (getdate(string_ed_date) - getdate(string_st_date)).days | ||||
def time_diff(string_ed_date, string_st_date): | |||||
return get_datetime(string_ed_date) - get_datetime(string_st_date) | |||||
def time_diff_in_seconds(string_ed_date, string_st_date): | def time_diff_in_seconds(string_ed_date, string_st_date): | ||||
return (get_datetime(string_ed_date) - get_datetime(string_st_date)).seconds | |||||
return time_diff(string_ed_date, string_st_date).seconds | |||||
def time_diff_in_hours(string_ed_date, string_st_date): | |||||
return round(float(time_diff(string_ed_date, string_st_date).seconds) / 3600, 6) | |||||
def now_datetime(): | def now_datetime(): | ||||
from datetime import datetime | from datetime import datetime | ||||
@@ -255,7 +255,8 @@ def save_report(): | |||||
d = Document('Report') | d = Document('Report') | ||||
d.report_name = data['name'] | d.report_name = data['name'] | ||||
d.ref_doctype = data['doctype'] | d.ref_doctype = data['doctype'] | ||||
d.report_type = "Report Builder" | |||||
d.json = data['json'] | d.json = data['json'] | ||||
webnotes.bean([d]).save() | webnotes.bean([d]).save() | ||||
webnotes.msgprint("%s saved." % d.name) | webnotes.msgprint("%s saved." % d.name) | ||||