From 84d205f553083221bd5e841e191a308ca15a76a7 Mon Sep 17 00:00:00 2001 From: "mergify[bot]" <37929162+mergify[bot]@users.noreply.github.com> Date: Thu, 4 Jun 2026 16:50:34 +0000 Subject: [PATCH] fix: prevent selling items from sample retention warehouse (backport #55613) (#55634) Co-authored-by: Pandiyan P Co-authored-by: Mihir Kandoi fix: prevent selling items from sample retention warehouse (#55613) --- erpnext/controllers/selling_controller.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/erpnext/controllers/selling_controller.py b/erpnext/controllers/selling_controller.py index 33411702d45..a3940aacb6b 100644 --- a/erpnext/controllers/selling_controller.py +++ b/erpnext/controllers/selling_controller.py @@ -70,6 +70,7 @@ class SellingController(StockController): self.validate_for_duplicate_items() self.validate_target_warehouse() self.validate_auto_repeat_subscription_dates() + self.validate_sample_retention_warehouse() for table_field in ["items", "packed_items"]: if self.get(table_field): self.set_serial_and_batch_bundle(table_field) @@ -891,6 +892,26 @@ class SellingController(StockController): validate_item_type(self, "is_sales_item", "sales") + def validate_sample_retention_warehouse(self): + if self.get("is_return"): + return + + sample_retention_warehouse = frappe.db.get_single_value( + "Stock Settings", "sample_retention_warehouse" + ) + if not sample_retention_warehouse: + return + + items = self.get("items") + (self.get("packed_items")) + for item in items: + if item.get("warehouse") == sample_retention_warehouse: + frappe.throw( + _("Row {0}: Cannot sell item {1} from Sample Retention Warehouse {2}").format( + item.idx, frappe.bold(item.item_code), frappe.bold(sample_retention_warehouse) + ), + title=_("Not Allowed"), + ) + def update_stock_reservation_entries(self) -> None: """Updates Delivered Qty in Stock Reservation Entries."""