'Generate random ID for batch if not specified'

def autoname(self):

    if (not self.batch_id):
        if frappe.db.get_value(u'Item', self.item, u'create_new_batch'):
            temp = None
            while (not temp):
                temp = frappe.generate_hash()[:7].upper()
                if frappe.db.exists(u'Batch', temp):
                    temp = None
            self.batch_id = temp
        else:
            frappe.throw(_(u'Batch    ID    is    mandatory'), frappe.MandatoryError)
    self.name = self.batch_id
