fix: trailing whitespace, duplication & more

This commit is contained in:
Sagar Vora 2019-01-23 16:01:19 +05:30
parent 57d7c837aa
commit 9aeabce3d3
4 changed files with 898 additions and 912 deletions

View File

@ -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,

View File

@ -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('&lt;','<').replace('&gt;','>')
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:

View File

@ -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('&lt;','<').replace('&gt;','>')
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,7 +53,16 @@ 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", "") try:
weighed_score = frappe.safe_eval(self.get_eval_statement(weighing_function), None, {'max':max, 'min': min})
except Exception:
frappe.throw(_("Could not solve weighted score function. Make sure the formula is valid."),frappe.ValidationError)
weighed_score = 0
return weighed_score
def get_eval_statement(self, input):
my_eval_statement = input.replace("\r", "").replace("\n", "")
for var in self.variables: for var in self.variables:
if var.value: if var.value:
@ -77,15 +72,7 @@ class SupplierScorecardPeriod(Document):
if var.param_name in my_eval_statement: 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('{' + var.param_name + '}', '0.0')
my_eval_statement = my_eval_statement.replace('&lt;','<').replace('&gt;','>') return my_eval_statement
try:
weighed_score = frappe.safe_eval(my_eval_statement, None, {'max':max, 'min': min})
except Exception:
frappe.throw(_("Could not solve weighted score function. Make sure the formula is valid."),frappe.ValidationError)
weighed_score = 0
return weighed_score
def import_string_path(path): def import_string_path(path):

View File

@ -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,