Skip to content

Commit

Permalink
Merge pull request #23675 from rohitwaghchaure/feat-added-balance-ser…
Browse files Browse the repository at this point in the history
…ial-no-column-develop

 feat: balance serial nos in stock ledger report
  • Loading branch information
rohitwaghchaure authored Oct 24, 2020
2 parents 434791e + 9ff4a2e commit 8be296b
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 3 deletions.
3 changes: 1 addition & 2 deletions erpnext/stock/doctype/item/item.py
Original file line number Diff line number Diff line change
Expand Up @@ -1188,8 +1188,7 @@ def invalidate_item_variants_cache_for_website(doc):

if item_code:
item_cache = ItemVariantsCacheManager(item_code)
item_cache.clear_cache()

item_cache.rebuild_cache()

def check_stock_uom_with_bin(item, stock_uom):
if stock_uom == frappe.db.get_value("Item", item, "stock_uom"):
Expand Down
28 changes: 27 additions & 1 deletion erpnext/stock/report/stock_ledger/stock_ledger.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from frappe.utils import cint, flt
from erpnext.stock.utils import update_included_uom_in_report
from frappe import _
from erpnext.stock.doctype.serial_no.serial_no import get_serial_nos

def execute(filters=None):
include_uom = filters.get("include_uom")
Expand All @@ -24,6 +25,7 @@ def execute(filters=None):

actual_qty = stock_value = 0

available_serial_nos = {}
for sle in sl_entries:
item_detail = item_details[sle.item_code]

Expand All @@ -47,6 +49,9 @@ def execute(filters=None):
"out_qty": min(sle.actual_qty, 0)
})

if sle.serial_no:
update_available_serial_nos(available_serial_nos, sle)

data.append(sle)

if include_uom:
Expand All @@ -55,6 +60,26 @@ def execute(filters=None):
update_included_uom_in_report(columns, data, include_uom, conversion_factors)
return columns, data

def update_available_serial_nos(available_serial_nos, sle):
serial_nos = get_serial_nos(sle.serial_no)
key = (sle.item_code, sle.warehouse)
if key not in available_serial_nos:
available_serial_nos.setdefault(key, [])

existing_serial_no = available_serial_nos[key]
for sn in serial_nos:
if sle.actual_qty > 0:
if sn in existing_serial_no:
existing_serial_no.remove(sn)
else:
existing_serial_no.append(sn)
else:
if sn in existing_serial_no:
existing_serial_no.remove(sn)
else:
existing_serial_no.append(sn)

sle.balance_serial_no = '\n'.join(existing_serial_no)

def get_columns():
columns = [
Expand All @@ -76,7 +101,8 @@ def get_columns():
{"label": _("Voucher Type"), "fieldname": "voucher_type", "width": 110},
{"label": _("Voucher #"), "fieldname": "voucher_no", "fieldtype": "Dynamic Link", "options": "voucher_type", "width": 100},
{"label": _("Batch"), "fieldname": "batch_no", "fieldtype": "Link", "options": "Batch", "width": 100},
{"label": _("Serial #"), "fieldname": "serial_no", "fieldtype": "Link", "options": "Serial No", "width": 100},
{"label": _("Serial No"), "fieldname": "serial_no", "fieldtype": "Link", "options": "Serial No", "width": 100},
{"label": _("Balance Serial No"), "fieldname": "balance_serial_no", "width": 100},
{"label": _("Project"), "fieldname": "project", "fieldtype": "Link", "options": "Project", "width": 100},
{"label": _("Company"), "fieldname": "company", "fieldtype": "Link", "options": "Company", "width": 110}
]
Expand Down

0 comments on commit 8be296b

Please sign in to comment.