Skip to content

Commit

Permalink
fix: Auto Create Serial and Batch Bundle For Outward
Browse files Browse the repository at this point in the history
  • Loading branch information
rohitwaghchaure committed Aug 15, 2024
1 parent 17ba0cf commit 018ed70
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -701,6 +701,57 @@ def test_pick_serial_nos_for_batch_item(self):
serial_nos = get_serial_nos_from_bundle(se.items[0].serial_and_batch_bundle)
self.assertEqual(serial_nos, serial_nos1)

def test_auto_create_serial_and_batch_bundle_for_outward_for_batch_item(self):
item_code = make_item(
"Test Auto Create Batch Bundle for Outward 1",
properties={
"is_stock_item": 1,
"has_batch_no": 1,
"batch_number_series": "ACSBBO-TACSB-.#####",
},
).name

if not frappe.db.exists("Batch", "ACSBBO-TACSB-00001"):
frappe.get_doc(
{
"doctype": "Batch",
"batch_id": "ACSBBO-TACSB-00001",
"item": item_code,
"company": "_Test Company",
}
).insert(ignore_permissions=True)

make_stock_entry(
item_code=item_code,
qty=10,
target="_Test Warehouse - _TC",
rate=500,
use_serial_batch_fields=True,
batch_no="ACSBBO-TACSB-00001",
)

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

original_value = frappe.db.get_single_value(
"Stock Settings", "auto_create_serial_and_batch_bundle_for_outward"
)

frappe.db.set_single_value("Stock Settings", "auto_create_serial_and_batch_bundle_for_outward", 0)
self.assertRaises(frappe.ValidationError, dispatch.submit)

frappe.db.set_single_value("Stock Settings", "auto_create_serial_and_batch_bundle_for_outward", 1)
dispatch.submit()

frappe.db.set_single_value(
"Stock Settings", "auto_create_serial_and_batch_bundle_for_outward", original_value
)


def get_batch_from_bundle(bundle):
from erpnext.stock.serial_batch_bundle import get_batch_nos
Expand Down
10 changes: 9 additions & 1 deletion erpnext/stock/serial_batch_bundle.py
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,15 @@ def process_batch_no(self):
not self.sle.is_cancelled
and not self.sle.serial_and_batch_bundle
and self.item_details.has_batch_no == 1
and self.item_details.create_new_batch
and (
self.item_details.create_new_batch
or (
frappe.db.get_single_value(
"Stock Settings", "auto_create_serial_and_batch_bundle_for_outward"
)
and self.sle.actual_qty < 0
)
)
):
self.make_serial_batch_no_bundle()
elif not self.sle.is_cancelled:
Expand Down

0 comments on commit 018ed70

Please sign in to comment.