fixes in gross profit report

This commit is contained in:
Nabin Hait 2012-09-26 11:27:23 +05:30
parent 9b4ffcb507
commit 052a5e85e0

View File

@ -54,9 +54,13 @@ def get_purchase_cost(dn, item, wh, qty):
from webnotes.utils import flt from webnotes.utils import flt
global sle global sle
purchase_cost = 0 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: for d in sle:
if d['voucher_no'] == dn and d['item_code'] == item \ if d['voucher_no'] == dn and [d['item_code'], flt(abs(d['actual_qty']))] in packing_items:
and d['warehouse'] == wh and abs(d['actual_qty']) == qty:
purchase_cost += flt(d['incoming_rate'])*flt(abs(d['actual_qty'])) purchase_cost += flt(d['incoming_rate'])*flt(abs(d['actual_qty']))
return purchase_cost return purchase_cost
@ -67,7 +71,7 @@ for r in res:
r.append(purchase_cost) r.append(purchase_cost)
gp = flt(r[col_idx['Amount']]) - flt(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))
r.append(fmt_money(gp_percent)) r.append(fmt_money(gp_percent))
out.append(r) 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['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']] = fmt_money(flt(tot_amount) - flt(tot_pur_cost))
l_row[col_idx['Gross Profit (%)']] = round((flt(tot_amount) - flt(tot_pur_cost))*100/ \ 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) out.append(l_row)