From c15012cd51c80baff894081aa25472a6c6d53959 Mon Sep 17 00:00:00 2001 From: "mergify[bot]" <37929162+mergify[bot]@users.noreply.github.com> Date: Thu, 4 Jun 2026 16:48:59 +0000 Subject: [PATCH] fix: prevent selling items from sample retention warehouse (backport #55613) (#55633) 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 d5bd3501527..3383bd51fdd 100644 --- a/erpnext/controllers/selling_controller.py +++ b/erpnext/controllers/selling_controller.py @@ -53,6 +53,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) @@ -874,6 +875,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."""