'update Sales Invoice refrence in Serial No'

def update_serial_no(self, in_cancel=False):

    invoice = (None if (in_cancel or self.is_return) else self.name)
    if (in_cancel and self.is_return):
        invoice = self.return_against
    for item in self.items:
        if (not item.serial_no):
            continue
        for serial_no in item.serial_no.split(u'\n'):
            if (serial_no and frappe.db.exists(u'Serial    No', serial_no)):
                sno = frappe.get_doc(u'Serial    No', serial_no)
                sno.sales_invoice = invoice
                sno.db_update()
