From 052a5e85e06daa7309614ebc3129a9d9d1c6b852 Mon Sep 17 00:00:00 2001 From: Nabin Hait Date: Wed, 26 Sep 2012 11:27:23 +0530 Subject: [PATCH] fixes in gross profit report --- .../search_criteria/gross_profit/gross_profit.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/erpnext/selling/search_criteria/gross_profit/gross_profit.py b/erpnext/selling/search_criteria/gross_profit/gross_profit.py index 5955222895..53a5fdbe5e 100644 --- a/erpnext/selling/search_criteria/gross_profit/gross_profit.py +++ b/erpnext/selling/search_criteria/gross_profit/gross_profit.py @@ -54,9 +54,13 @@ def get_purchase_cost(dn, item, wh, qty): from webnotes.utils import flt global sle purchase_cost = 0 + packing_items = sql("select item_code, qty from `tabSales BOM Item` where parent = %s", item) + if packing_items: + packing_items = [[t[0], flt(t[1])*qty] for t in packing_items] + else: + packing_items = [[item, qty]] for d in sle: - if d['voucher_no'] == dn and d['item_code'] == item \ - and d['warehouse'] == wh and abs(d['actual_qty']) == qty: + if d['voucher_no'] == dn and [d['item_code'], flt(abs(d['actual_qty']))] in packing_items: purchase_cost += flt(d['incoming_rate'])*flt(abs(d['actual_qty'])) return purchase_cost @@ -67,7 +71,7 @@ for r in res: r.append(purchase_cost) gp = flt(r[col_idx['Amount']]) - flt(purchase_cost) - gp_percent = purchase_cost and round((gp*100/purchase_cost), 2) or 0 + gp_percent = purchase_cost and round((gp*100/flt(r[col_idx['Amount']])), 2) or 0 r.append(fmt_money(gp)) r.append(fmt_money(gp_percent)) out.append(r) @@ -82,5 +86,5 @@ l_row[col_idx['Amount']] = fmt_money(tot_amount) l_row[col_idx['Purchase Cost']] = fmt_money(tot_pur_cost) l_row[col_idx['Gross Profit']] = fmt_money(flt(tot_amount) - flt(tot_pur_cost)) l_row[col_idx['Gross Profit (%)']] = round((flt(tot_amount) - flt(tot_pur_cost))*100/ \ -flt(tot_pur_cost), 2) +flt(tot_amount), 2) out.append(l_row) \ No newline at end of file