From 2115fda4e58696a0213d7d89e1323630584c9636 Mon Sep 17 00:00:00 2001 From: objecttothis <17935339+objecttothis@users.noreply.github.com> Date: Wed, 19 Aug 2026 17:17:08 +0400 Subject: [PATCH] fix(models): validate existence of stock location before setting as default - Added check to ensure that the stock location exists and is not deleted before attempting to set it as the default. Signed-off-by: objecttothis <17935339+objecttothis@users.noreply.github.com> --- app/Models/Stock_location.php | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/app/Models/Stock_location.php b/app/Models/Stock_location.php index 6b23ab7d8..0b4f8ea6c 100644 --- a/app/Models/Stock_location.php +++ b/app/Models/Stock_location.php @@ -159,6 +159,15 @@ class Stock_location extends Model */ public function setDefaultLocation(int $locationId): bool { + $exists = $this->db->table('stock_locations') + ->where('location_id', $locationId) + ->where('deleted', 0) + ->countAllResults(); + + if ($exists === 0) { + return false; + } + $this->db->transStart(); $builder = $this->db->table('stock_locations');