fix: remove from or target warehouse for non internal transfer entries (#37612)
diff --git a/erpnext/controllers/stock_controller.py b/erpnext/controllers/stock_controller.py
index 98d8248..61d7107 100644
--- a/erpnext/controllers/stock_controller.py
+++ b/erpnext/controllers/stock_controller.py
@@ -689,13 +689,21 @@
d.stock_uom_rate = d.rate / (d.conversion_factor or 1)
def validate_internal_transfer(self):
- if (
- self.doctype in ("Sales Invoice", "Delivery Note", "Purchase Invoice", "Purchase Receipt")
- and self.is_internal_transfer()
- ):
- self.validate_in_transit_warehouses()
- self.validate_multi_currency()
- self.validate_packed_items()
+ if self.doctype in ("Sales Invoice", "Delivery Note", "Purchase Invoice", "Purchase Receipt"):
+ if self.is_internal_transfer():
+ self.validate_in_transit_warehouses()
+ self.validate_multi_currency()
+ self.validate_packed_items()
+ else:
+ self.validate_internal_transfer_warehouse()
+
+ def validate_internal_transfer_warehouse(self):
+ for row in self.items:
+ if row.get("target_warehouse"):
+ row.target_warehouse = None
+
+ if row.get("from_warehouse"):
+ row.from_warehouse = None
def validate_in_transit_warehouses(self):
if (
diff --git a/erpnext/stock/doctype/delivery_note/test_delivery_note.py b/erpnext/stock/doctype/delivery_note/test_delivery_note.py
index 48b8ab7..d068192 100644
--- a/erpnext/stock/doctype/delivery_note/test_delivery_note.py
+++ b/erpnext/stock/doctype/delivery_note/test_delivery_note.py
@@ -1230,6 +1230,21 @@
frappe.db.rollback()
frappe.db.set_single_value("Selling Settings", "dont_reserve_sales_order_qty_on_sales_return", 0)
+ def non_internal_transfer_delivery_note(self):
+ from erpnext.stock.doctype.warehouse.test_warehouse import create_warehouse
+
+ dn = create_delivery_note(do_not_submit=True)
+ warehouse = create_warehouse("Internal Transfer Warehouse", dn.company)
+ dn.items[0].db_set("target_warehouse", "warehouse")
+
+ dn.reload()
+
+ self.assertEqual(dn.items[0].target_warehouse, warehouse.name)
+
+ dn.save()
+ dn.reload()
+ self.assertFalse(dn.items[0].target_warehouse)
+
def create_delivery_note(**args):
dn = frappe.new_doc("Delivery Note")
diff --git a/erpnext/stock/doctype/purchase_receipt/test_purchase_receipt.py b/erpnext/stock/doctype/purchase_receipt/test_purchase_receipt.py
index cdf5053..1af7b9a 100644
--- a/erpnext/stock/doctype/purchase_receipt/test_purchase_receipt.py
+++ b/erpnext/stock/doctype/purchase_receipt/test_purchase_receipt.py
@@ -2142,6 +2142,21 @@
for entry in gl_entries:
self.assertEqual(abs(entry.debit + entry.credit), abs(sl_entries[0].stock_value_difference))
+ def non_internal_transfer_purchase_receipt(self):
+ from erpnext.stock.doctype.warehouse.test_warehouse import create_warehouse
+
+ pr_doc = make_purchase_receipt(do_not_submit=True)
+ warehouse = create_warehouse("Internal Transfer Warehouse", pr_doc.company)
+ pr_doc.items[0].db_set("target_warehouse", "warehouse")
+
+ pr_doc.reload()
+
+ self.assertEqual(pr_doc.items[0].from_warehouse, warehouse.name)
+
+ pr_doc.save()
+ pr_doc.reload()
+ self.assertFalse(pr_doc.items[0].from_warehouse)
+
def prepare_data_for_internal_transfer():
from erpnext.accounts.doctype.sales_invoice.test_sales_invoice import create_internal_supplier