From 9aa11d2ad7b757851a9c0492efe8b5e840fa98ea Mon Sep 17 00:00:00 2001 From: ankitjavalkarwork Date: Thu, 18 Sep 2014 19:06:11 +0530 Subject: [PATCH] Add ability to fetch Non stock items in Gross Profit report --- .../report/gross_profit/gross_profit.json | 2 +- .../report/gross_profit/gross_profit.py | 7 +++--- erpnext/stock/utils.py | 25 +++++++++++++------ 3 files changed, 21 insertions(+), 13 deletions(-) diff --git a/erpnext/accounts/report/gross_profit/gross_profit.json b/erpnext/accounts/report/gross_profit/gross_profit.json index 81e0aaf925..69555d04c9 100644 --- a/erpnext/accounts/report/gross_profit/gross_profit.json +++ b/erpnext/accounts/report/gross_profit/gross_profit.json @@ -5,7 +5,7 @@ "doctype": "Report", "idx": 1, "is_standard": "Yes", - "modified": "2014-06-03 07:18:17.077022", + "modified": "2014-09-18 19:00:50.263854", "modified_by": "Administrator", "module": "Accounts", "name": "Gross Profit", diff --git a/erpnext/accounts/report/gross_profit/gross_profit.py b/erpnext/accounts/report/gross_profit/gross_profit.py index 76e7b4a163..bff561dc12 100644 --- a/erpnext/accounts/report/gross_profit/gross_profit.py +++ b/erpnext/accounts/report/gross_profit/gross_profit.py @@ -14,7 +14,7 @@ def execute(filters=None): source = get_source_data(filters) item_sales_bom = get_item_sales_bom() - columns = [__("Delivery Note/Sales Invoice") + "::120", _("Link") + "::30", _("Posting Date") + ":Date", _("Posting Time"), + columns = [_("Delivery Note/Sales Invoice") + "::120", _("Link") + "::30", _("Posting Date") + ":Date", _("Posting Time"), _("Item Code") + ":Link/Item", _("Item Name"), _("Description"), _("Warehouse") + ":Link/Warehouse", _("Qty") + ":Float", _("Selling Rate") + ":Currency", _("Avg. Buying Rate") + ":Currency", _("Selling Amount") + ":Currency", _("Buying Amount") + ":Currency", @@ -29,7 +29,7 @@ def execute(filters=None): 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.parenttype, row.name, row.item_row, + 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), [])) buying_amount = buying_amount > 0 and buying_amount or 0 @@ -107,11 +107,10 @@ def get_source_data(filters): timestamp(si.posting_date, si.posting_time) as posting_datetime from `tabSales Invoice` si, `tabSales Invoice Item` item where item.parent = si.name and si.docstatus = 1 %s - and si.update_stock = 1 order by si.posting_date desc, si.posting_time desc""" % (conditions,), filters, as_dict=1) source = delivery_note_items + sales_invoice_items if len(source) > len(delivery_note_items): source.sort(key=lambda d: d.posting_datetime, reverse=True) - return source \ No newline at end of file + return source diff --git a/erpnext/stock/utils.py b/erpnext/stock/utils.py index 7264f360b9..0b32f7ebf7 100644 --- a/erpnext/stock/utils.py +++ b/erpnext/stock/utils.py @@ -159,18 +159,27 @@ def get_sales_bom_buying_amount(item_code, warehouse, voucher_type, voucher_no, return buying_amount -def get_buying_amount(voucher_type, voucher_no, item_row, stock_ledger_entries): +def get_buying_amount(item_code, item_qty, voucher_type, voucher_no, item_row, stock_ledger_entries): # IMP NOTE # stock_ledger_entries should already be filtered by item_code and warehouse and # sorted by posting_date desc, posting_time desc - for i, sle in enumerate(stock_ledger_entries): - if sle.voucher_type == voucher_type and sle.voucher_no == voucher_no and \ - sle.voucher_detail_no == item_row: - previous_stock_value = len(stock_ledger_entries) > i+1 and \ - flt(stock_ledger_entries[i+1].stock_value) or 0.0 - buying_amount = previous_stock_value - flt(sle.stock_value) + if frappe.db.get_value("Item", item_code, "is_stock_item") == "Yes": + for i, sle in enumerate(stock_ledger_entries): + if sle.voucher_type == voucher_type and sle.voucher_no == voucher_no and \ + sle.voucher_detail_no == item_row: + previous_stock_value = len(stock_ledger_entries) > i+1 and \ + flt(stock_ledger_entries[i+1].stock_value) or 0.0 + buying_amount = previous_stock_value - flt(sle.stock_value) + + return buying_amount + else: + item_rate = frappe.db.sql("""select sum(base_amount) / sum(qty) + from `tabPurchase Invoice Item` + where item_code = %s and docstatus=1""" % ('%s'), item_code) + buying_amount = flt(item_qty) * flt(item_rate[0][0]) + + return buying_amount - return buying_amount return 0.0