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');