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:
parent
63b4d20bdf
commit
43fce29a04
@ -156,14 +156,18 @@ class StockController(AccountsController):
|
|||||||
if self.doctype == "Stock Reconciliation":
|
if self.doctype == "Stock Reconciliation":
|
||||||
qty = row.qty
|
qty = row.qty
|
||||||
type_of_transaction = "Inward"
|
type_of_transaction = "Inward"
|
||||||
|
warehouse = row.warehouse
|
||||||
else:
|
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)
|
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(
|
sn_doc = SerialBatchCreation(
|
||||||
{
|
{
|
||||||
"item_code": row.item_code,
|
"item_code": row.item_code,
|
||||||
"warehouse": row.warehouse,
|
"warehouse": warehouse,
|
||||||
"posting_date": self.posting_date,
|
"posting_date": self.posting_date,
|
||||||
"posting_time": self.posting_time,
|
"posting_time": self.posting_time,
|
||||||
"voucher_type": self.doctype,
|
"voucher_type": self.doctype,
|
||||||
|
@ -977,6 +977,9 @@ class StockEntry(StockController):
|
|||||||
already_picked_serial_nos = []
|
already_picked_serial_nos = []
|
||||||
|
|
||||||
for row in self.items:
|
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:
|
if not row.s_warehouse:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
|
@ -92,9 +92,6 @@ def make_stock_entry(**args):
|
|||||||
else:
|
else:
|
||||||
args.qty = cint(args.qty)
|
args.qty = cint(args.qty)
|
||||||
|
|
||||||
if args.serial_no or args.batch_no:
|
|
||||||
args.use_serial_batch_fields = True
|
|
||||||
|
|
||||||
# purpose
|
# purpose
|
||||||
if not args.purpose:
|
if not args.purpose:
|
||||||
if args.source and args.target:
|
if args.source and args.target:
|
||||||
@ -136,7 +133,7 @@ def make_stock_entry(**args):
|
|||||||
serial_number = args.serial_no
|
serial_number = args.serial_no
|
||||||
|
|
||||||
bundle_id = None
|
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({})
|
batches = frappe._dict({})
|
||||||
if args.batch_no:
|
if args.batch_no:
|
||||||
batches = frappe._dict({args.batch_no: args.qty})
|
batches = frappe._dict({args.batch_no: args.qty})
|
||||||
@ -164,6 +161,10 @@ def make_stock_entry(**args):
|
|||||||
.name
|
.name
|
||||||
)
|
)
|
||||||
|
|
||||||
|
args["serial_no"] = ""
|
||||||
|
args["batch_no"] = ""
|
||||||
|
|
||||||
|
else:
|
||||||
args.serial_no = serial_number
|
args.serial_no = serial_number
|
||||||
|
|
||||||
s.append(
|
s.append(
|
||||||
|
@ -1587,6 +1587,7 @@ class TestStockEntry(FrappeTestCase):
|
|||||||
qty=4,
|
qty=4,
|
||||||
to_warehouse="_Test Warehouse - _TC",
|
to_warehouse="_Test Warehouse - _TC",
|
||||||
batch_no=batch.name,
|
batch_no=batch.name,
|
||||||
|
use_serial_batch_fields=1,
|
||||||
do_not_save=True,
|
do_not_save=True,
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -1745,6 +1746,51 @@ class TestStockEntry(FrappeTestCase):
|
|||||||
mr.cancel()
|
mr.cancel()
|
||||||
mr.delete()
|
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):
|
def make_serialized_item(**args):
|
||||||
args = frappe._dict(args)
|
args = frappe._dict(args)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user