'Validate if case nos overlap. If they do, recommend next case no.'

def validate_case_nos(self):

    if (not cint(self.from_case_no)):
        frappe.msgprint(_(u"Please    specify    a    valid    'From    Case    No.'"), raise_exception=1)
    elif (not self.to_case_no):
        self.to_case_no = self.from_case_no
    elif (self.from_case_no > self.to_case_no):
        frappe.msgprint(_(u"'To    Case    No.'    cannot    be    less    than    'From    Case    No.'"), raise_exception=1)
    res = frappe.db.sql(u'SELECT    name    FROM    `tabPacking    Slip`\n DCTB  DCTB  DCTB WHERE    delivery_note    =    %(delivery_note)s    AND    docstatus    =    1    AND\n DCTB  DCTB  DCTB ((from_case_no    BETWEEN    %(from_case_no)s    AND    %(to_case_no)s)\n DCTB  DCTB  DCTB OR    (to_case_no    BETWEEN    %(from_case_no)s    AND    %(to_case_no)s)\n DCTB  DCTB  DCTB OR    (%(from_case_no)s    BETWEEN    from_case_no    AND    to_case_no))\n DCTB  DCTB  DCTB ', {u'delivery_note': self.delivery_note, u'from_case_no': self.from_case_no, u'to_case_no': self.to_case_no})
    if res:
        frappe.throw(_(u'Case    No(s)    already    in    use.    Try    from    Case    No    {0}').format(self.get_recommended_case_no()))
