[fixes] nested set fix for warehouse, tree for accounts and cost center
This commit is contained in:
@@ -15,24 +15,34 @@ def get_stock_value_on(warehouse=None, posting_date=None, item_code=None):
|
||||
values, condition = [posting_date], ""
|
||||
|
||||
if warehouse:
|
||||
values.append(warehouse)
|
||||
condition += " AND warehouse = %s"
|
||||
|
||||
wh = frappe.get_doc("Warehouse", warehouse)
|
||||
|
||||
if wh.is_group == "Yes":
|
||||
values.extend([wh.lft, wh.rgt])
|
||||
condition += "and exists (\
|
||||
select name from `tabWarehouse` wh where wh.name = sle.warehouse\
|
||||
and wh.lft >= %s and wh.rgt <= %s)"
|
||||
|
||||
else:
|
||||
values.append(warehouse)
|
||||
condition += " AND warehouse = %s"
|
||||
|
||||
if item_code:
|
||||
values.append(item_code)
|
||||
condition.append(" AND item_code = %s")
|
||||
|
||||
stock_ledger_entries = frappe.db.sql("""
|
||||
SELECT item_code, stock_value
|
||||
FROM `tabStock Ledger Entry`
|
||||
SELECT item_code, stock_value, name, warehouse
|
||||
FROM `tabStock Ledger Entry` sle
|
||||
WHERE posting_date <= %s {0}
|
||||
ORDER BY timestamp(posting_date, posting_time) DESC, name DESC
|
||||
""".format(condition), values, as_dict=1)
|
||||
|
||||
sle_map = {}
|
||||
for sle in stock_ledger_entries:
|
||||
sle_map.setdefault(sle.item_code, flt(sle.stock_value))
|
||||
|
||||
sle_map[sle.item_code] = sle_map.get(sle.item_code, 0.0) + flt(sle.stock_value)
|
||||
|
||||
return sum(sle_map.values())
|
||||
|
||||
def get_stock_balance(item_code, warehouse, posting_date=None, posting_time=None, with_valuation_rate=False):
|
||||
|
||||
Reference in New Issue
Block a user