From 34a33ba06f83299402489e2c7a8b355d529fd601 Mon Sep 17 00:00:00 2001 From: Carlos Ruiz Date: Sat, 8 Jul 2023 05:17:37 +0200 Subject: [PATCH] IDEMPIERE-1437 Do not allow changing Table in Tab when there are Fields (#1927) --- migration/iD11/oracle/202307061451_IDEMPIERE-1437.sql | 10 ++++++++++ .../iD11/postgresql/202307061451_IDEMPIERE-1437.sql | 7 +++++++ org.adempiere.base/src/org/compiere/model/MTab.java | 5 +++++ 3 files changed, 22 insertions(+) create mode 100644 migration/iD11/oracle/202307061451_IDEMPIERE-1437.sql create mode 100644 migration/iD11/postgresql/202307061451_IDEMPIERE-1437.sql diff --git a/migration/iD11/oracle/202307061451_IDEMPIERE-1437.sql b/migration/iD11/oracle/202307061451_IDEMPIERE-1437.sql new file mode 100644 index 0000000000..7d31ece9a5 --- /dev/null +++ b/migration/iD11/oracle/202307061451_IDEMPIERE-1437.sql @@ -0,0 +1,10 @@ +-- IDEMPIERE-1437 +SELECT register_migration_script('202307061451_IDEMPIERE-1437.sql') FROM dual; + +SET SQLBLANKLINES ON +SET DEFINE OFF + +-- Jul 6, 2023, 2:51:25 PM CEST +UPDATE AD_Field SET ReadOnlyLogic='@SQL=SELECT 1 FROM AD_Field WHERE AD_Tab_ID=@AD_Tab_ID@',Updated=TO_TIMESTAMP('2023-07-06 14:51:25','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=100 WHERE AD_Field_ID=131 +; + diff --git a/migration/iD11/postgresql/202307061451_IDEMPIERE-1437.sql b/migration/iD11/postgresql/202307061451_IDEMPIERE-1437.sql new file mode 100644 index 0000000000..2db3de9d1c --- /dev/null +++ b/migration/iD11/postgresql/202307061451_IDEMPIERE-1437.sql @@ -0,0 +1,7 @@ +-- IDEMPIERE-1437 +SELECT register_migration_script('202307061451_IDEMPIERE-1437.sql') FROM dual; + +-- Jul 6, 2023, 2:51:25 PM CEST +UPDATE AD_Field SET ReadOnlyLogic='@SQL=SELECT 1 FROM AD_Field WHERE AD_Tab_ID=@AD_Tab_ID@',Updated=TO_TIMESTAMP('2023-07-06 14:51:25','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=100 WHERE AD_Field_ID=131 +; + diff --git a/org.adempiere.base/src/org/compiere/model/MTab.java b/org.adempiere.base/src/org/compiere/model/MTab.java index effbff2df7..d6a6f96e30 100644 --- a/org.adempiere.base/src/org/compiere/model/MTab.java +++ b/org.adempiere.base/src/org/compiere/model/MTab.java @@ -232,6 +232,11 @@ public class MTab extends X_AD_Tab implements ImmutablePOSupport */ protected boolean beforeSave (boolean newRecord) { + if (! newRecord && is_ValueChanged(COLUMNNAME_AD_Table_ID) && getFields(false, get_TrxName()).length > 0) { + log.saveError("Error", "Cannot change table if there are related fields"); + return false; + } + if (isReadOnly() && isInsertRecord()) setIsInsertRecord(false); if (is_new() || is_ValueChanged(COLUMNNAME_AD_TabType))