From 20eb92891a715ba5af69f53c82712de7c3950b49 Mon Sep 17 00:00:00 2001 From: Jeppe B <2jepp9350@gmail.com> Date: Thu, 28 May 2026 17:21:36 +0200 Subject: [PATCH] Avoid empty self-serve invoice orders Only create the invoice order context when elapsed minute billing has a positive quantity. This preserves automatic-mode included-minute reduction without leaving an empty order id on the lane. Tests: - bash scripts/php-ci-test.sh unit --- .../modules/selfserve/traits/selfserve_lane_invoice_t.php | 2 +- .../Unit/Selfserve/SelfserveLaneInvoiceModeBillingTest.php | 5 ++++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/services/nginx/app/modules/selfserve/traits/selfserve_lane_invoice_t.php b/services/nginx/app/modules/selfserve/traits/selfserve_lane_invoice_t.php index 320df5b4..63208551 100644 --- a/services/nginx/app/modules/selfserve/traits/selfserve_lane_invoice_t.php +++ b/services/nginx/app/modules/selfserve/traits/selfserve_lane_invoice_t.php @@ -124,8 +124,8 @@ trait selfserve_lane_invoice_t $included_minutes = $this->resolveIncludedMinutesForBilling(); $billable_minutes = $this->calculateBillableMinutes($elapsed_minutes, $included_minutes); - $order = $this->createInvoiceOrderContext($arguments); if ($billable_minutes > 0) { + $order = $this->createInvoiceOrderContext($arguments); $this->billable_minutes_order_item = $this->addMinuteBillingLine((int)$order->id, (int)$product_id, $billable_minutes); } return true; diff --git a/services/nginx/app/tests/Unit/Selfserve/SelfserveLaneInvoiceModeBillingTest.php b/services/nginx/app/tests/Unit/Selfserve/SelfserveLaneInvoiceModeBillingTest.php index 6a73a3cb..6de6db03 100644 --- a/services/nginx/app/tests/Unit/Selfserve/SelfserveLaneInvoiceModeBillingTest.php +++ b/services/nginx/app/tests/Unit/Selfserve/SelfserveLaneInvoiceModeBillingTest.php @@ -24,6 +24,7 @@ class SelfserveLaneInvoiceModeBillingHarness public ?int $lastAddedOrderId = null; public ?int $lastAddedProductId = null; public ?int $lastAddedQuantity = null; + public int $createdOrderContexts = 0; private selfserve_lane_status $laneStatus = selfserve_lane_status::OCCUPIED; private selfserve_lane_mode $laneMode = selfserve_lane_mode::MANUAL; @@ -85,6 +86,7 @@ class SelfserveLaneInvoiceModeBillingHarness protected function createInvoiceOrderContext(): orders_o { + $this->createdOrderContexts++; $order = new SelfserveLaneInvoiceModeOrderStub(); $order->id = 424242; $this->last_invoice_order_id = (int)$order->id; @@ -111,6 +113,7 @@ it('bills manual self-serve stop using full elapsed minutes without included-min expect($harness->lastAddedOrderId)->toBe(424242); expect($harness->lastAddedProductId)->toBe(999); expect($harness->lastAddedQuantity)->toBe(1); + expect($harness->createdOrderContexts)->toBe(1); expect($harness->getLastInvoiceOrderId())->toBe(424242); }); @@ -126,6 +129,6 @@ it('keeps included-minute reduction for automatic mode', function (): void { expect($harness->lastAddedOrderId)->toBeNull(); expect($harness->lastAddedProductId)->toBeNull(); expect($harness->lastAddedQuantity)->toBeNull(); + expect($harness->createdOrderContexts)->toBe(0); expect($harness->getLastInvoiceOrderId())->toBeNull(); }); -