From 052a5e85e06daa7309614ebc3129a9d9d1c6b852 Mon Sep 17 00:00:00 2001 From: Nabin Hait Date: Wed, 26 Sep 2012 11:27:23 +0530 Subject: [PATCH 1/3] 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 From 9be5717f6c3b3098bb8b960e30d9f8becc937b77 Mon Sep 17 00:00:00 2001 From: Nabin Hait Date: Wed, 26 Sep 2012 11:30:30 +0530 Subject: [PATCH 2/3] fixes in gross profit report --- erpnext/selling/search_criteria/gross_profit/gross_profit.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/erpnext/selling/search_criteria/gross_profit/gross_profit.py b/erpnext/selling/search_criteria/gross_profit/gross_profit.py index 53a5fdbe5e..5b4d3fabac 100644 --- a/erpnext/selling/search_criteria/gross_profit/gross_profit.py +++ b/erpnext/selling/search_criteria/gross_profit/gross_profit.py @@ -71,7 +71,8 @@ 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/flt(r[col_idx['Amount']])), 2) or 0 + gp_percent = r[col_idx['Amount']] and 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) From 0baf74a139b6a946dabe07f155ae8bf1dc10f72b Mon Sep 17 00:00:00 2001 From: Nabin Hait Date: Wed, 26 Sep 2012 11:38:48 +0530 Subject: [PATCH 3/3] fixes in gross profit report --- erpnext/selling/search_criteria/gross_profit/gross_profit.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/erpnext/selling/search_criteria/gross_profit/gross_profit.py b/erpnext/selling/search_criteria/gross_profit/gross_profit.py index 5b4d3fabac..ba3425eccc 100644 --- a/erpnext/selling/search_criteria/gross_profit/gross_profit.py +++ b/erpnext/selling/search_criteria/gross_profit/gross_profit.py @@ -86,6 +86,6 @@ l_row[col_idx['Project Name']] = 'TOTALS' 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_amount), 2) +l_row[col_idx['Gross Profit (%)']] = tot_amount and \ + round((flt(tot_amount) - flt(tot_pur_cost))*100 / flt(tot_amount), 2) out.append(l_row) \ No newline at end of file