fix: don't set from warehouse for purchase material request (backport #37132) (#37134)
fix: don't set from warehouse for purchase material request (#37132)
(cherry picked from commit e62b783f340844783352030de422c6be14b3ddfc)
Co-authored-by: rohitwaghchaure <rohitw1991@gmail.com>
diff --git a/erpnext/manufacturing/doctype/production_plan/production_plan.js b/erpnext/manufacturing/doctype/production_plan/production_plan.js
index 46c554c..72438dd 100644
--- a/erpnext/manufacturing/doctype/production_plan/production_plan.js
+++ b/erpnext/manufacturing/doctype/production_plan/production_plan.js
@@ -476,6 +476,15 @@
}
})
}
+ },
+
+ material_request_type(frm, cdt, cdn) {
+ let row = locals[cdt][cdn];
+
+ if (row.from_warehouse &&
+ row.material_request_type !== "Material Transfer") {
+ frappe.model.set_value(cdt, cdn, 'from_warehouse', '');
+ }
}
});
diff --git a/erpnext/manufacturing/doctype/production_plan/production_plan.py b/erpnext/manufacturing/doctype/production_plan/production_plan.py
index 7bde29f..e88b791 100644
--- a/erpnext/manufacturing/doctype/production_plan/production_plan.py
+++ b/erpnext/manufacturing/doctype/production_plan/production_plan.py
@@ -40,6 +40,12 @@
self._rename_temporary_references()
validate_uom_is_integer(self, "stock_uom", "planned_qty")
self.validate_sales_orders()
+ self.validate_material_request_type()
+
+ def validate_material_request_type(self):
+ for row in self.get("mr_items"):
+ if row.from_warehouse and row.material_request_type != "Material Transfer":
+ row.from_warehouse = ""
@frappe.whitelist()
def validate_sales_orders(self, sales_order=None):
@@ -750,7 +756,9 @@
"items",
{
"item_code": item.item_code,
- "from_warehouse": item.from_warehouse,
+ "from_warehouse": item.from_warehouse
+ if material_request_type == "Material Transfer"
+ else None,
"qty": item.quantity,
"schedule_date": schedule_date,
"warehouse": item.warehouse,
diff --git a/erpnext/manufacturing/doctype/production_plan/test_production_plan.py b/erpnext/manufacturing/doctype/production_plan/test_production_plan.py
index 6ed7506..5292571 100644
--- a/erpnext/manufacturing/doctype/production_plan/test_production_plan.py
+++ b/erpnext/manufacturing/doctype/production_plan/test_production_plan.py
@@ -1098,6 +1098,41 @@
)
self.assertEqual(reserved_qty_after_mr, before_qty)
+ def test_from_warehouse_for_purchase_material_request(self):
+ from erpnext.stock.doctype.warehouse.test_warehouse import create_warehouse
+ from erpnext.stock.utils import get_or_make_bin
+
+ create_item("RM-TEST-123 For Purchase", valuation_rate=100)
+ bin_name = get_or_make_bin("RM-TEST-123 For Purchase", "_Test Warehouse - _TC")
+ t_warehouse = create_warehouse("_Test Store - _TC")
+ make_stock_entry(
+ item_code="Raw Material Item 1",
+ qty=5,
+ rate=100,
+ target=t_warehouse,
+ )
+
+ plan = create_production_plan(item_code="Test Production Item 1", do_not_save=1)
+ mr_items = get_items_for_material_requests(
+ plan.as_dict(), warehouses=[{"warehouse": t_warehouse}]
+ )
+
+ for d in mr_items:
+ plan.append("mr_items", d)
+
+ plan.save()
+
+ for row in plan.mr_items:
+ if row.material_request_type == "Material Transfer":
+ self.assertEqual(row.from_warehouse, t_warehouse)
+
+ row.material_request_type = "Purchase"
+
+ plan.save()
+
+ for row in plan.mr_items:
+ self.assertFalse(row.from_warehouse)
+
def test_skip_available_qty_for_sub_assembly_items(self):
from erpnext.manufacturing.doctype.bom.test_bom import create_nested_bom