A free open source IT asset/license management system
Keep warranty expiration in the last month for purchases late in the month
Jay Hemnaniba7ac81cefa7
diff --git a/app/Models/Asset.php b/app/Models/Asset.phpindex 7149d936be..159400417e 100644--- a/app/Models/Asset.php+++ b/app/Models/Asset.php@@ -429,7 +429,7 @@ class Asset extends Depreciable implements Importableprotected function warrantyExpires(): Attribute{return Attribute::make(- get: fn (mixed $value, array $attributes) => (! empty($attributes['warranty_months']) && ! empty($attributes['purchase_date'])) ? Carbon::parse($attributes['purchase_date'])->addMonths((int) $attributes['warranty_months']) : null,+ get: fn (mixed $value, array $attributes) => (! empty($attributes['warranty_months']) && ! empty($attributes['purchase_date'])) ? Carbon::parse($attributes['purchase_date'])->addMonthsNoOverflow((int) $attributes['warranty_months']) : null,);}@@ -1230,7 +1230,7 @@ class Asset extends Depreciable implements Importable->get();$expired_warranties = $assets_with_warranties->filter(function ($asset) use ($now, $end) {- $expiration_window = Carbon::parse($asset->purchase_date)->addMonths((int) $asset->warranty_months);+ $expiration_window = Carbon::parse($asset->purchase_date)->addMonthsNoOverflow((int) $asset->warranty_months);return $expiration_window->betweenIncluded($now, $end);});diff --git a/tests/Unit/AssetTest.php b/tests/Unit/AssetTest.phpindex 40ae42ad95..206da188c4 100644--- a/tests/Unit/AssetTest.php+++ b/tests/Unit/AssetTest.php@@ -318,6 +318,21 @@ class AssetTest extends TestCase}+ public function test_warranty_expires_stays_in_the_last_month_for_a_purchase_late_in_the_month()+ {+ $asset = Asset::factory()->create([+ 'warranty_months' => 1,+ 'purchase_date' => '2026-08-31',+ ]);+ $this->assertEquals('2026-09-30', $asset->warranty_expires->format('Y-m-d'));++ $asset = Asset::factory()->create([+ 'warranty_months' => 1,+ 'purchase_date' => '2026-01-31',+ ]);+ $this->assertEquals('2026-02-28', $asset->warranty_expires->format('Y-m-d'));+ }+public function test_eol_progress_percent_returns_expected_value(): void{Carbon::setTestNow(Carbon::create(2026, 1, 1, 0, 0, 0));