Opening balance in stock ledger report (#12729)
This commit is contained in:
parent
82fa04ce32
commit
b9ce104b09
@ -106,11 +106,10 @@ def get_opening_balance(filters, columns):
|
||||
from erpnext.stock.stock_ledger import get_previous_sle
|
||||
last_entry = get_previous_sle({
|
||||
"item_code": filters.item_code,
|
||||
"warehouse": get_warehouse_condition(filters.warehouse),
|
||||
"warehouse_condition": get_warehouse_condition(filters.warehouse),
|
||||
"posting_date": filters.from_date,
|
||||
"posting_time": "00:00:00"
|
||||
})
|
||||
|
||||
row = [""]*len(columns)
|
||||
row[1] = _("'Opening'")
|
||||
for i, v in ((9, 'qty_after_transaction'), (11, 'valuation_rate'), (12, 'stock_value')):
|
||||
@ -122,7 +121,7 @@ def get_warehouse_condition(warehouse):
|
||||
warehouse_details = frappe.db.get_value("Warehouse", warehouse, ["lft", "rgt"], as_dict=1)
|
||||
if warehouse_details:
|
||||
return " exists (select name from `tabWarehouse` wh \
|
||||
where wh.lft >= %s and wh.rgt <= %s and sle.warehouse = wh.name)"%(warehouse_details.lft,
|
||||
where wh.lft >= %s and wh.rgt <= %s and warehouse = wh.name)"%(warehouse_details.lft,
|
||||
warehouse_details.rgt)
|
||||
|
||||
return ''
|
||||
|
@ -407,7 +407,12 @@ def get_previous_sle(args, for_update=False):
|
||||
|
||||
def get_stock_ledger_entries(previous_sle, operator=None, order="desc", limit=None, for_update=False, debug=False):
|
||||
"""get stock ledger entries filtered by specific posting datetime conditions"""
|
||||
conditions = "timestamp(posting_date, posting_time) {0} timestamp(%(posting_date)s, %(posting_time)s)".format(operator)
|
||||
conditions = " and timestamp(posting_date, posting_time) {0} timestamp(%(posting_date)s, %(posting_time)s)".format(operator)
|
||||
if previous_sle.get("warehouse"):
|
||||
conditions += " and warehouse = %(warehouse)s"
|
||||
elif previous_sle.get("warehouse_condition"):
|
||||
conditions += " and " + previous_sle.get("warehouse_condition")
|
||||
|
||||
if not previous_sle.get("posting_date"):
|
||||
previous_sle["posting_date"] = "1900-01-01"
|
||||
if not previous_sle.get("posting_time"):
|
||||
@ -418,9 +423,8 @@ def get_stock_ledger_entries(previous_sle, operator=None, order="desc", limit=No
|
||||
|
||||
return frappe.db.sql("""select *, timestamp(posting_date, posting_time) as "timestamp" from `tabStock Ledger Entry`
|
||||
where item_code = %%(item_code)s
|
||||
and warehouse = %%(warehouse)s
|
||||
and ifnull(is_cancelled, 'No')='No'
|
||||
and %(conditions)s
|
||||
%(conditions)s
|
||||
order by timestamp(posting_date, posting_time) %(order)s, name %(order)s
|
||||
%(limit)s %(for_update)s""" % {
|
||||
"conditions": conditions,
|
||||
|
Loading…
x
Reference in New Issue
Block a user