Skip to content

Commit

Permalink
fix: stock entry for use serial batch fields
Browse files Browse the repository at this point in the history
  • Loading branch information
rohitwaghchaure committed Feb 11, 2024
1 parent 159a123 commit 1cb71bd
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 7 deletions.
8 changes: 6 additions & 2 deletions erpnext/controllers/stock_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,14 +156,18 @@ def make_bundle_using_old_serial_batch_fields(self):
if self.doctype == "Stock Reconciliation":
qty = row.qty
type_of_transaction = "Inward"
warehouse = row.warehouse
else:
qty = row.stock_qty
qty = row.stock_qty if self.doctype != "Stock Entry" else row.transfer_qty
type_of_transaction = get_type_of_transaction(self, row)
warehouse = (
row.warehouse if self.doctype != "Stock Entry" else row.s_warehouse or row.t_warehouse
)

sn_doc = SerialBatchCreation(
{
"item_code": row.item_code,
"warehouse": row.warehouse,
"warehouse": warehouse,
"posting_date": self.posting_date,
"posting_time": self.posting_time,
"voucher_type": self.doctype,
Expand Down
3 changes: 3 additions & 0 deletions erpnext/stock/doctype/stock_entry/stock_entry.py
Original file line number Diff line number Diff line change
Expand Up @@ -982,6 +982,9 @@ def make_serial_and_batch_bundle_for_outward(self):
already_picked_serial_nos = []

for row in self.items:
if row.use_serial_batch_fields and (row.serial_no or row.batch_no):
continue

if not row.s_warehouse:
continue

Expand Down
11 changes: 6 additions & 5 deletions erpnext/stock/doctype/stock_entry/stock_entry_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,6 @@ def process_serial_numbers(serial_nos_list):
else:
args.qty = cint(args.qty)

if args.serial_no or args.batch_no:
args.use_serial_batch_fields = True

# purpose
if not args.purpose:
if args.source and args.target:
Expand Down Expand Up @@ -136,7 +133,7 @@ def process_serial_numbers(serial_nos_list):
serial_number = args.serial_no

bundle_id = None
if args.serial_no or args.batch_no or args.batches:
if not args.use_serial_batch_fields and (args.serial_no or args.batch_no or args.batches):
batches = frappe._dict({})
if args.batch_no:
batches = frappe._dict({args.batch_no: args.qty})
Expand Down Expand Up @@ -164,7 +161,11 @@ def process_serial_numbers(serial_nos_list):
.name
)

args.serial_no = serial_number
args["serial_no"] = ""
args["batch_no"] = ""

else:
args.serial_no = serial_number

s.append(
"items",
Expand Down
45 changes: 45 additions & 0 deletions erpnext/stock/doctype/stock_entry/test_stock_entry.py
Original file line number Diff line number Diff line change
Expand Up @@ -1754,6 +1754,51 @@ def test_auto_reorder_level(self):
mr.cancel()
mr.delete()

def test_use_serial_and_batch_fields(self):
item = make_item(
"Test Use Serial and Batch Item SN Item",
{"has_serial_no": 1, "is_stock_item": 1},
)

serial_nos = [
"Test Use Serial and Batch Item SN Item - SN 001",
"Test Use Serial and Batch Item SN Item - SN 002",
]

se = make_stock_entry(
item_code=item.name,
qty=2,
to_warehouse="_Test Warehouse - _TC",
use_serial_batch_fields=1,
serial_no="\n".join(serial_nos),
)

self.assertTrue(se.items[0].use_serial_batch_fields)
self.assertFalse(se.items[0].serial_no)
self.assertTrue(se.items[0].serial_and_batch_bundle)

for serial_no in serial_nos:
self.assertTrue(frappe.db.exists("Serial No", serial_no))
self.assertEqual(frappe.db.get_value("Serial No", serial_no, "status"), "Active")

se1 = make_stock_entry(
item_code=item.name,
qty=2,
from_warehouse="_Test Warehouse - _TC",
use_serial_batch_fields=1,
serial_no="\n".join(serial_nos),
)

se1.reload()

self.assertTrue(se1.items[0].use_serial_batch_fields)
self.assertFalse(se1.items[0].serial_no)
self.assertTrue(se1.items[0].serial_and_batch_bundle)

for serial_no in serial_nos:
self.assertTrue(frappe.db.exists("Serial No", serial_no))
self.assertEqual(frappe.db.get_value("Serial No", serial_no, "status"), "Delivered")


def make_serialized_item(**args):
args = frappe._dict(args)
Expand Down

0 comments on commit 1cb71bd

Please sign in to comment.