fix: trailing whitespace, duplication & more
This commit is contained in:
parent
57d7c837aa
commit
9aeabce3d3
@ -237,7 +237,7 @@
|
|||||||
"fieldtype": "Small Text",
|
"fieldtype": "Small Text",
|
||||||
"hidden": 0,
|
"hidden": 0,
|
||||||
"ignore_user_permissions": 0,
|
"ignore_user_permissions": 0,
|
||||||
"ignore_xss_filter": 0,
|
"ignore_xss_filter": 1,
|
||||||
"in_filter": 0,
|
"in_filter": 0,
|
||||||
"in_global_search": 0,
|
"in_global_search": 0,
|
||||||
"in_list_view": 0,
|
"in_list_view": 0,
|
||||||
|
@ -30,7 +30,6 @@ class SupplierScorecardCriteria(Document):
|
|||||||
for dummy2 in range(0, len(match.groups())):
|
for dummy2 in range(0, len(match.groups())):
|
||||||
test_formula = test_formula.replace('{' + match.group(1) + '}', "0")
|
test_formula = test_formula.replace('{' + match.group(1) + '}', "0")
|
||||||
|
|
||||||
test_formula = test_formula.replace('<','<').replace('>','>')
|
|
||||||
try:
|
try:
|
||||||
frappe.safe_eval(test_formula, None, {'max':max, 'min': min})
|
frappe.safe_eval(test_formula, None, {'max':max, 'min': min})
|
||||||
except Exception:
|
except Exception:
|
||||||
|
@ -40,22 +40,8 @@ class SupplierScorecardPeriod(Document):
|
|||||||
|
|
||||||
def calculate_criteria(self):
|
def calculate_criteria(self):
|
||||||
for crit in self.criteria:
|
for crit in self.criteria:
|
||||||
my_eval_statement = crit.formula.replace("\r", "").replace("\n", "")
|
|
||||||
|
|
||||||
for var in self.variables:
|
|
||||||
if var.value:
|
|
||||||
if var.param_name in my_eval_statement:
|
|
||||||
my_eval_statement = my_eval_statement.replace('{' + var.param_name + '}', "{:.2f}".format(var.value))
|
|
||||||
else:
|
|
||||||
if var.param_name in my_eval_statement:
|
|
||||||
my_eval_statement = my_eval_statement.replace('{' + var.param_name + '}', '0.0')
|
|
||||||
|
|
||||||
#frappe.msgprint(my_eval_statement )
|
|
||||||
|
|
||||||
my_eval_statement = my_eval_statement.replace('<','<').replace('>','>')
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
crit.score = min(crit.max_score, max( 0 ,frappe.safe_eval(my_eval_statement, None, {'max':max, 'min': min})))
|
crit.score = min(crit.max_score, max( 0 ,frappe.safe_eval(self.get_eval_statement(crit.formula), None, {'max':max, 'min': min})))
|
||||||
except Exception:
|
except Exception:
|
||||||
frappe.throw(_("Could not solve criteria score function for {0}. Make sure the formula is valid.".format(crit.criteria_name)),frappe.ValidationError)
|
frappe.throw(_("Could not solve criteria score function for {0}. Make sure the formula is valid.".format(crit.criteria_name)),frappe.ValidationError)
|
||||||
crit.score = 0
|
crit.score = 0
|
||||||
@ -67,26 +53,27 @@ class SupplierScorecardPeriod(Document):
|
|||||||
self.total_score = myscore
|
self.total_score = myscore
|
||||||
|
|
||||||
def calculate_weighted_score(self, weighing_function):
|
def calculate_weighted_score(self, weighing_function):
|
||||||
my_eval_statement = weighing_function.replace("\r", "").replace("\n", "")
|
|
||||||
|
|
||||||
for var in self.variables:
|
|
||||||
if var.value:
|
|
||||||
if var.param_name in my_eval_statement:
|
|
||||||
my_eval_statement = my_eval_statement.replace('{' + var.param_name + '}', "{:.2f}".format(var.value))
|
|
||||||
else:
|
|
||||||
if var.param_name in my_eval_statement:
|
|
||||||
my_eval_statement = my_eval_statement.replace('{' + var.param_name + '}', '0.0')
|
|
||||||
|
|
||||||
my_eval_statement = my_eval_statement.replace('<','<').replace('>','>')
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
weighed_score = frappe.safe_eval(my_eval_statement, None, {'max':max, 'min': min})
|
weighed_score = frappe.safe_eval(self.get_eval_statement(weighing_function), None, {'max':max, 'min': min})
|
||||||
except Exception:
|
except Exception:
|
||||||
frappe.throw(_("Could not solve weighted score function. Make sure the formula is valid."),frappe.ValidationError)
|
frappe.throw(_("Could not solve weighted score function. Make sure the formula is valid."),frappe.ValidationError)
|
||||||
weighed_score = 0
|
weighed_score = 0
|
||||||
return weighed_score
|
return weighed_score
|
||||||
|
|
||||||
|
|
||||||
|
def get_eval_statement(self, input):
|
||||||
|
my_eval_statement = input.replace("\r", "").replace("\n", "")
|
||||||
|
|
||||||
|
for var in self.variables:
|
||||||
|
if var.value:
|
||||||
|
if var.param_name in my_eval_statement:
|
||||||
|
my_eval_statement = my_eval_statement.replace('{' + var.param_name + '}', "{:.2f}".format(var.value))
|
||||||
|
else:
|
||||||
|
if var.param_name in my_eval_statement:
|
||||||
|
my_eval_statement = my_eval_statement.replace('{' + var.param_name + '}', '0.0')
|
||||||
|
|
||||||
|
return my_eval_statement
|
||||||
|
|
||||||
|
|
||||||
def import_string_path(path):
|
def import_string_path(path):
|
||||||
components = path.split('.')
|
components = path.split('.')
|
||||||
|
@ -203,7 +203,7 @@
|
|||||||
"fieldtype": "Small Text",
|
"fieldtype": "Small Text",
|
||||||
"hidden": 1,
|
"hidden": 1,
|
||||||
"ignore_user_permissions": 0,
|
"ignore_user_permissions": 0,
|
||||||
"ignore_xss_filter": 0,
|
"ignore_xss_filter": 1,
|
||||||
"in_filter": 0,
|
"in_filter": 0,
|
||||||
"in_global_search": 0,
|
"in_global_search": 0,
|
||||||
"in_list_view": 0,
|
"in_list_view": 0,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user