A free open source IT asset/license management system
Locations Print Assigned: Fixed #19093 - accessories not showing
snipe5545d08a2890
diff --git a/resources/views/locations/print.blade.php b/resources/views/locations/print.blade.phpindex 7d46e5b6cd..f2b25e174d 100644--- a/resources/views/locations/print.blade.php+++ b/resources/views/locations/print.blade.php@@ -312,14 +312,22 @@$counter = 1;@endphp- @foreach ($assignedAccessories as $accessory)+ {{-- $assignedAccessories is a collection of AccessoryCheckout+ rows (Location::assignedAccessories() is a morphMany onto+ accessories_checkout, keyed by assigned_type / assigned_to).+ Fix for #19093: reach through ->accessory to render the+ underlying Accessory attributes. Prior code addressed+ $checkout->name / ->category / etc. directly and produced+ blank cells because AccessoryCheckout has none of those+ attributes. --}}+ @foreach ($assignedAccessories as $checkout)<tr><td>{{ $counter }}</td>- <td>{{ $accessory->name }}</td>- <td>{{ ($accessory->category) ? $accessory->category->name : '' }}</td>- <td>{{ ($accessory->manufacturer) ? $accessory->manufacturer->name : '' }}</td>- <td>{{ $accessory->model_number }}</td>- <td>{{ ($accessory->location) ? $accessory->location->name : '' }}</td>+ <td>{{ $checkout->accessory?->name }}</td>+ <td>{{ $checkout->accessory?->category?->name }}</td>+ <td>{{ $checkout->accessory?->manufacturer?->name }}</td>+ <td>{{ $checkout->accessory?->model_number }}</td>+ <td>{{ $checkout->accessory?->location?->name }}</td></tr>@php$counter++diff --git a/tests/Feature/Locations/Ui/ShowLocationTest.php b/tests/Feature/Locations/Ui/ShowLocationTest.phpindex e1bd7ba5ef..bac6aa6085 100644--- a/tests/Feature/Locations/Ui/ShowLocationTest.php+++ b/tests/Feature/Locations/Ui/ShowLocationTest.php@@ -38,6 +38,32 @@ class ShowLocationTest extends TestCase->assertOk();}+ public function test_print_all_assigned_renders_accessory_name_for_location_checkouts()+ {+ // Regression guard for #19093: Location::assignedAccessories()+ // is a morphMany onto accessories_checkout, so the collection+ // items are AccessoryCheckout instances, not Accessory. The+ // print template used to read $checkout->name (which doesn't+ // exist on AccessoryCheckout) and quietly produced blank rows.+ // Reach through ->accessory to render the real attributes.+ $location = Location::factory()->create();+ $accessory = \App\Models\Accessory::factory()->create([+ 'name' => 'DistinctBluetoothMouse-19093',+ 'model_number' => 'MDL-19093',+ ]);+ \App\Models\AccessoryCheckout::factory()->create([+ 'accessory_id' => $accessory->id,+ 'assigned_to' => $location->id,+ 'assigned_type' => Location::class,+ ]);++ $this->actingAs(User::factory()->superuser()->create())+ ->get(route('locations.print_all_assigned', $location))+ ->assertOk()+ ->assertSee('DistinctBluetoothMouse-19093')+ ->assertSee('MDL-19093');+ }+public function test_show_page_includes_parent_location_breadcrumb_hierarchy(){$grandparent = Location::factory()->create(['name' => 'Grandparent Breadcrumb Location']);