'Returns
* \'Delivery Note Items\' query result as a list of dict
* Item Quantity dict of current packing slip doc
* No. of Cases of this packing slip'

def get_details_for_packing(self):

    rows = [d.item_code for d in self.get(u'items')]
    custom_fields = u',    '.join([u'dni.`{0}`'.format(d.fieldname) for d in frappe.get_meta(u'Delivery    Note    Item').get_custom_fields()])
    if custom_fields:
        custom_fields = (u',    ' + custom_fields)
    condition = u''
    if rows:
        condition = (u'    and    item_code    in    (%s)' % u',    '.join(([u'%s'] * len(rows))))
    res = frappe.db.sql(u'select    item_code,    sum(qty)    as    qty,\n DCTB  DCTB  DCTB (select    sum(psi.qty    *    (abs(ps.to_case_no    -    ps.from_case_no)    +    1))\n DCTB  DCTB  DCTB  DCTB from    `tabPacking    Slip`    ps,    `tabPacking    Slip    Item`    psi\n DCTB  DCTB  DCTB  DCTB where    ps.name    =    psi.parent    and    ps.docstatus    =    1\n DCTB  DCTB  DCTB  DCTB and    ps.delivery_note    =    dni.parent    and    psi.item_code=dni.item_code)    as    packed_qty,\n DCTB  DCTB  DCTB stock_uom,    item_name,    description,    dni.batch_no    {custom_fields}\n DCTB  DCTB  DCTB from    `tabDelivery    Note    Item`    dni\n DCTB  DCTB  DCTB where    parent=%s    {condition}\n DCTB  DCTB  DCTB group    by    item_code'.format(condition=condition, custom_fields=custom_fields), tuple(([self.delivery_note] + rows)), as_dict=1)
    ps_item_qty = dict([[d.item_code, d.qty] for d in self.get(u'items')])
    no_of_cases = ((cint(self.to_case_no) - cint(self.from_case_no)) + 1)
    return (res, ps_item_qty, no_of_cases)
