Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: batch reset while making SABB (backport #42076) #42123

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -646,6 +646,61 @@ def test_serial_no_valuation_for_legacy_ledgers(self):

self.assertEqual(flt(stock_value_difference, 2), 353.0 * -1)

def test_pick_serial_nos_for_batch_item(self):
item_code = make_item(
"Test Pick Serial Nos for Batch Item 1",
properties={
"is_stock_item": 1,
"has_batch_no": 1,
"create_new_batch": 1,
"batch_no_series": "PSNBI-TSNVL-.#####",
"has_serial_no": 1,
"serial_no_series": "SN-PSNBI-TSNVL-.#####",
},
).name

se = make_stock_entry(
item_code=item_code,
qty=10,
target="_Test Warehouse - _TC",
rate=500,
)

batch1 = get_batch_from_bundle(se.items[0].serial_and_batch_bundle)
serial_nos1 = get_serial_nos_from_bundle(se.items[0].serial_and_batch_bundle)

se = make_stock_entry(
item_code=item_code,
qty=10,
target="_Test Warehouse - _TC",
rate=500,
)

batch2 = get_batch_from_bundle(se.items[0].serial_and_batch_bundle)
serial_nos2 = get_serial_nos_from_bundle(se.items[0].serial_and_batch_bundle)

se = make_stock_entry(
item_code=item_code,
qty=10,
source="_Test Warehouse - _TC",
use_serial_batch_fields=True,
batch_no=batch2,
)

serial_nos = get_serial_nos_from_bundle(se.items[0].serial_and_batch_bundle)
self.assertEqual(serial_nos, serial_nos2)

se = make_stock_entry(
item_code=item_code,
qty=10,
source="_Test Warehouse - _TC",
use_serial_batch_fields=True,
batch_no=batch1,
)

serial_nos = get_serial_nos_from_bundle(se.items[0].serial_and_batch_bundle)
self.assertEqual(serial_nos, serial_nos1)


def get_batch_from_bundle(bundle):
from erpnext.stock.serial_batch_bundle import get_batch_nos
Expand Down
12 changes: 11 additions & 1 deletion erpnext/stock/serial_batch_bundle.py
Original file line number Diff line number Diff line change
Expand Up @@ -950,7 +950,17 @@ def set_auto_serial_batch_entries_for_outward(self):
if self.get("ignore_serial_nos"):
kwargs["ignore_serial_nos"] = self.ignore_serial_nos

if self.has_serial_no and not self.get("serial_nos"):
if (
self.has_serial_no
and self.has_batch_no
and not self.get("serial_nos")
and self.get("batches")
and len(self.get("batches")) == 1
):
# If only one batch is available and no serial no is available
kwargs["batches"] = next(iter(self.get("batches").keys()))
self.serial_nos = get_serial_nos_for_outward(kwargs)
elif self.has_serial_no and not self.get("serial_nos"):
self.serial_nos = get_serial_nos_for_outward(kwargs)
elif not self.has_serial_no and self.has_batch_no and not self.get("batches"):
self.batches = get_available_batches(kwargs)
Expand Down
Loading