diff --git a/erpnext/stock/doctype/stock_reconciliation/stock_reconciliation.py b/erpnext/stock/doctype/stock_reconciliation/stock_reconciliation.py index ccc79dece4e..fa3cada5731 100644 --- a/erpnext/stock/doctype/stock_reconciliation/stock_reconciliation.py +++ b/erpnext/stock/doctype/stock_reconciliation/stock_reconciliation.py @@ -877,7 +877,7 @@ class StockReconciliation(StockController): if row.get(dimension.get("fieldname")): has_dimensions = True - if self.docstatus == 2 and (not row.batch_no or not row.serial_and_batch_bundle): + if self.docstatus == 2: if row.current_qty and current_bundle: data.actual_qty = -1 * row.current_qty data.qty_after_transaction = flt(row.current_qty) diff --git a/erpnext/stock/doctype/stock_reconciliation/test_stock_reconciliation.py b/erpnext/stock/doctype/stock_reconciliation/test_stock_reconciliation.py index 01c2e207137..2500b521017 100644 --- a/erpnext/stock/doctype/stock_reconciliation/test_stock_reconciliation.py +++ b/erpnext/stock/doctype/stock_reconciliation/test_stock_reconciliation.py @@ -1657,6 +1657,59 @@ class TestStockReconciliation(IntegrationTestCase, StockTestMixin): batch_qty = get_batch_qty(batch_no, warehouse, item_code) self.assertEqual(batch_qty, 4) + def test_sabb_cancel_on_stock_reco_cancellation(self): + item_code = self.make_item( + "Test Item for SABB Cancel on Stock Reco Cancellation", + { + "is_stock_item": 1, + "has_batch_no": 1, + "create_new_batch": 1, + "batch_number_series": "TEST-BATCH-SABBCANC-.###", + }, + ).name + + warehouse = "_Test Warehouse - _TC" + + sr = create_stock_reconciliation( + item_code=item_code, + warehouse=warehouse, + qty=10, + rate=100, + use_serial_batch_fields=1, + ) + + sr.reload() + + batch_no = get_batch_from_bundle(sr.items[0].serial_and_batch_bundle) + + sr1 = create_stock_reconciliation( + item_code=item_code, + warehouse=warehouse, + qty=20, + rate=100, + use_serial_batch_fields=1, + batch_no=batch_no, + ) + + sr1.reload() + + current_serial_and_batch_bundle = sr1.items[0].current_serial_and_batch_bundle + serial_and_batch_bundle = sr1.items[0].serial_and_batch_bundle + + self.assertTrue(current_serial_and_batch_bundle) + self.assertTrue(serial_and_batch_bundle) + + sr1.cancel() + + for sabb in [serial_and_batch_bundle, current_serial_and_batch_bundle]: + docstatus = frappe.db.get_value( + "Serial and Batch Bundle", + sabb, + "docstatus", + ) + + self.assertEqual(docstatus, 2) + def create_batch_item_with_batch(item_name, batch_id): batch_item_doc = create_item(item_name, is_stock_item=1)