From 974b342333f87d25f1f1914ce6f009c9a1bfed4b Mon Sep 17 00:00:00 2001 From: David Bomba Date: Wed, 10 Jan 2024 12:28:12 +1100 Subject: [PATCH] Fixes for migration --- VERSION.txt | 2 +- config/ninja.php | 4 ++-- .../2024_01_09_084515_product_cost_field_population.php | 6 ++++-- tests/Feature/ProductTest.php | 9 ++++++--- 4 files changed, 13 insertions(+), 8 deletions(-) diff --git a/VERSION.txt b/VERSION.txt index a94a88fbb889..fb54fe3dc194 100644 --- a/VERSION.txt +++ b/VERSION.txt @@ -1 +1 @@ -5.8.5 \ No newline at end of file +5.8.6 \ No newline at end of file diff --git a/config/ninja.php b/config/ninja.php index 0ed8eb4931d4..ce024437469e 100644 --- a/config/ninja.php +++ b/config/ninja.php @@ -17,8 +17,8 @@ return [ 'require_https' => env('REQUIRE_HTTPS', true), 'app_url' => rtrim(env('APP_URL', ''), '/'), 'app_domain' => env('APP_DOMAIN', 'invoicing.co'), - 'app_version' => env('APP_VERSION', '5.8.5'), - 'app_tag' => env('APP_TAG', '5.8.5'), + 'app_version' => env('APP_VERSION', '5.8.6'), + 'app_tag' => env('APP_TAG', '5.8.6'), 'minimum_client_version' => '5.0.16', 'terms_version' => '1.0.1', 'api_secret' => env('API_SECRET', false), diff --git a/database/migrations/2024_01_09_084515_product_cost_field_population.php b/database/migrations/2024_01_09_084515_product_cost_field_population.php index ce08aed2dcee..d47126d04906 100644 --- a/database/migrations/2024_01_09_084515_product_cost_field_population.php +++ b/database/migrations/2024_01_09_084515_product_cost_field_population.php @@ -31,10 +31,12 @@ return new class extends Migration foreach ($line_items as $key => $item) { - if($item?->product_cost == 0 && $product = Product::where('company_id', $invoice->company_id)->where('product_key', $item->product_key)->where('cost', '>', 0)->first()) + if($product = Product::where('company_id', $invoice->company_id)->where('product_key', $item->product_key)->where('cost', '>', 0)->first()) { - $line_items[$key]->product_cost = $product->cost; + if((property_exists($item, 'product_cost') && $item->product_cost == 0) || !property_exists($item, 'product_cost')) + $line_items[$key]->product_cost = $product->cost; } + } $invoice->line_items = $line_items; diff --git a/tests/Feature/ProductTest.php b/tests/Feature/ProductTest.php index 40af31f9a9cc..e2b4c7a9cca3 100644 --- a/tests/Feature/ProductTest.php +++ b/tests/Feature/ProductTest.php @@ -95,19 +95,22 @@ class ProductTest extends TestCase ->cursor() ->each(function (Invoice $invoice) { - $line_items = $invoice->line_items; foreach ($line_items as $key => $item) { - if(property_exists($item, 'product_cost') && $item->product_cost == 0 && $product = Product::where('company_id', $invoice->company_id)->where('product_key', $item->product_key)->where('cost', '>', 0)->first()) { - $line_items[$key]->product_cost = $product->cost; + if($product = Product::where('company_id', $invoice->company_id)->where('product_key', $item->product_key)->where('cost', '>', 0)->first()) { + if((property_exists($item, 'product_cost') && $item->product_cost == 0) || !property_exists($item, 'product_cost')) { + $line_items[$key]->product_cost = $product->cost; + } } + } $invoice->line_items = $line_items; $invoice->saveQuietly(); + });