def get_where_clause_value(self, value, param, error=False): if value: if isinstance(value, basestring): a = ["'%s'" % frappe.utils.strip(t) for t in value.split(",")] else: a = ["'%s'" % unicode(t) for t in value] else: """ get default value for id """ value = utils.get_default_param_value(param, error=error) if isinstance(value, basestring): a = ["'%s'" % frappe.utils.strip(t) for t in value.split(",")] elif value is not None: a = ["'%s'" % unicode(t) for t in list(value)] else: """ If there is no default value for id then return. Probably there is one in the sended parameters The Administrator need to set the parameter type to Ask` ad remove his default values """ return value = "where name %s (%s)" % (param.param_expression, ",".join(a)) return value
def get_where_clause_value(self, value, param, error=False): if value: if isinstance(value, basestring): a = ["'%s'" % frappe.utils.strip(t) for t in value.split(",")] else: a = ["'%s'" % unicode(t) for t in value] else: """ get default value for id """ value = utils.get_default_param_value(param, error=error) if isinstance(value, basestring): a = ["'%s'" % frappe.utils.strip(t) for t in value.split(",")] elif value is not None: a = ["'%s'" % unicode(t) for t in list(value)] else: """ If there is no default value for id then return. Probably there is one in the sended parameters The Administrator need to set the parameter type to Ask` ad remove his default values """ return value = "where name %s (%s)" % (param.param_expression, ",".join(a)) return value
def do_params(self, data, params, pformat): pram = [] copies = {} pram_server = [] #used_ids = False for param in params: is_copy = param.is_copy.lower() p = param.jasper_param_name value = "" if is_copy == "is for where clause": value = self.get_where_clause_value(data.get('ids', []), param) if not value: """ Check if the ids was sended by asked parameters """ value = self.get_where_clause_value(data.get("params", {}).get(p), param, error=True) value = [value] elif is_copy == "is for copies" and pformat=="pdf": #set the number of copies #indicate the index of param is for copies copies["pram_copy_index"] = len(pram) values = utils.get_default_param_value(param, error=False) or "" value = self.get_param_values(values) elif is_copy == "is for page number" and pformat=="pdf": copies["pram_copy_page_index"] = len(pram) elif is_copy == "is for server hook":#_("is for server hook"): #don't do server hook here. Get first all defaults values #if not value: #if not data then get default first value = utils.get_default_param_value(param, error=False) pram_server.append({"name":p, 'value': value, "attrs": param}) continue else: #value sent take precedence from value in doctype jasper_param_value values = data.get("params", {}).get(p) or param.jasper_param_value or "" value = self.get_param_values(values) pram.append({"name":p, 'value':value}) return (pram, pram_server, copies)
def do_params(self, data, params, pformat): pram = [] copies = {} pram_server = [] #used_ids = False for param in params: is_copy = param.is_copy.lower() p = param.jasper_param_name value = "" if is_copy == "is for where clause": value = self.get_where_clause_value(data.get('ids', []), param) if not value: """ Check if the ids was sended by asked parameters """ value = self.get_where_clause_value(data.get("params", {}).get(p), param, error=True) value = [value] elif is_copy == "is for copies" and pformat=="pdf": #set the number of copies #indicate the index of param is for copies copies["pram_copy_index"] = len(pram) values = utils.get_default_param_value(param, error=False) or "" value = self.get_param_values(values) elif is_copy == "is for page number" and pformat=="pdf": copies["pram_copy_page_index"] = len(pram) elif is_copy == "is for server hook":#_("is for server hook"): #don't do server hook here. Get first all defaults values #if not value: #if not data then get default first value = utils.get_default_param_value(param, error=False) pram_server.append({"name":p, 'value': value, "attrs": param}) continue else: #value sent take precedence from value in doctype jasper_param_value values = data.get("params", {}).get(p) or param.jasper_param_value or "" value = self.get_param_values(values) pram.append({"name":p, 'value':value}) return (pram, pram_server, copies)
def do_params(self, data, params, pformat, doc): pram = [] copies = {} pram_server = [] #used_ids = False for param in params: is_copy = param.is_copy.lower() p = param.jasper_param_name value = "" if is_copy == "is for where clause": value = self.get_where_clause_value(data.get('ids', []), param) if not value: """ Check if the ids was sended by asked parameters """ value = self.get_where_clause_value(data.get("params", {}).get(p), param, error=True) value = [value] elif is_copy == "is for copies" and pformat == "pdf": #set the number of copies #indicate the index of param is for copies copies["pram_copy_index"] = len(pram) values = utils.get_default_param_value(param, error=False) or "" value = self.get_param_values(values) elif is_copy == "is for page number" and pformat == "pdf": copies["pram_copy_page_index"] = len(pram) elif is_copy == "is for server hook": #_("is for server hook"): #don't do server hook here. Get first all defaults values #if not value: #if not data then get default first value = utils.get_default_param_value(param, error=False) pram_server.append({"name": p, 'value': value, "attrs": param}) continue elif is_copy == "is doctype id": values = data.get("params", {}).get(p) or param.jasper_param_value or "" if not values or (isinstance(values, basestring) and len(values.split(":")) > 1): field_name = values or param.jasper_field_doctype.strip() f = field_name.split(":") if len(f) > 2: doctype = f[0] docname = f[1] field = f[2] elif len(f) > 1: doctype = f[0] field = f[1] docname = data.get('ids', [])[0] else: doctype = doc.jasper_doctype docname = data.get('ids', [])[0] field = f[0] frappe_doc = frappe.get_doc(doctype, docname) values = getattr(frappe_doc, field) value = self.get_param_values(values) print "value do_params %s" % value else: #value sent take precedence from value in doctype jasper_param_value values = data.get("params", {}).get(p) or param.jasper_param_value or "" value = self.get_param_values(values) if param.jasper_param_type != "String": for idx, val in enumerate(value): value[idx] = str(val) """ if param.jasper_param_type == "Int": from jasper_erpnext_report.jasper_reports import Integer for idx, val in enumerate(value): value[idx] = Integer(val) """ pram.append({"name": p, 'value': value}) return (pram, pram_server, copies)
def do_params(self, data, params, pformat, doc): pram = [] copies = {} pram_server = [] #used_ids = False for param in params: is_copy = param.is_copy.lower() p = param.jasper_param_name value = "" if is_copy == "is for where clause": value = self.get_where_clause_value(data.get('ids', []), param) if not value: """ Check if the ids was sended by asked parameters """ value = self.get_where_clause_value(data.get("params", {}).get(p), param, error=True) value = [value] elif is_copy == "is for copies" and pformat=="pdf": #set the number of copies #indicate the index of param is for copies copies["pram_copy_index"] = len(pram) values = utils.get_default_param_value(param, error=False) or "" value = self.get_param_values(values) elif is_copy == "is for page number" and pformat=="pdf": copies["pram_copy_page_index"] = len(pram) elif is_copy == "is for server hook":#_("is for server hook"): #don't do server hook here. Get first all defaults values #if not value: #if not data then get default first value = utils.get_default_param_value(param, error=False) pram_server.append({"name":p, 'value': value, "attrs": param}) continue elif is_copy == "is doctype id": values = data.get("params", {}).get(p) or param.jasper_param_value or "" if not values or (isinstance(values, basestring) and len(values.split(":")) > 1): field_name = values or param.jasper_field_doctype.strip() f = field_name.split(":") if len(f) > 2: doctype = f[0] docname = f[1] field = f[2] elif len(f) > 1: doctype = f[0] field = f[1] docname = data.get('ids', [])[0] else: doctype = doc.jasper_doctype docname = data.get('ids', [])[0] field = f[0] frappe_doc = frappe.get_doc(doctype, docname) values = getattr(frappe_doc, field) value = self.get_param_values(values) print "value do_params %s" % value else: #value sent take precedence from value in doctype jasper_param_value values = data.get("params", {}).get(p) or param.jasper_param_value or "" value = self.get_param_values(values) if param.jasper_param_type != "String": for idx, val in enumerate(value): value[idx] = str(val) """ if param.jasper_param_type == "Int": from jasper_erpnext_report.jasper_reports import Integer for idx, val in enumerate(value): value[idx] = Integer(val) """ pram.append({"name":p, 'value':value}) return (pram, pram_server, copies)