fix: do not make serial batch bundle for zero qty (#38949) (cherry picked from commit 06d6220a2aa2f7855db2c2f985d046280e26f13a) Co-authored-by: rohitwaghchaure <rohitw1991@gmail.com>
This commit is contained in:
parent
f704ccbb59
commit
a41cf62437
@ -85,6 +85,7 @@ class SerialandBatchBundle(Document):
|
|||||||
# end: auto-generated types
|
# end: auto-generated types
|
||||||
|
|
||||||
def validate(self):
|
def validate(self):
|
||||||
|
self.set_batch_no()
|
||||||
self.validate_serial_and_batch_no()
|
self.validate_serial_and_batch_no()
|
||||||
self.validate_duplicate_serial_and_batch_no()
|
self.validate_duplicate_serial_and_batch_no()
|
||||||
self.validate_voucher_no()
|
self.validate_voucher_no()
|
||||||
@ -99,6 +100,26 @@ class SerialandBatchBundle(Document):
|
|||||||
self.set_incoming_rate()
|
self.set_incoming_rate()
|
||||||
self.calculate_qty_and_amount()
|
self.calculate_qty_and_amount()
|
||||||
|
|
||||||
|
def set_batch_no(self):
|
||||||
|
if self.has_serial_no and self.has_batch_no:
|
||||||
|
serial_nos = [d.serial_no for d in self.entries if d.serial_no]
|
||||||
|
has_no_batch = any(not d.batch_no for d in self.entries)
|
||||||
|
if not has_no_batch:
|
||||||
|
return
|
||||||
|
|
||||||
|
serial_no_batch = frappe._dict(
|
||||||
|
frappe.get_all(
|
||||||
|
"Serial No",
|
||||||
|
filters={"name": ("in", serial_nos)},
|
||||||
|
fields=["name", "batch_no"],
|
||||||
|
as_list=True,
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
for row in self.entries:
|
||||||
|
if not row.batch_no:
|
||||||
|
row.batch_no = serial_no_batch.get(row.serial_no)
|
||||||
|
|
||||||
def validate_serial_nos_inventory(self):
|
def validate_serial_nos_inventory(self):
|
||||||
if not (self.has_serial_no and self.type_of_transaction == "Outward"):
|
if not (self.has_serial_no and self.type_of_transaction == "Outward"):
|
||||||
return
|
return
|
||||||
|
@ -171,7 +171,7 @@ class StockReconciliation(StockController):
|
|||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
|
||||||
if item_details.has_batch_no:
|
elif item_details.has_batch_no:
|
||||||
batch_nos_details = get_available_batches(
|
batch_nos_details = get_available_batches(
|
||||||
frappe._dict(
|
frappe._dict(
|
||||||
{
|
{
|
||||||
@ -228,6 +228,9 @@ class StockReconciliation(StockController):
|
|||||||
|
|
||||||
def set_new_serial_and_batch_bundle(self):
|
def set_new_serial_and_batch_bundle(self):
|
||||||
for item in self.items:
|
for item in self.items:
|
||||||
|
if not item.qty:
|
||||||
|
continue
|
||||||
|
|
||||||
if item.current_serial_and_batch_bundle and not item.serial_and_batch_bundle:
|
if item.current_serial_and_batch_bundle and not item.serial_and_batch_bundle:
|
||||||
current_doc = frappe.get_doc("Serial and Batch Bundle", item.current_serial_and_batch_bundle)
|
current_doc = frappe.get_doc("Serial and Batch Bundle", item.current_serial_and_batch_bundle)
|
||||||
|
|
||||||
|
@ -865,6 +865,66 @@ class TestStockReconciliation(FrappeTestCase, StockTestMixin):
|
|||||||
sr1.load_from_db()
|
sr1.load_from_db()
|
||||||
self.assertEqual(sr1.difference_amount, 10000)
|
self.assertEqual(sr1.difference_amount, 10000)
|
||||||
|
|
||||||
|
def test_make_stock_zero_for_serial_batch_item(self):
|
||||||
|
from erpnext.stock.doctype.stock_entry.test_stock_entry import make_stock_entry
|
||||||
|
|
||||||
|
serial_item = self.make_item(
|
||||||
|
properties={"is_stock_item": 1, "has_serial_no": 1, "serial_no_series": "DJJ.####"}
|
||||||
|
).name
|
||||||
|
batch_item = self.make_item(
|
||||||
|
properties={
|
||||||
|
"is_stock_item": 1,
|
||||||
|
"has_batch_no": 1,
|
||||||
|
"batch_number_series": "BDJJ.####",
|
||||||
|
"create_new_batch": 1,
|
||||||
|
}
|
||||||
|
).name
|
||||||
|
|
||||||
|
serial_batch_item = self.make_item(
|
||||||
|
properties={
|
||||||
|
"is_stock_item": 1,
|
||||||
|
"has_batch_no": 1,
|
||||||
|
"batch_number_series": "ADJJ.####",
|
||||||
|
"create_new_batch": 1,
|
||||||
|
"has_serial_no": 1,
|
||||||
|
"serial_no_series": "SN-ADJJ.####",
|
||||||
|
}
|
||||||
|
).name
|
||||||
|
|
||||||
|
warehouse = "_Test Warehouse - _TC"
|
||||||
|
|
||||||
|
for item_code in [serial_item, batch_item, serial_batch_item]:
|
||||||
|
make_stock_entry(
|
||||||
|
item_code=item_code,
|
||||||
|
target=warehouse,
|
||||||
|
qty=10,
|
||||||
|
basic_rate=100,
|
||||||
|
)
|
||||||
|
|
||||||
|
_reco = create_stock_reconciliation(
|
||||||
|
item_code=item_code,
|
||||||
|
warehouse=warehouse,
|
||||||
|
qty=0.0,
|
||||||
|
)
|
||||||
|
|
||||||
|
serial_batch_bundle = frappe.get_all(
|
||||||
|
"Stock Ledger Entry",
|
||||||
|
{"item_code": item_code, "warehouse": warehouse, "is_cancelled": 0, "voucher_no": _reco.name},
|
||||||
|
"serial_and_batch_bundle",
|
||||||
|
)
|
||||||
|
|
||||||
|
self.assertEqual(len(serial_batch_bundle), 1)
|
||||||
|
|
||||||
|
_reco.cancel()
|
||||||
|
|
||||||
|
serial_batch_bundle = frappe.get_all(
|
||||||
|
"Stock Ledger Entry",
|
||||||
|
{"item_code": item_code, "warehouse": warehouse, "is_cancelled": 0, "voucher_no": _reco.name},
|
||||||
|
"serial_and_batch_bundle",
|
||||||
|
)
|
||||||
|
|
||||||
|
self.assertEqual(len(serial_batch_bundle), 0)
|
||||||
|
|
||||||
|
|
||||||
def create_batch_item_with_batch(item_name, batch_id):
|
def create_batch_item_with_batch(item_name, batch_id):
|
||||||
batch_item_doc = create_item(item_name, is_stock_item=1)
|
batch_item_doc = create_item(item_name, is_stock_item=1)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user