fix: on cancellation of document cancel the serial and batch bundle (#39076)
This commit is contained in:
parent
d048644327
commit
6e5484ea03
@ -921,11 +921,9 @@ class TestWorkOrder(FrappeTestCase):
|
||||
"Test RM Item 2 for Scrap Item Test",
|
||||
]
|
||||
|
||||
from_time = add_days(now(), -1)
|
||||
job_cards = frappe.get_all(
|
||||
"Job Card Time Log",
|
||||
fields=["distinct parent as name", "docstatus"],
|
||||
filters={"from_time": (">", from_time)},
|
||||
order_by="creation asc",
|
||||
)
|
||||
|
||||
|
@ -85,6 +85,7 @@ class SerialandBatchBundle(Document):
|
||||
# end: auto-generated types
|
||||
|
||||
def validate(self):
|
||||
self.reset_serial_batch_bundle()
|
||||
self.set_batch_no()
|
||||
self.validate_serial_and_batch_no()
|
||||
self.validate_duplicate_serial_and_batch_no()
|
||||
@ -100,6 +101,15 @@ class SerialandBatchBundle(Document):
|
||||
self.set_incoming_rate()
|
||||
self.calculate_qty_and_amount()
|
||||
|
||||
def reset_serial_batch_bundle(self):
|
||||
if self.is_new() and self.amended_from:
|
||||
for field in ["is_cancelled", "is_rejected"]:
|
||||
if self.get(field):
|
||||
self.set(field, 0)
|
||||
|
||||
if self.voucher_detail_no:
|
||||
self.voucher_detail_no = None
|
||||
|
||||
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]
|
||||
@ -914,7 +924,11 @@ def upload_csv_file(item_code, file_path):
|
||||
|
||||
|
||||
def get_serial_batch_from_csv(item_code, file_path):
|
||||
file_path = frappe.get_site_path() + file_path
|
||||
if "private" in file_path:
|
||||
file_path = frappe.get_site_path() + file_path
|
||||
else:
|
||||
file_path = frappe.get_site_path() + "/public" + file_path
|
||||
|
||||
serial_nos = []
|
||||
batch_nos = []
|
||||
|
||||
|
@ -427,11 +427,12 @@ class TestSerialandBatchBundle(FrappeTestCase):
|
||||
from erpnext.stock.doctype.purchase_receipt.test_purchase_receipt import make_purchase_receipt
|
||||
|
||||
item = make_item(
|
||||
"Test Serial and Batch Bundle Company Item",
|
||||
properties={
|
||||
"has_serial_no": 1,
|
||||
"serial_no_series": "TT-SER-VAL-.#####",
|
||||
}
|
||||
)
|
||||
},
|
||||
).name
|
||||
|
||||
pr = make_purchase_receipt(
|
||||
item_code=item,
|
||||
@ -460,6 +461,26 @@ class TestSerialandBatchBundle(FrappeTestCase):
|
||||
sn_doc = add_serial_batch_ledgers(entries, item_row, pr, "_Test Warehouse - _TC")
|
||||
self.assertEqual(sn_doc.company, "_Test Company")
|
||||
|
||||
def test_auto_cancel_serial_and_batch(self):
|
||||
item_code = make_item(
|
||||
properties={"has_serial_no": 1, "serial_no_series": "ATC-TT-SER-VAL-.#####"}
|
||||
).name
|
||||
|
||||
se = make_stock_entry(
|
||||
item_code=item_code,
|
||||
target="_Test Warehouse - _TC",
|
||||
qty=5,
|
||||
rate=500,
|
||||
)
|
||||
|
||||
bundle = se.items[0].serial_and_batch_bundle
|
||||
docstatus = frappe.db.get_value("Serial and Batch Bundle", bundle, "docstatus")
|
||||
self.assertEqual(docstatus, 1)
|
||||
|
||||
se.cancel()
|
||||
docstatus = frappe.db.get_value("Serial and Batch Bundle", bundle, "docstatus")
|
||||
self.assertEqual(docstatus, 2)
|
||||
|
||||
|
||||
def get_batch_from_bundle(bundle):
|
||||
from erpnext.stock.serial_batch_bundle import get_batch_nos
|
||||
|
@ -242,6 +242,12 @@ class SerialBatchBundle:
|
||||
if self.item_details.has_batch_no == 1:
|
||||
self.update_batch_qty()
|
||||
|
||||
if self.sle.is_cancelled and self.sle.serial_and_batch_bundle:
|
||||
self.cancel_serial_and_batch_bundle()
|
||||
|
||||
def cancel_serial_and_batch_bundle(self):
|
||||
frappe.get_cached_doc("Serial and Batch Bundle", self.sle.serial_and_batch_bundle).cancel()
|
||||
|
||||
def submit_serial_and_batch_bundle(self):
|
||||
doc = frappe.get_doc("Serial and Batch Bundle", self.sle.serial_and_batch_bundle)
|
||||
self.validate_actual_qty(doc)
|
||||
|
Loading…
x
Reference in New Issue
Block a user