How to Check and update value in all rows of Child table?

I am using below code to check the serial number in Sales Invoice and updating value as ’ 1’ if the serial number exsisted in sales invoice .In my case it fetches the value perfectly but checking and updating is performing only once at time .How to get previous value (status) along with current value.

from future import unicode_literals
import frappe
from frappe.model.document import Document
from frappe.utils import cint,cstr

class SerialVerification(Document):

def validate(self):
	value_dict = []
	value = frappe.db.sql("""SELECT serial_no from `tabSales Invoice Item` where parent = %s and docstatus = 1""",(self.name1))
	y= [] 
	for i in value:
		for j in i:
			data = j
			if '\n' in data:
				val = data .replace('\n',',')
				val = cstr(val)
				val = val.split(',')
				for val1 in val:
					y = val1

	self.set('item', {})

	last_idx = max([cint(d.idx) for d in self.get("item")] or [0,])
	for i, d in enumerate(value_dict):
		ch = self.append('item', {}) = d
		ch.rows = 0
			if(self.invoice ==
				ch.status = 1	
				frappe.db.sql(""" update `tabSerial Item` t1, `tabSerial Verification`t2 set t1.status = %s where t1.parent = and t1.parent = %s""",(ch.status,
				ch.status = 0
		ch.idx = last_idx + i + 1

Screenshot is attached for reference
step 1:
Value (1) is updated perfectly

step 2 :
When it check for other number ,it also updating correctly ,But the previous updated value is disabled…

How to get previous value and current value at a time