mirror of
https://github.com/grocy/grocy.git
synced 2025-08-16 10:44:37 +00:00
Fixed purchase/consume page handling when FEATURE_FLAG_STOCK_LOCATION_TRACKING is disabled (fixes #1829)
This commit is contained in:
@@ -11,6 +11,7 @@
|
|||||||
- It's now possible to change a products stock QU, even after it was once added to stock
|
- 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
|
- 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)
|
- 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
|
### Shopping list
|
||||||
|
|
||||||
|
23
migrations/8888.php
Normal file
23
migrations/8888.php
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
// This migration is always executed (on every migration run, not only once)
|
||||||
|
|
||||||
|
// This is executed inside DatabaseMigrationService class/context
|
||||||
|
|
||||||
|
// When FEATURE_FLAG_STOCK_LOCATION_TRACKING is disabled,
|
||||||
|
// some places assume that there exists a location with id 1,
|
||||||
|
// so make sure that this location is available in that case
|
||||||
|
if (!GROCY_FEATURE_FLAG_STOCK_LOCATION_TRACKING)
|
||||||
|
{
|
||||||
|
$db = $this->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();
|
||||||
|
}
|
||||||
|
}
|
@@ -401,6 +401,11 @@ if (Grocy.Components.ProductPicker !== undefined)
|
|||||||
|
|
||||||
function PrefillBestBeforeDate(product, location)
|
function PrefillBestBeforeDate(product, location)
|
||||||
{
|
{
|
||||||
|
if (location == null)
|
||||||
|
{
|
||||||
|
location = {}
|
||||||
|
}
|
||||||
|
|
||||||
if (Grocy.FeatureFlags.GROCY_FEATURE_FLAG_STOCK_BEST_BEFORE_DATE_TRACKING)
|
if (Grocy.FeatureFlags.GROCY_FEATURE_FLAG_STOCK_BEST_BEFORE_DATE_TRACKING)
|
||||||
{
|
{
|
||||||
var dueDays;
|
var dueDays;
|
||||||
|
@@ -4,9 +4,12 @@ namespace Grocy\Services;
|
|||||||
|
|
||||||
class DatabaseMigrationService extends BaseService
|
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;
|
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()
|
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')))");
|
$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();
|
$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;
|
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 . ')');
|
$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();
|
$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();
|
$this->getDatabaseService()->GetDbConnectionRaw()->beginTransaction();
|
||||||
|
|
||||||
@@ -62,7 +65,7 @@ class DatabaseMigrationService extends BaseService
|
|||||||
{
|
{
|
||||||
$this->getDatabaseService()->ExecuteDbStatement($sql);
|
$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 . ')');
|
$this->getDatabaseService()->ExecuteDbStatement('INSERT INTO migrations (migration) VALUES (' . $migrationId . ')');
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user