'Return the status based on stock entries against this production order'

def get_status(self, status=None):

    if (not status):
        status = self.status
    if (self.docstatus == 0):
        status = u'Draft'
    elif (self.docstatus == 1):
        if (status != u'Stopped'):
            stock_entries = frappe._dict(frappe.db.sql(u'select    purpose,    sum(fg_completed_qty)\n DCTB  DCTB  DCTB  DCTB  DCTB from    `tabStock    Entry`    where    production_order=%s    and    docstatus=1\n DCTB  DCTB  DCTB  DCTB  DCTB group    by    purpose', self.name))
            status = u'Not    Started'
            if stock_entries:
                status = u'In    Process'
                produced_qty = stock_entries.get(u'Manufacture')
                if (flt(produced_qty) == flt(self.qty)):
                    status = u'Completed'
    else:
        status = u'Cancelled'
    return status
