fix: stock entry for use serial batch fields (backport #39843) (#39844)

fix: stock entry for use serial batch fields (#39843)

(cherry picked from commit e5824fc3f1f862ab625eea19f27f61ab74e0708d)

Co-authored-by: rohitwaghchaure <rohitw1991@gmail.com>
This commit is contained in:
mergify[bot] 2024-02-11 11:28:48 +05:30 committed by GitHub
parent 63b4d20bdf
commit 43fce29a04
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 61 additions and 7 deletions

View File

@ -156,14 +156,18 @@ class StockController(AccountsController):
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,

View File

@ -977,6 +977,9 @@ class StockEntry(StockController):
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

View File

@ -92,9 +92,6 @@ def make_stock_entry(**args):
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:
@ -136,7 +133,7 @@ def make_stock_entry(**args):
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})
@ -164,7 +161,11 @@ def make_stock_entry(**args):
.name
)
args.serial_no = serial_number
args["serial_no"] = ""
args["batch_no"] = ""
else:
args.serial_no = serial_number
s.append(
"items",

View File

@ -1587,6 +1587,7 @@ class TestStockEntry(FrappeTestCase):
qty=4,
to_warehouse="_Test Warehouse - _TC",
batch_no=batch.name,
use_serial_batch_fields=1,
do_not_save=True,
)
@ -1745,6 +1746,51 @@ class TestStockEntry(FrappeTestCase):
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)