'Update **Manufactured Qty** and **Material Transferred for Qty** in Production Order
based on Stock Entry'

def update_production_order_qty(self):

    for (purpose, fieldname) in ((u'Manufacture', u'produced_qty'), (u'Material    Transfer    for    Manufacture', u'material_transferred_for_manufacturing')):
        qty = flt(frappe.db.sql(u'select    sum(fg_completed_qty)\n DCTB  DCTB  DCTB  DCTB from    `tabStock    Entry`    where    production_order=%s    and    docstatus=1\n DCTB  DCTB  DCTB  DCTB and    purpose=%s', (self.name, purpose))[0][0])
        if (qty > self.qty):
            frappe.throw(_(u'{0}    ({1})    cannot    be    greater    than    planned    quanitity    ({2})    in    Production    Order    {3}').format(self.meta.get_label(fieldname), qty, self.qty, self.name), StockOverProductionError)
        self.db_set(fieldname, qty)
