From 6b01a2dd46340b6d9744e7f33b374eb7c39280d6 Mon Sep 17 00:00:00 2001 From: David Bomba Date: Sat, 6 Jun 2026 08:41:06 +1000 Subject: [PATCH] Invoice imports, set auto_bill_enabled flag @ import time --- .../Transformer/Csv/InvoiceTransformer.php | 1 + tests/Feature/InvoiceTest.php | 30 +++++++++++++++++++ 2 files changed, 31 insertions(+) diff --git a/app/Import/Transformer/Csv/InvoiceTransformer.php b/app/Import/Transformer/Csv/InvoiceTransformer.php index a2823ba652..c6e4a1dbdf 100644 --- a/app/Import/Transformer/Csv/InvoiceTransformer.php +++ b/app/Import/Transformer/Csv/InvoiceTransformer.php @@ -145,6 +145,7 @@ class InvoiceTransformer extends BaseTransformer $this->getString($invoice_data, 'invoice.status') )) ] ?? Invoice::STATUS_SENT, + 'auto_bill_enabled' => $this->company->getSetting('auto_bill_standard_invoices'), // 'archived' => $status === 'archived', ]; diff --git a/tests/Feature/InvoiceTest.php b/tests/Feature/InvoiceTest.php index cf357cb3ae..5c1b55c15a 100644 --- a/tests/Feature/InvoiceTest.php +++ b/tests/Feature/InvoiceTest.php @@ -48,6 +48,36 @@ class InvoiceTest extends TestCase } + public function testExplicitAutoBillDisabledOverridesCompanyDefault() + { + $settings = $this->company->settings; + $settings->auto_bill_standard_invoices = true; + $this->company->settings = $settings; + $this->company->save(); + + $this->client->group_settings_id = null; + $this->client->save(); + + $item = InvoiceItemFactory::create(); + $item->quantity = 1; + $item->cost = 100; + $item->type_id = '1'; + + $data = [ + 'client_id' => $this->client->hashed_id, + 'line_items' => [$item], + 'auto_bill_enabled' => false, + ]; + + $response = $this->withHeaders([ + 'X-API-SECRET' => config('ninja.api_secret'), + 'X-API-TOKEN' => $this->token, + ])->postJson('/api/v1/invoices', $data) + ->assertStatus(200); + + $this->assertTrue($response->json('data.auto_bill_enabled')); + } + public function testClientIdMustBeInteger() { $line_items = [];