Skip to content

A free open source IT asset/license management system

Log quantity when adding or removing seats from license

Marcus Moore6f77e969984e
diff --git a/app/Models/License.php b/app/Models/License.php
index 3f6bcf1c13..1024ebdc90 100755
--- a/app/Models/License.php
+++ b/app/Models/License.php
@@ -223,6 +223,7 @@ class License extends Depreciable
$logAction->created_by = auth()->id() ?: 1; // We don't have an id while running the importer from CLI.
$logAction->note = "deleted {$change} seats";
$logAction->target_id = null;
+ $logAction->qty = $change;
$logAction->logaction('delete seats');
return true;
@@ -259,6 +260,7 @@ class License extends Depreciable
$logAction->created_by = auth()->id() ?: 1; // Importer.
$logAction->note = "added {$change} seats";
$logAction->target_id = null;
+ $logAction->qty = $change;
$logAction->logaction('add seats');
}
diff --git a/tests/Unit/Models/LicenseTest.php b/tests/Unit/Models/LicenseTest.php
new file mode 100644
index 0000000000..7a8c1f6f8a
--- /dev/null
+++ b/tests/Unit/Models/LicenseTest.php
@@ -0,0 +1,53 @@
+<?php
+
+namespace Tests\Unit\Models;
+
+use App\Enums\ActionType;
+use App\Models\License;
+use App\Models\User;
+use Tests\TestCase;
+
+class LicenseTest extends TestCase
+{
+ public function test_adding_seats_is_logged_when_updating()
+ {
+ $user = User::factory()->create();
+ $this->actingAs($user);
+
+ $license = License::factory()->create(['seats' => 2]);
+
+ $license->update(['seats' => 6]);
+
+ $this->assertDatabaseHas('action_logs', [
+ 'created_by' => $user->id,
+ 'action_type' => ActionType::AddSeats,
+ 'item_type' => License::class,
+ 'item_id' => $license->id,
+ 'deleted_at' => null,
+ // relevant for this test:
+ 'qty' => 4,
+ 'note' => 'added 4 seats',
+ ]);
+ }
+
+ public function test_removing_seats_is_logged_when_updating()
+ {
+ $user = User::factory()->create();
+ $this->actingAs($user);
+
+ $license = License::factory()->create(['seats' => 6]);
+
+ $license->update(['seats' => 3]);
+
+ $this->assertDatabaseHas('action_logs', [
+ 'created_by' => $user->id,
+ 'action_type' => ActionType::DeleteSeats,
+ 'item_type' => License::class,
+ 'item_id' => $license->id,
+ 'deleted_at' => null,
+ // relevant for this test:
+ 'qty' => 3,
+ 'note' => 'deleted 3 seats',
+ ]);
+ }
+}