From b540a5afc03a3248567b79ef3755f778dd512add Mon Sep 17 00:00:00 2001 From: snipe Date: Thu, 14 May 2026 15:58:10 +0100 Subject: [PATCH] Fixed #19006 - update null location --- .../Assets/AssetCheckinController.php | 15 +++++++++------ tests/Feature/Checkins/Ui/AssetCheckinTest.php | 16 ++++++++++++++++ 2 files changed, 25 insertions(+), 6 deletions(-) diff --git a/app/Http/Controllers/Assets/AssetCheckinController.php b/app/Http/Controllers/Assets/AssetCheckinController.php index dd3f36e035..f023bd5d3d 100644 --- a/app/Http/Controllers/Assets/AssetCheckinController.php +++ b/app/Http/Controllers/Assets/AssetCheckinController.php @@ -133,14 +133,17 @@ class AssetCheckinController extends Controller $this->migrateLegacyLocations($asset); - $asset->location_id = $asset->rtd_location_id; - if ($request->filled('location_id')) { - Log::debug('NEW Location ID: '.$request->input('location_id')); - $asset->location_id = $request->input('location_id'); + if ($request->has('location_id')) { + if ($request->filled('location_id')) { + Log::debug('NEW Location ID: ' . $request->input('location_id')); + $asset->location_id = $request->input('location_id'); - if ($request->input('update_default_location') == 0) { - $asset->rtd_location_id = $request->input('location_id'); + if ($request->input('update_default_location') == 0) { + $asset->rtd_location_id = $request->input('location_id'); + } + } else { + $asset->location_id = null; } } diff --git a/tests/Feature/Checkins/Ui/AssetCheckinTest.php b/tests/Feature/Checkins/Ui/AssetCheckinTest.php index 1179aa721d..4f2ef14531 100644 --- a/tests/Feature/Checkins/Ui/AssetCheckinTest.php +++ b/tests/Feature/Checkins/Ui/AssetCheckinTest.php @@ -179,6 +179,22 @@ class AssetCheckinTest extends TestCase $this->assertHasTheseActionLogs($asset, ['create', 'checkin from']); } + public function test_location_is_nulled_when_empty_location_id_submitted_on_checkin() + { + $rtdLocation = Location::factory()->create(); + $asset = Asset::factory()->assignedToUser()->create([ + 'location_id' => Location::factory()->create()->id, + 'rtd_location_id' => $rtdLocation->id, + ]); + + $this->actingAs(User::factory()->checkinAssets()->create()) + ->post(route('hardware.checkin.store', [$asset]), [ + 'location_id' => '', + ]); + + $this->assertNull($asset->refresh()->location_id); + } + public function test_default_location_can_be_updated_upon_checkin() { $location = Location::factory()->create();