brotherton-erpnext/erpnext/accounts/report/gross_profit/gross_profit.py

66 lines
2.6 KiB
Python
Raw Normal View History

2013-11-20 07:29:58 +00:00
# Copyright (c) 2013, Web Notes Technologies Pvt. Ltd. and Contributors
# License: GNU General Public License v3. See license.txt
from __future__ import unicode_literals
2014-02-14 10:17:51 +00:00
import frappe
2014-09-11 08:15:27 +00:00
from frappe import _
2014-11-21 06:36:00 +00:00
from erpnext.accounts.reports.gross_profit import gross_profit_generator
def execute(filters=None):
if not filters: filters = {}
2014-09-17 06:43:31 +00:00
2013-03-06 13:20:53 +00:00
stock_ledger_entries = get_stock_ledger_entries(filters)
source = get_source_data(filters)
2013-03-22 07:46:10 +00:00
item_sales_bom = get_item_sales_bom()
2014-09-17 06:43:31 +00:00
2014-11-21 06:36:00 +00:00
columns = [_("Sales Invoice") + "::120", _("Link") + "::30", _("Posting Date") + ":Date", _("Posting Time"),
2014-09-11 08:15:27 +00:00
_("Item Code") + ":Link/Item", _("Item Name"), _("Description"), _("Warehouse") + ":Link/Warehouse",
2014-09-17 06:43:31 +00:00
_("Qty") + ":Float", _("Selling Rate") + ":Currency", _("Avg. Buying Rate") + ":Currency",
2014-09-11 08:15:27 +00:00
_("Selling Amount") + ":Currency", _("Buying Amount") + ":Currency",
_("Gross Profit") + ":Currency", _("Gross Profit %") + ":Percent", _("Project") + ":Link/Project"]
data = []
for row in source:
2014-02-10 13:50:15 +00:00
selling_amount = flt(row.base_amount)
total_selling_amount += flt(row.base_amount)
2014-09-17 06:43:31 +00:00
2014-02-14 10:17:51 +00:00
item_sales_bom_map = item_sales_bom.get(row.parenttype, {}).get(row.name, frappe._dict())
2014-09-17 06:43:31 +00:00
if item_sales_bom_map.get(row.item_code):
2014-09-17 06:43:31 +00:00
buying_amount = get_sales_bom_buying_amount(row.item_code, row.warehouse,
row.parenttype, row.name, row.item_row, stock_ledger_entries, item_sales_bom_map)
else:
buying_amount = get_buying_amount(row.item_code, row.qty, row.parenttype, row.name, row.item_row,
stock_ledger_entries.get((row.item_code, row.warehouse), []))
2014-09-17 06:43:31 +00:00
buying_amount = buying_amount > 0 and buying_amount or 0
total_buying_amount += buying_amount
2013-03-28 11:10:30 +00:00
gross_profit = selling_amount - buying_amount
total_gross_profit += gross_profit
if selling_amount:
gross_profit_percent = (gross_profit / selling_amount) * 100.0
else:
2013-03-28 11:10:30 +00:00
gross_profit_percent = 0.0
2014-09-17 06:43:31 +00:00
icon = """<a href="%s"><i class="icon icon-share" style="cursor: pointer;"></i></a>""" \
% ("/".join(["#Form", row.parenttype, row.name]),)
data.append([row.name, icon, row.posting_date, row.posting_time, row.item_code, row.item_name,
2014-09-17 06:43:31 +00:00
row.description, row.warehouse, row.qty, row.base_rate,
2014-02-10 13:50:15 +00:00
row.qty and (buying_amount / row.qty) or 0, row.base_amount, buying_amount,
gross_profit, gross_profit_percent, row.project])
2014-09-17 06:43:31 +00:00
if total_selling_amount:
total_gross_profit_percent = (total_gross_profit / total_selling_amount) * 100.0
else:
total_gross_profit_percent = 0.0
data.append(["Total", None, None, None, None, None, None, None, None, None, None, total_selling_amount,
total_buying_amount, total_gross_profit, total_gross_profit_percent, None])
return columns, data
2014-09-17 06:43:31 +00:00
2014-11-21 06:36:00 +00:00