If condition in python

def check_total_points(self):
total_points = 0
for d in self.get(“work_changes”):
total_points += int(d.per_weightage or 0)

	if cint(total_points) != 0 or 100:
		frappe.throw(_("Sum of points for all weightage of work plan changes should be 100. It is {0}").format(total_points))

if total_points is equal to “0” or “100”, it should allow but if total_points is not equal to “0” to “100”, it should not allow.

but my above code is not working. its not allow to save data if total_points is “0”.

please help me.

I have not found docs or example code with cint?

total_points is an int type

In your OR boolean expression, total_points must be evaluated both times.

 total_points = 1
 type(total_points)
<class ‘int’>
 total_points != 0 or total_points != 100
total_points = 0
 total_points != 0
 total_points = 1
 total_points != 0


try this

if cint(total_points) not in (0, 100):
1 Like

@max_morais_dmm, thanks for your help, it work find

How odd no sign of this function in these docs!? https://docs.python.org/3/genindex-C.html

Perhaps someone can shed light on this or what I am missing here?


@clarkej, it’s not part of python functions, but it’s part of frappe data conversion utilities

Just one historical contextualization

On the beggining of frappe (aka wnframework) it was one CGI framework, and in CGI all the data is handled as text, so you need to have functions to ensure the property conversion between types.

1 Like

Thank you for the explanation my grep skills failed me :slight_smile: