Skip to content

Commit

Permalink
refactor: shows opening balance from filtered from_date (#26877)
Browse files Browse the repository at this point in the history
* refactor: shows opening balance from filtered from_date

* refactor: opening balance considered from filtered from_date in stock ledger

* fix: check if stock reco is opening and misc cleanups

(cherry picked from commit fdaf93f)
  • Loading branch information
noahjacob authored and mergify-bot committed Oct 23, 2021
1 parent 943def5 commit ce5f806
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
4 changes: 3 additions & 1 deletion erpnext/stock/report/stock_balance/stock_balance.py
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,9 @@ def get_item_warehouse_map(filters, sle):

value_diff = flt(d.stock_value_difference)

if d.posting_date < from_date:
if d.posting_date < from_date or (d.posting_date == from_date
and d.voucher_type == "Stock Reconciliation" and
frappe.db.get_value("Stock Reconciliation", d.voucher_no, "purpose") == "Opening Stock"):
qty_dict.opening_qty += qty_diff
qty_dict.opening_val += value_diff

Expand Down
13 changes: 11 additions & 2 deletions erpnext/stock/report/stock_ledger/stock_ledger.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def execute(filters=None):
items = get_items(filters)
sl_entries = get_stock_ledger_entries(filters, items)
item_details = get_item_details(items, sl_entries, include_uom)
opening_row = get_opening_balance(filters, columns)
opening_row = get_opening_balance(filters, columns, sl_entries)
precision = cint(frappe.db.get_single_value("System Settings", "float_precision"))

data = []
Expand Down Expand Up @@ -218,7 +218,7 @@ def get_sle_conditions(filters):
return "and {}".format(" and ".join(conditions)) if conditions else ""


def get_opening_balance(filters, columns):
def get_opening_balance(filters, columns, sl_entries):
if not (filters.item_code and filters.warehouse and filters.from_date):
return

Expand All @@ -230,6 +230,15 @@ def get_opening_balance(filters, columns):
"posting_time": "00:00:00"
})

# check if any SLEs are actually Opening Stock Reconciliation
for sle in sl_entries:
if (sle.get("voucher_type") == "Stock Reconciliation"
and sle.get("date").split()[0] == filters.from_date
and frappe.db.get_value("Stock Reconciliation", sle.voucher_no, "purpose") == "Opening Stock"
):
last_entry = sle
sl_entries.remove(sle)

row = {
"item_code": _("'Opening'"),
"qty_after_transaction": last_entry.get("qty_after_transaction", 0),
Expand Down

0 comments on commit ce5f806

Please sign in to comment.