Skip to content

Commit

Permalink
fix: incorrect Balance Qty in the stock ledger for the item with Seri…
Browse files Browse the repository at this point in the history
…al and Batch no
  • Loading branch information
rohitwaghchaure committed Jul 17, 2023
1 parent 665898a commit 373b868
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,30 @@ def test_stock_reco_for_serial_and_batch_item(self):
self.assertEqual(frappe.db.get_value("Serial No", serial_nos[0], "status"), "Inactive")
self.assertEqual(frappe.db.exists("Batch", batch_no), None)

def test_stock_reco_balance_qty_for_serial_and_batch_item(self):
from erpnext.stock.doctype.stock_entry.stock_entry_utils import make_stock_entry

item = create_item("_TestBatchSerialItemReco_1")
item.has_batch_no = 1
item.create_new_batch = 1
item.has_serial_no = 1
item.batch_number_series = "TBS-BATCH1-.##"
item.serial_no_series = "TBS1-.####"
item.save()

warehouse = "_Test Warehouse for Stock Reco2"
warehouse = create_warehouse(warehouse)

make_stock_entry(item_code=item.name, target=warehouse, qty=10, basic_rate=100)

sr = create_stock_reconciliation(item_code=item.name, warehouse=warehouse, qty=10, rate=200)

qty_after_transaction = frappe.db.get_value(
"Stock Ledger Entry", {"voucher_no": sr.name, "is_cancelled": 0}, "qty_after_transaction"
)

self.assertEqual(qty_after_transaction, 20)

def test_stock_reco_for_serial_and_batch_item_with_future_dependent_entry(self):
"""
Behaviour: 1) Create Stock Reconciliation, which will be the origin document
Expand Down
2 changes: 1 addition & 1 deletion erpnext/stock/stock_ledger.py
Original file line number Diff line number Diff line change
Expand Up @@ -579,7 +579,7 @@ def process_sle(self, sle):
if get_serial_nos(sle.serial_no):
self.get_serialized_values(sle)
self.wh_data.qty_after_transaction += flt(sle.actual_qty)
if sle.voucher_type == "Stock Reconciliation":
if sle.voucher_type == "Stock Reconciliation" and not sle.batch_no:
self.wh_data.qty_after_transaction = sle.qty_after_transaction

self.wh_data.stock_value = flt(self.wh_data.qty_after_transaction) * flt(
Expand Down

0 comments on commit 373b868

Please sign in to comment.