[minor] converty types for single doctypes in load_from_db, moved some functions to number_format.js for use in website
This commit is contained in:
parent
2d0f99b80c
commit
a000ec95d7
8 changed files with 54 additions and 39 deletions
|
|
@ -68,17 +68,6 @@ function replace_newlines(t) {
|
|||
return t?t.replace(/\n/g, '<br>'):'';
|
||||
}
|
||||
|
||||
function cint(v, def) {
|
||||
if(v===true)
|
||||
return 1;
|
||||
if(v===false)
|
||||
return 0;
|
||||
v=v+'';
|
||||
v=lstrip(v, ['0']);
|
||||
v=parseInt(v);
|
||||
if(isNaN(v))v=def===undefined?0:def;
|
||||
return v;
|
||||
}
|
||||
function validate_email(txt) {
|
||||
return wn.utils.validate_type(txt, "email");
|
||||
}
|
||||
|
|
@ -116,17 +105,6 @@ var strip = function(s, chars) {
|
|||
return s;
|
||||
}
|
||||
|
||||
var lstrip = function(s, chars) {
|
||||
if(!chars) chars = ['\n', '\t', ' '];
|
||||
// strip left
|
||||
var first_char = s.substr(0,1);
|
||||
while(in_list(chars, first_char)) {
|
||||
var s = s.substr(1);
|
||||
first_char = s.substr(0,1);
|
||||
}
|
||||
return s;
|
||||
}
|
||||
|
||||
var rstrip = function(s, chars) {
|
||||
if(!chars) chars = ['\n', '\t', ' '];
|
||||
var last_char = s.substr(s.length-1);
|
||||
|
|
@ -160,13 +138,6 @@ function values(obj) {
|
|||
return myvalues;
|
||||
}
|
||||
|
||||
function in_list(list, item) {
|
||||
if(!list) return false;
|
||||
for(var i=0, j=list.length; i<j; i++)
|
||||
if(list[i]==item) return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
function has_words(list, item) {
|
||||
if(!item) return true;
|
||||
if(!list) return false;
|
||||
|
|
|
|||
|
|
@ -787,7 +787,7 @@ _f.Frm.prototype.disable_save = function() {
|
|||
|
||||
_f.Frm.prototype.save_or_update = function() {
|
||||
if(this.save_disabled) return;
|
||||
|
||||
|
||||
if(this.doc.docstatus===0) {
|
||||
this.save();
|
||||
} else if(this.doc.docstatus===1 && this.doc.__unsaved) {
|
||||
|
|
|
|||
|
|
@ -202,9 +202,9 @@ wn.Application = Class.extend({
|
|||
$(document).keydown("meta+s ctrl+s", function(e) {
|
||||
if(cur_frm) {
|
||||
cur_frm.save_or_update();
|
||||
}
|
||||
else if(wn.container.page.save_action)
|
||||
} else if(wn.container.page.save_action) {
|
||||
wn.container.page.save_action();
|
||||
}
|
||||
return false;
|
||||
});
|
||||
},
|
||||
|
|
|
|||
|
|
@ -24,6 +24,18 @@ function flt(v, decimals, number_format) {
|
|||
return v;
|
||||
}
|
||||
|
||||
function cint(v, def) {
|
||||
if(v===true)
|
||||
return 1;
|
||||
if(v===false)
|
||||
return 0;
|
||||
v=v+'';
|
||||
v=lstrip(v, ['0']);
|
||||
v=parseInt(v);
|
||||
if(isNaN(v))v=def===undefined?0:def;
|
||||
return v;
|
||||
}
|
||||
|
||||
function strip_number_groups(v, number_format) {
|
||||
if(!number_format) number_format = get_number_format();
|
||||
|
||||
|
|
@ -163,4 +175,22 @@ function precision(fieldname, doc) {
|
|||
var df = wn.meta.get_docfield(doc.doctype, fieldname, doc.parent || doc.name);
|
||||
if(!df) console.log(fieldname + ": could not find docfield in method precision()");
|
||||
return wn.meta.get_field_precision(df, doc);
|
||||
}
|
||||
|
||||
var lstrip = function(s, chars) {
|
||||
if(!chars) chars = ['\n', '\t', ' '];
|
||||
// strip left
|
||||
var first_char = s.substr(0,1);
|
||||
while(in_list(chars, first_char)) {
|
||||
var s = s.substr(1);
|
||||
first_char = s.substr(0,1);
|
||||
}
|
||||
return s;
|
||||
}
|
||||
|
||||
function in_list(list, item) {
|
||||
if(!list) return false;
|
||||
for(var i=0, j=list.length; i<j; i++)
|
||||
if(list[i]==item) return true;
|
||||
return false;
|
||||
}
|
||||
|
|
@ -229,6 +229,7 @@ class LoginManager:
|
|||
from webnotes.sessions import clear_sessions
|
||||
clear_sessions(user)
|
||||
webnotes.add_cookies["full_name"] = ""
|
||||
webnotes.add_cookies["sid"] = ""
|
||||
|
||||
|
||||
class CookieManager:
|
||||
|
|
|
|||
|
|
@ -30,7 +30,7 @@ Group actions like save, etc are performed on doclists
|
|||
|
||||
import webnotes
|
||||
from webnotes import _, msgprint
|
||||
from webnotes.utils import cint, cstr
|
||||
from webnotes.utils import cint, cstr, flt
|
||||
from webnotes.model.doc import Document
|
||||
|
||||
class DocstatusTransitionError(webnotes.ValidationError): pass
|
||||
|
|
@ -68,7 +68,7 @@ class Bean:
|
|||
if not dn: dn = self.doc.name
|
||||
|
||||
doc = Document(dt, dn, prefix=prefix)
|
||||
|
||||
|
||||
# get all children types
|
||||
tablefields = webnotes.model.meta.get_table_fields(dt)
|
||||
|
||||
|
|
@ -78,6 +78,9 @@ class Bean:
|
|||
doclist += getchildren(doc.name, t[0], t[1], dt, prefix=prefix)
|
||||
|
||||
self.set_doclist(doclist)
|
||||
|
||||
if dt == dn:
|
||||
self.convert_type(self.doc)
|
||||
|
||||
def __iter__(self):
|
||||
return self.doclist.__iter__()
|
||||
|
|
@ -219,7 +222,7 @@ class Bean:
|
|||
if d.parentfield:
|
||||
if not webnotes.in_import:
|
||||
if not d.parentfield in parentfields:
|
||||
webnotes.msgprint("Bad parentfield %s" % parentfield,
|
||||
webnotes.msgprint("Bad parentfield %s" % d.parentfield,
|
||||
raise_exception=True)
|
||||
d.parenttype = self.doc.doctype
|
||||
d.parent = self.doc.name
|
||||
|
|
@ -377,7 +380,7 @@ class Bean:
|
|||
msg = ""
|
||||
if df.fieldtype == "Table":
|
||||
if not self.doclist.get({"parentfield": df.fieldname}):
|
||||
msg = _("Error") + ": " + _("Data missing in table") + ": " + _(label)
|
||||
msg = _("Error") + ": " + _("Data missing in table") + ": " + _(df.label)
|
||||
|
||||
elif doc.fields.get(df.fieldname) is None:
|
||||
msg = _("Error") + ": "
|
||||
|
|
@ -394,6 +397,15 @@ class Bean:
|
|||
msgprint(msg)
|
||||
|
||||
raise webnotes.MandatoryError, ", ".join([fieldname for msg, fieldname in missing])
|
||||
|
||||
def convert_type(self, doc):
|
||||
for df in self.meta.get({"doctype": "DocField", "parent": doc.doctype}):
|
||||
if df.fieldtype in ("Int", "Check"):
|
||||
doc.fields[df.fieldname] = cint(doc.fields.get(df.fieldname))
|
||||
elif df.fieldtype in ("Float", "Currency"):
|
||||
doc.fields[df.fieldname] = flt(doc.fields.get(df.fieldname))
|
||||
|
||||
doc.docstatus = cint(doc.docstatus)
|
||||
|
||||
def clone(source_wrapper):
|
||||
""" make a clone of a document"""
|
||||
|
|
|
|||
|
|
@ -26,13 +26,14 @@ from webnotes import _
|
|||
from webnotes.utils import cstr
|
||||
from webnotes.model import default_fields
|
||||
|
||||
def get_mapped_doclist(from_doctype, from_docname, table_maps, target_doclist=[], postprocess=None):
|
||||
def get_mapped_doclist(from_doctype, from_docname, table_maps, target_doclist=[], postprocess=None,
|
||||
ignore_permissions=False):
|
||||
if isinstance(target_doclist, basestring):
|
||||
target_doclist = json.loads(target_doclist)
|
||||
|
||||
source = webnotes.bean(from_doctype, from_docname)
|
||||
|
||||
if not webnotes.has_permission(from_doctype, doc=source.doc):
|
||||
if not ignore_permissions and not webnotes.has_permission(from_doctype, doc=source.doc):
|
||||
webnotes.msgprint("No Permission", raise_exception=webnotes.PermissionError)
|
||||
|
||||
source_meta = webnotes.get_doctype(from_doctype)
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@ from __future__ import unicode_literals
|
|||
|
||||
import os
|
||||
import conf
|
||||
from startup.website import *
|
||||
from startup.webutils import *
|
||||
import webnotes
|
||||
import webnotes.utils
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue