fixes in gross profit report
This commit is contained in:
parent
162a081a9f
commit
6d8d3b4cee
@ -793,7 +793,7 @@ class DocType(SellingController):
|
||||
def set_buying_amount(self):
|
||||
if cint(self.doc.is_pos) and cint(self.doc.update_stock):
|
||||
stock_ledger_entries = self.get_stock_ledger_entries()
|
||||
item_sales_bom = get_sales_bom()
|
||||
item_sales_bom = get_sales_bom(self.doc.doctype, self.doc.name)
|
||||
else:
|
||||
stock_ledger_entries = item_sales_bom = None
|
||||
|
||||
|
@ -7,7 +7,8 @@ def execute(filters=None):
|
||||
if not filters: filters = {}
|
||||
|
||||
stock_ledger_entries = get_stock_ledger_entries(filters)
|
||||
item_sales_bom = get_sales_bom()
|
||||
|
||||
item_sales_bom = get_sales_bom("Delivery Note")
|
||||
|
||||
delivery_note_items = webnotes.conn.sql("""select dn.name, dn.posting_date, dn.posting_time,
|
||||
dn.project_name, item.item_code, item.item_name, item.description, item.warehouse,
|
||||
@ -25,7 +26,9 @@ def execute(filters=None):
|
||||
for row in delivery_note_items:
|
||||
selling_amount = flt(row.amount)
|
||||
buying_amount = get_buying_amount(row.item_code, row.warehouse, -1*row.qty,
|
||||
"Delivery Note", row.name, row.item_row, stock_ledger_entries, item_sales_bom)
|
||||
"Delivery Note", row.name, row.item_row, stock_ledger_entries,
|
||||
item_sales_bom.get(row.name, webnotes._dict()))
|
||||
|
||||
buying_amount = buying_amount > 0 and buying_amount or 0
|
||||
|
||||
if selling_amount:
|
||||
|
@ -396,7 +396,7 @@ class DocType(SellingController):
|
||||
def set_buying_amount(self):
|
||||
from stock.utils import get_buying_amount, get_sales_bom
|
||||
stock_ledger_entries = self.get_stock_ledger_entries()
|
||||
item_sales_bom = get_sales_bom()
|
||||
item_sales_bom = get_sales_bom(self.doc.doctype, self.doc.name)
|
||||
|
||||
if stock_ledger_entries:
|
||||
for item in self.doclist.get({"parentfield": "delivery_note_details"}):
|
||||
|
@ -171,7 +171,8 @@ def get_buying_amount(item_code, warehouse, qty, voucher_type, voucher_no, vouch
|
||||
buying_amount = 0.0
|
||||
for bom_item in item_sales_bom[item_code]:
|
||||
buying_amount += _get_buying_amount(voucher_type, voucher_no, "[** No Item Row **]",
|
||||
bom_item.item_code, warehouse, bom_item.qty * qty, stock_ledger_entries)
|
||||
bom_item.item_code, bom_item.warehouse or warehouse,
|
||||
bom_item.total_qty or (bom_item.qty * qty), stock_ledger_entries)
|
||||
return buying_amount
|
||||
else:
|
||||
# doesn't have sales bom
|
||||
@ -184,21 +185,37 @@ def _get_buying_amount(voucher_type, voucher_no, item_row, item_code, warehouse,
|
||||
if sle.voucher_type == voucher_type and sle.voucher_no == voucher_no and \
|
||||
(sle.voucher_detail_no == item_row or (sle.voucher_type != "Stock Reconciliation"
|
||||
and sle.item_code == item_code and sle.warehouse == warehouse and flt(sle.qty) == qty)):
|
||||
# print "previous_sle", stock_ledger_entries[i+1]
|
||||
# print "current sle", sle
|
||||
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
|
||||
return 0.0
|
||||
|
||||
def get_sales_bom():
|
||||
item_sales_bom = {}
|
||||
# for r in webnotes.conn.sql("""select parent_item, item_code, qty, warehouse, voucher_detail_no
|
||||
# from `tabDelivery Note Packing Item` where docstatus = 1""", as_dict=1):
|
||||
for r in webnotes.conn.sql("""select parent, item_code, qty from `tabSales BOM Item`""",
|
||||
as_dict=1):
|
||||
item_sales_bom.setdefault(r.parent, []).append(r)
|
||||
|
||||
return item_sales_bom
|
||||
def get_sales_bom(doctype=None, docname=None):
|
||||
item_sales_bom = webnotes._dict()
|
||||
|
||||
query = """select parenttype, parent, parent_item,
|
||||
item_code, warehouse, -1*qty as total_qty
|
||||
from `tabDelivery Note Packing Item` where docstatus=1"""
|
||||
|
||||
args = {}
|
||||
if doctype:
|
||||
query += " and parenttype=%(parenttype)s"
|
||||
args["parenttype"] = doctype
|
||||
|
||||
if docname:
|
||||
query += " and parent=%(parent)s"
|
||||
args["parent"] = docname
|
||||
|
||||
for d in webnotes.conn.sql(query, args, as_dict=1):
|
||||
item_sales_bom.setdefault(d.parenttype, webnotes._dict()).setdefault(d.parent,
|
||||
webnotes._dict()).setdefault(d.parent_item, []).append(d)
|
||||
|
||||
if doctype and docname:
|
||||
return item_sales_bom[doctype].get(docname, webnotes._dict())
|
||||
elif doctype:
|
||||
return item_sales_bom[doctype]
|
||||
else:
|
||||
return item_sales_bom
|
||||
|
Loading…
x
Reference in New Issue
Block a user