Merge pull request #2213 from ankitjavalkarwork/grossprofitrep

Add ability to fetch Non stock items in Gross Profit report
This commit is contained in:
Nabin Hait 2014-09-26 15:03:09 +05:30
commit 81959cc8eb
3 changed files with 21 additions and 13 deletions

View File

@ -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",

View File

@ -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
return source

View File

@ -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