Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: do not delete batches implicitly #39548

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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
Loading