Skip to content

Commit

Permalink
Merge pull request #39548 from rohitwaghchaure/fix-do-not-delete-batc…
Browse files Browse the repository at this point in the history
…h-implicitly

fix: do not delete batches implicitly
  • Loading branch information
rohitwaghchaure authored Jan 25, 2024
2 parents 22c13b1 + 9a5995a commit 822a5a8
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 8 deletions.
5 changes: 0 additions & 5 deletions erpnext/controllers/stock_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -402,11 +402,6 @@ def delete_auto_created_batches(self):
d.batch_no = None
d.db_set("batch_no", None)

for data in frappe.get_all(
"Batch", {"reference_name": self.name, "reference_doctype": self.doctype}
):
frappe.delete_doc("Batch", data.name)

def get_sl_entries(self, d, args):
sl_dict = frappe._dict(
{
Expand Down
14 changes: 13 additions & 1 deletion erpnext/stock/doctype/purchase_receipt/test_purchase_receipt.py
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,6 @@ def test_batched_serial_no_purchase(self):
batch_no = pr.items[0].batch_no
pr.cancel()

self.assertFalse(frappe.db.get_value("Batch", {"item": item.name, "reference_name": pr.name}))
self.assertFalse(frappe.db.get_all("Serial No", {"batch_no": batch_no}))

def test_purchase_receipt_gl_entry(self):
Expand Down Expand Up @@ -2172,6 +2171,19 @@ def non_internal_transfer_purchase_receipt(self):
pr_doc.reload()
self.assertFalse(pr_doc.items[0].from_warehouse)

def test_do_not_delete_batch_implicitly(self):
item = make_item(
"_Test Item With Delete Batch",
{"has_batch_no": 1, "create_new_batch": 1, "batch_number_series": "TBWDB.#####"},
).name

pr = make_purchase_receipt(item_code=item, qty=10, rate=100)
batch_no = pr.items[0].batch_no
self.assertTrue(frappe.db.exists("Batch", batch_no))

pr.cancel()
self.assertTrue(frappe.db.exists("Batch", batch_no))


def prepare_data_for_internal_transfer():
from erpnext.accounts.doctype.sales_invoice.test_sales_invoice import create_internal_supplier
Expand Down
2 changes: 1 addition & 1 deletion erpnext/stock/doctype/stock_entry/test_stock_entry.py
Original file line number Diff line number Diff line change
Expand Up @@ -737,7 +737,7 @@ def test_serial_batch_item_stock_entry(self):
self.assertEqual(batch_in_serial_no, None)

self.assertEqual(frappe.db.get_value("Serial No", serial_no, "status"), "Inactive")
self.assertEqual(frappe.db.exists("Batch", batch_no), None)
self.assertTrue(frappe.db.exists("Batch", batch_no))

def test_serial_batch_item_qty_deduction(self):
"""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,7 @@ def test_stock_reco_for_serial_and_batch_item(self):
sr.cancel()

self.assertEqual(frappe.db.get_value("Serial No", serial_nos[0], "status"), "Inactive")
self.assertEqual(frappe.db.exists("Batch", batch_no), None)
self.assertTrue(frappe.db.exists("Batch", batch_no))

def test_stock_reco_balance_qty_for_serial_and_batch_item(self):
from erpnext.stock.doctype.stock_entry.stock_entry_utils import make_stock_entry
Expand Down

0 comments on commit 822a5a8

Please sign in to comment.