From bda230537a7d69f7c1ae16abf390b5e160c83cad Mon Sep 17 00:00:00 2001 From: Bernd Bestel Date: Wed, 23 Mar 2022 17:34:51 +0100 Subject: [PATCH] Fixed purchase/consume page handling when FEATURE_FLAG_STOCK_LOCATION_TRACKING is disabled (fixes #1829) --- changelog/67_UNRELEASED_xxxx-xx-xx.md | 1 + migrations/8888.php | 23 +++++++++++++++++++++++ public/viewjs/purchase.js | 5 +++++ services/DatabaseMigrationService.php | 13 ++++++++----- 4 files changed, 37 insertions(+), 5 deletions(-) create mode 100644 migrations/8888.php diff --git a/changelog/67_UNRELEASED_xxxx-xx-xx.md b/changelog/67_UNRELEASED_xxxx-xx-xx.md index 0fedb2d7..498796e2 100644 --- a/changelog/67_UNRELEASED_xxxx-xx-xx.md +++ b/changelog/67_UNRELEASED_xxxx-xx-xx.md @@ -11,6 +11,7 @@ - It's now possible to change a products stock QU, even after it was once added to stock - When the product was once added to stock, there needs to exist a corresponding unit conversion for the new QU - Added the product grocycode as a (hidden by default) column to the products list (master data) +- Fixed that consuming via the consume page was not possible when `FEATURE_FLAG_STOCK_LOCATION_TRACKING` was disabled ### Shopping list diff --git a/migrations/8888.php b/migrations/8888.php new file mode 100644 index 00000000..ae48aad2 --- /dev/null +++ b/migrations/8888.php @@ -0,0 +1,23 @@ +getDatabaseService()->GetDbConnection(); + + if ($db->locations()->where('id', 1)->count() === 0) + { + // Create 2 default quantity units + $defaultLocation = $db->locations()->createRow([ + 'id' => 1, + 'name' => 'Default' + ]); + $defaultLocation->save(); + } +} diff --git a/public/viewjs/purchase.js b/public/viewjs/purchase.js index 9f160a62..762c402b 100644 --- a/public/viewjs/purchase.js +++ b/public/viewjs/purchase.js @@ -401,6 +401,11 @@ if (Grocy.Components.ProductPicker !== undefined) function PrefillBestBeforeDate(product, location) { + if (location == null) + { + location = {} + } + if (Grocy.FeatureFlags.GROCY_FEATURE_FLAG_STOCK_BEST_BEFORE_DATE_TRACKING) { var dueDays; diff --git a/services/DatabaseMigrationService.php b/services/DatabaseMigrationService.php index 014096aa..449031c0 100644 --- a/services/DatabaseMigrationService.php +++ b/services/DatabaseMigrationService.php @@ -4,9 +4,12 @@ namespace Grocy\Services; class DatabaseMigrationService extends BaseService { - // This migration will be always execute, can be used to fix things manually + // This migration will be always executed, can be used to fix things manually (will never be shipped) const EMERGENCY_MIGRATION_ID = 9999; + // This migration will be always executed, is used for things which need to be checked always + const DOALWAYS_MIGRATION_ID = 8888; + public function MigrateDatabase() { $this->getDatabaseService()->ExecuteDbStatement("CREATE TABLE IF NOT EXISTS migrations (migration INTEGER NOT NULL PRIMARY KEY UNIQUE, execution_time_timestamp DATETIME DEFAULT (datetime('now', 'localtime')))"); @@ -39,11 +42,11 @@ class DatabaseMigrationService extends BaseService { $rowCount = $this->getDatabaseService()->ExecuteDbQuery('SELECT COUNT(*) FROM migrations WHERE migration = ' . $migrationId)->fetchColumn(); - if (intval($rowCount) === 0 || $migrationId == self::EMERGENCY_MIGRATION_ID) + if (intval($rowCount) === 0 || $migrationId == self::EMERGENCY_MIGRATION_ID || $migrationId == self::DOALWAYS_MIGRATION_ID) { include $phpFile; - if ($migrationId != self::EMERGENCY_MIGRATION_ID) + if ($migrationId != self::EMERGENCY_MIGRATION_ID && $migrationId != self::DOALWAYS_MIGRATION_ID) { $this->getDatabaseService()->ExecuteDbStatement('INSERT INTO migrations (migration) VALUES (' . $migrationId . ')'); } @@ -54,7 +57,7 @@ class DatabaseMigrationService extends BaseService { $rowCount = $this->getDatabaseService()->ExecuteDbQuery('SELECT COUNT(*) FROM migrations WHERE migration = ' . $migrationId)->fetchColumn(); - if (intval($rowCount) === 0 || $migrationId == self::EMERGENCY_MIGRATION_ID) + if (intval($rowCount) === 0 || $migrationId == self::EMERGENCY_MIGRATION_ID || $migrationId == self::DOALWAYS_MIGRATION_ID) { $this->getDatabaseService()->GetDbConnectionRaw()->beginTransaction(); @@ -62,7 +65,7 @@ class DatabaseMigrationService extends BaseService { $this->getDatabaseService()->ExecuteDbStatement($sql); - if ($migrationId != self::EMERGENCY_MIGRATION_ID) + if ($migrationId != self::EMERGENCY_MIGRATION_ID && $migrationId != self::DOALWAYS_MIGRATION_ID) { $this->getDatabaseService()->ExecuteDbStatement('INSERT INTO migrations (migration) VALUES (' . $migrationId . ')'); }