'Cancel submitted packing slips related to this delivery note'

def cancel_packing_slips(self):

    res = frappe.db.sql(u'SELECT    name    FROM    `tabPacking    Slip`    WHERE    delivery_note    =    %s\n DCTB  DCTB  DCTB AND    docstatus    =    1', self.name)
    if res:
        for r in res:
            ps = frappe.get_doc(u'Packing    Slip', r[0])
            ps.cancel()
        frappe.msgprint(_(u'Packing    Slip(s)    cancelled'))
