def get_invoiced_qty_map(delivery_note):
 invoiced_qty_map = {}
 for (dn_detail, qty) in frappe.db.sql(u'select dn_detail, qty from `tabSales Invoice Item`\n DCTB  DCTB where delivery_note=%s and docstatus=1', delivery_note):
  if (not invoiced_qty_map.get(dn_detail)):
   invoiced_qty_map[dn_detail] = 0
  invoiced_qty_map[dn_detail] += qty
 return invoiced_qty_map

def get_invoiced_qty_map ( delivery_note ) : invoiced_qty_map = { } for ( dn_detail , qty ) in frappe . db . sql ( u'select dn_detail, qty from `tabSales Invoice Item`\n DCTB  DCTB where delivery_note=%s and docstatus=1' , delivery_note ) : if ( not invoiced_qty_map . get ( dn_detail ) ) : invoiced_qty_map [ dn_detail ] = 0 invoiced_qty_map [ dn_detail ] += qty return invoiced_qty_map
returns a map: {dn_detail: invoiced_qty} .