diff --git a/core/doctype/doctype/doctype.txt b/core/doctype/doctype/doctype.txt
index 37391b363e..c886ffb918 100644
--- a/core/doctype/doctype/doctype.txt
+++ b/core/doctype/doctype/doctype.txt
@@ -1,8 +1,8 @@
[
{
- "creation": "2013-01-15 17:23:52",
+ "creation": "2013-02-18 13:36:19",
"docstatus": 0,
- "modified": "2013-01-22 14:56:00",
+ "modified": "2013-02-18 17:19:42",
"modified_by": "Administrator",
"owner": "Administrator"
},
@@ -161,6 +161,13 @@
"reqd": 0,
"search_index": 0
},
+ {
+ "description": "Allow Import via Data Import Tool",
+ "doctype": "DocField",
+ "fieldname": "allow_import",
+ "fieldtype": "Check",
+ "label": "Allow Import"
+ },
{
"doctype": "DocField",
"fieldname": "cb11",
diff --git a/core/page/data_import_tool/data_import_tool.js b/core/page/data_import_tool/data_import_tool.js
index a8d4ecab27..580fbaaa1f 100644
--- a/core/page/data_import_tool/data_import_tool.js
+++ b/core/page/data_import_tool/data_import_tool.js
@@ -141,15 +141,23 @@ wn.pages['data-import-tool'].onload = function(wrapper) {
});
// add overwrite option
+ var $submit_btn = $('#dit-upload-area form input[type="submit"]');
$(' \
Overwrite \
If you are uploading a child table (for example Item Price), the all the entries of that table will be deleted (for that parent record) and new entries will be made.
')
- .insertBefore('#dit-upload-area form input[type="submit"]')
+ .insertBefore($submit_btn);
+
+ // add submit option
+ $(' \
+ Submit \
+ If you are inserting new records (overwrite not checked) \
+ and if you have submit permission, the record will be submitted.
')
+ .insertBefore($submit_btn);
// add ignore option
$(' \
Ignore Encoding Errors ')
- .insertBefore('#dit-upload-area form input[type="submit"]')
+ .insertBefore($submit_btn);
// rename button
$('#dit-upload-area form input[type="submit"]')
diff --git a/core/page/data_import_tool/data_import_tool.py b/core/page/data_import_tool/data_import_tool.py
index 1b985d388b..6dd285cdac 100644
--- a/core/page/data_import_tool/data_import_tool.py
+++ b/core/page/data_import_tool/data_import_tool.py
@@ -19,7 +19,7 @@ doctype_dl = None
@webnotes.whitelist()
def get_doctypes():
return [r[0] for r in webnotes.conn.sql("""select name from `tabDocType`
- where document_type = 'Master'""")]
+ where document_type = 'Master' or allow_import = 1""")]
@webnotes.whitelist()
def get_doctype_options():
@@ -137,6 +137,9 @@ def getdocfield(fieldname):
def upload():
"""upload data"""
global doctype_dl
+
+ webnotes.mute_emails = True
+
from webnotes.utils.datautils import read_csv_content_from_uploaded_file
def bad_template():
@@ -223,6 +226,8 @@ def upload():
webnotes.conn.rollback()
else:
webnotes.conn.commit()
+
+ webnotes.mute_emails = False
return {"messages": ret, "error": error}
@@ -298,5 +303,9 @@ def import_doc(d, doctype, overwrite, row_idx):
d['__islocal'] = 1
dl = Bean([webnotes.model.doc.Document(fielddata = d)])
dl.save()
+
+ if webnotes.form_dict.get("_submit")=="on":
+ dl.submit()
+
return 'Inserted row (#%d) %s' % (row_idx, getlink(doctype,
dl.doc.fields['name']))
diff --git a/core/page/permission_manager/permission_manager.py b/core/page/permission_manager/permission_manager.py
index 74c8f32055..236a9cd84b 100644
--- a/core/page/permission_manager/permission_manager.py
+++ b/core/page/permission_manager/permission_manager.py
@@ -9,7 +9,7 @@ def get_roles_and_doctypes():
ifnull(issingle,0)=0 and
name not in ('DocType')""")],
"roles": [d[0] for d in webnotes.conn.sql("""select name from tabRole where name not in
- ('All', 'Guest', 'Administrator')""")]
+ ('Guest', 'Administrator')""")]
}
@webnotes.whitelist(allow_roles=["System Manager", "Administrator"])
diff --git a/public/js/legacy/utils/datetime.js b/public/js/legacy/utils/datetime.js
index 675bbb6bdb..14bfa5ca05 100644
--- a/public/js/legacy/utils/datetime.js
+++ b/public/js/legacy/utils/datetime.js
@@ -165,7 +165,7 @@ wn.datetime = {
+ d.getHours() + ':' + d.getMinutes() + ':' + d.getSeconds();
},
- user_to_str: function(d) {
+ user_to_str: function(d, no_time_str) {
var user_fmt = this.get_user_fmt();
var time_str = '';
@@ -193,6 +193,9 @@ wn.datetime = {
var d = d.split('-');
var val = d[2]+'-'+d[0]+'-'+d[1];
}
+
+ if(no_time_str)time_str = '';
+
return val + time_str;
},
diff --git a/public/js/wn/misc/datetime.js b/public/js/wn/misc/datetime.js
index 36378928cb..cc388f2cb5 100644
--- a/public/js/wn/misc/datetime.js
+++ b/public/js/wn/misc/datetime.js
@@ -40,6 +40,7 @@ $.extend(wn.datetime, {
return [double_digit(d.getHours()), double_digit(d.getMinutes()), double_digit(d.getSeconds())].join(":")
},
get_datetime_as_string: function(d) {
+ if(!d) return null;
return [d.getFullYear(), double_digit(d.getMonth()+1), double_digit(d.getDate())].join("-") + " "
+ [double_digit(d.getHours()), double_digit(d.getMinutes()), double_digit(d.getSeconds())].join(":");
}
diff --git a/public/js/wn/model/meta.js b/public/js/wn/model/meta.js
index 889bfb6a31..a7760d3f88 100644
--- a/public/js/wn/model/meta.js
+++ b/public/js/wn/model/meta.js
@@ -65,7 +65,11 @@ $.extend(wn.meta, {
},
get_label: function(dt, fn, dn) {
- return this.get_docfield(dt, fn, dn).label || fn;
+ if(fn==="owner") {
+ return "Owner";
+ } else {
+ return this.get_docfield(dt, fn, dn).label || fn;
+ }
},
get_print_formats: function(doctype) {
diff --git a/public/js/wn/views/calendar.js b/public/js/wn/views/calendar.js
index 262bce7212..f746af0b55 100644
--- a/public/js/wn/views/calendar.js
+++ b/public/js/wn/views/calendar.js
@@ -115,14 +115,16 @@ wn.views.Calendar = Class.extend({
},
eventClick: function(event, jsEvent, view) {
// edit event description or delete
- if(wn.model.can_read(me.doctype))
- wn.set_route("Form", me.doctype, event.name);
+ var doctype = event.doctype || me.doctype;
+ if(wn.model.can_read(doctype)) {
+ wn.set_route("Form", doctype, event.name);
+ }
},
eventDrop: function(event, dayDelta, minuteDelta, allDay, revertFunc) {
- me.update_event(event);
+ me.update_event(event, revertFunc);
},
eventResize: function(event, dayDelta, minuteDelta, allDay, revertFunc) {
- me.update_event(event);
+ me.update_event(event, revertFunc);
},
select: function(startDate, endDate, allDay, jsEvent, view) {
if(jsEvent.day_clicked && view.name=="month")
@@ -160,15 +162,20 @@ wn.views.Calendar = Class.extend({
var me = this;
$.each(events, function(i, d) {
d.id = d.name;
- d.editable = wn.model.can_write(d.doctype || this.doctype);
+ d.editable = wn.model.can_write(d.doctype || me.doctype);
+ // do not allow submitted/cancelled events to be moved / extended
+ if(d.docstatus && d.docstatus > 0) {
+ d.editable = false;
+ }
+
$.each(me.field_map, function(target, source) {
d[target] = d[source];
});
if(!me.field_map.allDay)
d.allDay = 1;
-
+
if(d.status) {
if(me.style_map) {
$.extend(d, me.styles[me.style_map[d.status]] || {});
@@ -180,7 +187,7 @@ wn.views.Calendar = Class.extend({
}
})
},
- update_event: function(event) {
+ update_event: function(event, revertFunc) {
var me = this;
wn.model.remove_from_locals(me.doctype, event.name);
wn.call({
@@ -189,6 +196,7 @@ wn.views.Calendar = Class.extend({
callback: function(r) {
if(r.exc) {
show_alert("Unable to update event.")
+ revertFunc();
}
}
});
diff --git a/webnotes/model/bean.py b/webnotes/model/bean.py
index 6be84dc4e3..9fd67c818d 100644
--- a/webnotes/model/bean.py
+++ b/webnotes/model/bean.py
@@ -247,6 +247,9 @@ class Bean:
def save(self, check_links=1):
if self.ignore_permissions or webnotes.has_permission(self.doc.doctype, "write", self.doc):
+ if self.doc.docstatus == 1:
+ self.no_permission_to("Save submitted document")
+
self.prepare_for_save(check_links)
self.run_method('validate')
self.save_main()
diff --git a/webnotes/model/doc.py b/webnotes/model/doc.py
index 8504db1143..531be43105 100755
--- a/webnotes/model/doc.py
+++ b/webnotes/model/doc.py
@@ -660,4 +660,15 @@ def get(dt, dn='', with_children = 1, from_controller = 0, prefix = 'tab'):
def getsingle(doctype):
"""get single doc as dict"""
dataset = webnotes.conn.sql("select field, value from tabSingles where doctype=%s", doctype)
- return dict(dataset)
\ No newline at end of file
+ return dict(dataset)
+
+def copy_common_fields(from_doc, to_doc):
+ from webnotes.model import default_fields
+ doctype_list = webnotes.get_doctype(to_doc.doctype)
+
+ for fieldname, value in from_doc.fields.items():
+ if fieldname in default_fields:
+ continue
+
+ if doctype_list.get_field(fieldname) and to_doc.fields[fieldname] != value:
+ to_doc.fields[fieldname] = value
\ No newline at end of file
diff --git a/webnotes/test_runner.py b/webnotes/test_runner.py
index 39b1646331..a8bdaac124 100644
--- a/webnotes/test_runner.py
+++ b/webnotes/test_runner.py
@@ -77,7 +77,15 @@ def make_test_objects(doctype, test_records):
if not d.doc.naming_series:
d.doc.naming_series = "_T-" + d.doc.doctype + "-"
+ # submit if docstatus is set to 1 for test record
+ docstatus = d.doc.docstatus
+
+ d.doc.docstatus = 0
d.insert()
+
+ if docstatus == 1:
+ d.submit()
+
records.append(d.doc.name)
return records
diff --git a/webnotes/utils/file_manager.py b/webnotes/utils/file_manager.py
index 70af7a7b81..d92f810bff 100644
--- a/webnotes/utils/file_manager.py
+++ b/webnotes/utils/file_manager.py
@@ -23,6 +23,7 @@
from __future__ import unicode_literals
import webnotes
import os, conf
+from webnotes.utils import cstr
def upload():
# get record details
@@ -94,7 +95,7 @@ def get_uploaded_content():
# should not be unicode when reading a file, hence using webnotes.form
if 'filedata' in webnotes.form:
i = webnotes.form['filedata']
- webnotes.uploaded_filename, webnotes.uploaded_content = i.filename, i.file.read()
+ webnotes.uploaded_filename, webnotes.uploaded_content = cstr(i.filename), i.file.read()
return webnotes.uploaded_filename, webnotes.uploaded_content
else:
webnotes.msgprint('No File')
diff --git a/webnotes/widgets/calendar.py b/webnotes/widgets/calendar.py
index c947ed9ab1..75a4c7e1a7 100644
--- a/webnotes/widgets/calendar.py
+++ b/webnotes/widgets/calendar.py
@@ -29,7 +29,6 @@ import json
def update_event(args, field_map):
args = webnotes._dict(json.loads(args))
field_map = webnotes._dict(json.loads(field_map))
-
w = webnotes.bean(args.doctype, args.name)
w.doc.fields[field_map.start] = args[field_map.start]
w.doc.fields[field_map.end] = args[field_map.end]
diff --git a/webnotes/widgets/reportview.py b/webnotes/widgets/reportview.py
index 0ee8928d9d..ab562d1b2b 100644
--- a/webnotes/widgets/reportview.py
+++ b/webnotes/widgets/reportview.py
@@ -42,25 +42,41 @@ def build_query(arg=None):
gets doctype, subject, filters
limit_start, limit_page_length
"""
- data = webnotes.form_dict
- global tables
+ data = prepare_data(arg)
if 'query' in data:
return run_custom_query(data)
- filters = json.loads(data['filters'])
- fields = json.loads(data['fields'])
- tables = get_tables()
- load_doctypes()
+ query = """select %(fields)s from %(tables)s where %(conditions)s
+ %(group_by)s order by %(order_by)s %(limit)s""" % data
+
+ return query
- remove_user_tags(fields)
- # conditions
- conditions = build_conditions(filters)
+def prepare_data(arg=None):
+ global tables
+
+ if arg:
+ data = webnotes._dict(arg)
+ else:
+ data = webnotes._dict(webnotes.form_dict)
+
+ if 'query' in data:
+ return data
+
+ if isinstance(data.get("filters"), basestring):
+ data["filters"] = json.loads(data["filters"])
+ if isinstance(data.get("fields"), basestring):
+ data["fields"] = json.loads(data["fields"])
+
+ tables = get_tables(data)
+ load_doctypes()
+ remove_user_tags(data)
+ conditions = build_conditions(data)
# query dict
data['tables'] = ', '.join(tables)
data['conditions'] = ' and '.join(conditions)
- data['fields'] = ', '.join(fields)
+ data['fields'] = ', '.join(data.fields)
if not data.get('order_by'):
data['order_by'] = tables[0] + '.modified desc'
@@ -74,10 +90,7 @@ def build_query(arg=None):
add_limit(data)
- query = """select %(fields)s from %(tables)s where %(conditions)s
- %(group_by)s order by %(order_by)s %(limit)s""" % data
-
- return query
+ return data
def compress(data):
"""separate keys and values"""
@@ -126,12 +139,12 @@ def load_doctypes():
raise webnotes.PermissionError, doctype
doctypes[doctype] = webnotes.model.doctype.get(doctype)
-def remove_user_tags(fields):
+def remove_user_tags(data):
"""remove column _user_tags if not in table"""
- for fld in fields:
+ for fld in data.fields:
if '_user_tags' in fld:
- if not '_user_tags' in get_table_columns(webnotes.form_dict['doctype']):
- del fields[fields.index(fld)]
+ if not '_user_tags' in get_table_columns(data.doctype):
+ del data.fields[data.fields.index(fld)]
break
def add_limit(data):
@@ -140,35 +153,37 @@ def add_limit(data):
else:
data['limit'] = ''
-def build_conditions(filters):
+def build_conditions(data):
"""build conditions"""
- data = webnotes.form_dict
-
# docstatus condition
- docstatus = json.loads(data['docstatus'])
- if docstatus:
- conditions = [tables[0] + '.docstatus in (' + ','.join(docstatus) + ')']
+ if isinstance(data.docstatus, basestring):
+ data.docstatus = json.loads(data.docstatus)
+
+ if data.docstatus:
+ conditions = [tables[0] + '.docstatus in (' + ','.join(data.docstatus) + ')']
else:
# default condition
conditions = [tables[0] + '.docstatus < 2']
# make conditions from filters
- build_filter_conditions(data, filters, conditions)
+ build_filter_conditions(data, conditions)
# join parent, child tables
for tname in tables[1:]:
conditions.append(tname + '.parent = ' + tables[0] + '.name')
# match conditions
- build_match_conditions(data, conditions)
+ match_conditions = build_match_conditions(data)
+ if match_conditions:
+ conditions.append(match_conditions)
return conditions
-def build_filter_conditions(data, filters, conditions):
+def build_filter_conditions(data, conditions):
"""build conditions from user filters"""
from webnotes.utils import cstr
- for f in filters:
+ for f in data.filters:
tname = ('`tab' + f[0] + '`')
if not tname in tables:
tables.append(tname)
@@ -186,10 +201,16 @@ def build_filter_conditions(data, filters, conditions):
conditions.append('ifnull(' + tname + '.' + f[1] + ",0) " + f[2] \
+ " " + cstr(f[3]))
-def build_match_conditions(data, conditions):
+def build_match_conditions(data):
"""add match conditions if applicable"""
match_conditions = []
match = True
+
+ if not tables or not doctypes:
+ global tables
+ tables = get_tables(data)
+ load_doctypes()
+
for d in doctypes[data['doctype']]:
if d.doctype == 'DocPerm' and d.parent == data['doctype']:
if d.role in roles:
@@ -209,15 +230,16 @@ def build_match_conditions(data, conditions):
match = False
if match_conditions and match:
- conditions.append('('+ ' or '.join(match_conditions) +')')
+ return '('+ ' or '.join(match_conditions) +')'
-def get_tables():
+def get_tables(data):
"""extract tables from fields"""
- data = webnotes.form_dict
tables = ['`tab' + data['doctype'] + '`']
# add tables from fields
- for f in json.loads(data['fields']):
+ for f in data.get('fields') or []:
+ if "." not in f: continue
+
table_name = f.split('.')[0]
if table_name.lower().startswith('group_concat('):
table_name = table_name[13:]