From 85796b35348d0bbce3c0cfd78096c683e01ec29c Mon Sep 17 00:00:00 2001 From: Rohit Waghchaure Date: Wed, 17 Apr 2024 17:07:19 +0530 Subject: [PATCH] fix: validation for zero qty in SABB (cherry picked from commit 497f560b4b08e8722d80a4ebb11f66e0ae0c9299) --- .../assets/doctype/asset_repair/test_asset_repair.py | 1 + erpnext/stock/doctype/batch/test_batch.py | 4 ++++ .../purchase_receipt/test_purchase_receipt.py | 1 + .../serial_and_batch_bundle.py | 12 ++++++++++++ .../stock_ledger_entry/test_stock_ledger_entry.py | 2 +- .../test_stock_reconciliation.py | 2 +- 6 files changed, 20 insertions(+), 2 deletions(-) diff --git a/erpnext/assets/doctype/asset_repair/test_asset_repair.py b/erpnext/assets/doctype/asset_repair/test_asset_repair.py index 3a5acbe0322..278da1b08bf 100644 --- a/erpnext/assets/doctype/asset_repair/test_asset_repair.py +++ b/erpnext/assets/doctype/asset_repair/test_asset_repair.py @@ -305,6 +305,7 @@ def create_asset_repair(**args): "serial_nos": args.serial_no, "posting_date": today(), "posting_time": nowtime(), + "do_not_submit": 1, } ) ).name diff --git a/erpnext/stock/doctype/batch/test_batch.py b/erpnext/stock/doctype/batch/test_batch.py index 3f37b7bf098..3ef0e57c25a 100644 --- a/erpnext/stock/doctype/batch/test_batch.py +++ b/erpnext/stock/doctype/batch/test_batch.py @@ -86,6 +86,7 @@ class TestBatch(FrappeTestCase): "batches": frappe._dict({batch_no: 20}), "type_of_transaction": "Inward", "company": receipt.company, + "do_not_submit": 1, } ) .make_serial_and_batch_bundle() @@ -176,6 +177,7 @@ class TestBatch(FrappeTestCase): "batches": frappe._dict({batch_no: batch_qty}), "type_of_transaction": "Outward", "company": receipt.company, + "do_not_submit": 1, } ) .make_serial_and_batch_bundle() @@ -249,6 +251,7 @@ class TestBatch(FrappeTestCase): "batches": frappe._dict({batch_no: batch_qty}), "type_of_transaction": "Outward", "company": receipt.company, + "do_not_submit": 1, } ) .make_serial_and_batch_bundle() @@ -341,6 +344,7 @@ class TestBatch(FrappeTestCase): "batches": frappe._dict({batch_name: 90}), "type_of_transaction": "Inward", "company": "_Test Company", + "do_not_submit": 1, } ).make_serial_and_batch_bundle() diff --git a/erpnext/stock/doctype/purchase_receipt/test_purchase_receipt.py b/erpnext/stock/doctype/purchase_receipt/test_purchase_receipt.py index e67736253cd..54a695126c7 100644 --- a/erpnext/stock/doctype/purchase_receipt/test_purchase_receipt.py +++ b/erpnext/stock/doctype/purchase_receipt/test_purchase_receipt.py @@ -2968,6 +2968,7 @@ def make_purchase_receipt(**args): "serial_nos": serial_nos, "posting_date": args.posting_date or today(), "posting_time": args.posting_time, + "do_not_submit": 1, } ) ).name diff --git a/erpnext/stock/doctype/serial_and_batch_bundle/serial_and_batch_bundle.py b/erpnext/stock/doctype/serial_and_batch_bundle/serial_and_batch_bundle.py index 286a220c5dd..91951834bf9 100644 --- a/erpnext/stock/doctype/serial_and_batch_bundle/serial_and_batch_bundle.py +++ b/erpnext/stock/doctype/serial_and_batch_bundle/serial_and_batch_bundle.py @@ -596,6 +596,13 @@ class SerialandBatchBundle(Document): serial_batches = {} for row in self.entries: + if not row.qty and row.batch_no and not row.serial_no: + frappe.throw( + _("At row {0}: Qty is mandatory for the batch {1}").format( + bold(row.idx), bold(row.batch_no) + ) + ) + if self.has_serial_no and not row.serial_no: frappe.throw( _("At row {0}: Serial No is mandatory for Item {1}").format( @@ -831,7 +838,12 @@ class SerialandBatchBundle(Document): for batch in batches: frappe.db.set_value("Batch", batch.name, {"reference_name": None, "reference_doctype": None}) + def validate_serial_and_batch_data(self): + if not self.voucher_no: + frappe.throw(_("Voucher No is mandatory")) + def before_submit(self): + self.validate_serial_and_batch_data() self.validate_serial_and_batch_no_for_returned() self.set_purchase_document_no() diff --git a/erpnext/stock/doctype/stock_ledger_entry/test_stock_ledger_entry.py b/erpnext/stock/doctype/stock_ledger_entry/test_stock_ledger_entry.py index ce50155ffd5..069192fdb16 100644 --- a/erpnext/stock/doctype/stock_ledger_entry/test_stock_ledger_entry.py +++ b/erpnext/stock/doctype/stock_ledger_entry/test_stock_ledger_entry.py @@ -1483,7 +1483,7 @@ def create_delivery_note_entries_for_batchwise_item_valuation_test(dn_entry_list "posting_date": dn.posting_date, "posting_time": dn.posting_time, "voucher_type": "Delivery Note", - "do_not_submit": dn.name, + "do_not_submit": 1, } ) ).name diff --git a/erpnext/stock/doctype/stock_reconciliation/test_stock_reconciliation.py b/erpnext/stock/doctype/stock_reconciliation/test_stock_reconciliation.py index 0ffcdd55fc8..b31ca3046bd 100644 --- a/erpnext/stock/doctype/stock_reconciliation/test_stock_reconciliation.py +++ b/erpnext/stock/doctype/stock_reconciliation/test_stock_reconciliation.py @@ -1085,7 +1085,7 @@ def create_stock_reconciliation(**args): ) bundle_id = None - if not args.use_serial_batch_fields and (args.batch_no or args.serial_no): + if not args.use_serial_batch_fields and (args.batch_no or args.serial_no) and args.qty: batches = frappe._dict({}) if args.batch_no: batches[args.batch_no] = args.qty