From 0b7180146201beda0a0bb0cff30faf0ef2157f31 Mon Sep 17 00:00:00 2001 From: Rohit Waghchaure Date: Fri, 20 Nov 2020 12:59:00 +0530 Subject: [PATCH] fix: incorrect delink serial no and batch --- erpnext/controllers/stock_controller.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/erpnext/controllers/stock_controller.py b/erpnext/controllers/stock_controller.py index 4aa1cad85e..2d2fff8fd5 100644 --- a/erpnext/controllers/stock_controller.py +++ b/erpnext/controllers/stock_controller.py @@ -247,16 +247,17 @@ class StockController(AccountsController): for d in self.items: if not d.batch_no: continue + serial_nos = [sr.name for sr in frappe.get_all("Serial No", + {'batch_no': d.batch_no, 'status': 'Inactive'})] + + if serial_nos: + frappe.db.set_value("Serial No", { 'name': ['in', serial_nos] }, "batch_no", None) + 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}): - - serial_nos = [sr.name for sr in frappe.get_all("Serial No", {'batch_no': data.name})] - if serial_nos: - frappe.db.set_value("Serial No", { 'name': ['in', serial_nos] }, "batch_no", None) - frappe.delete_doc("Batch", data.name) def get_sl_entries(self, d, args):