From d8ef615ee2db86b346168630cf4b871264f954c6 Mon Sep 17 00:00:00 2001 From: teo_sarca Date: Fri, 21 Nov 2008 12:30:46 +0000 Subject: [PATCH] BF [ 1883533 ] Change to summary - valid combination issue BF [ 2320411 ] Translate "Already posted to" message --- .../src/org/compiere/model/MElementValue.java | 63 +++++++++++-------- migration/352a-trunk/329_BF2320411.sql | 15 +++++ .../352a-trunk/postgresql/329_BF2320411.sql | 15 +++++ 3 files changed, 66 insertions(+), 27 deletions(-) create mode 100644 migration/352a-trunk/329_BF2320411.sql create mode 100644 migration/352a-trunk/postgresql/329_BF2320411.sql diff --git a/base/src/org/compiere/model/MElementValue.java b/base/src/org/compiere/model/MElementValue.java index 74cd202f45..2a12f208b5 100644 --- a/base/src/org/compiere/model/MElementValue.java +++ b/base/src/org/compiere/model/MElementValue.java @@ -16,15 +16,21 @@ *****************************************************************************/ package org.compiere.model; -import java.sql.*; -import java.util.*; -import org.compiere.util.*; +import java.sql.ResultSet; +import java.util.Properties; + +import org.adempiere.exceptions.AdempiereException; +import org.compiere.util.Env; /** * Natural Account * * @author Jorg Janke * @version $Id: MElementValue.java,v 1.3 2006/07/30 00:58:37 jjanke Exp $ + * + * @author Teo Sarca, SC ARHIPAC SERVICE SRL + * BF [ 1883533 ] Change to summary - valid combination issue + * BF [ 2320411 ] Translate "Already posted to" message */ public class MElementValue extends X_C_ElementValue { @@ -191,36 +197,43 @@ public class MElementValue extends X_C_ElementValue - /** - * Before Save - * @param newRecord - * @return true if ir can be saved - */ + @Override protected boolean beforeSave (boolean newRecord) { if (getAD_Org_ID() != 0) setAD_Org_ID(0); // - if (!newRecord && isSummary() - && is_ValueChanged("IsSummary")) + // Transform to summary level account + if (!newRecord && isSummary() && is_ValueChanged(COLUMNNAME_IsSummary)) { - String sql = "SELECT COUNT(*) FROM Fact_Acct WHERE Account_ID=?"; - int no = DB.getSQLValue(get_TrxName(), sql, getC_ElementValue_ID()); - if (no != 0) + // + // Check if we have accounting facts + boolean match = new Query(getCtx(), MFactAcct.Table_Name, MFactAcct.COLUMNNAME_Account_ID+"=?", get_TrxName()) + .setParameters(new Object[]{getC_ElementValue_ID()}) + .match(); + if (match) { - log.saveError("Error", "Already posted to"); - return false; + throw new AdempiereException("@AlreadyPostedTo@"); + } + // + // Check Valid Combinations - teo_sarca FR [ 1883533 ] + String whereClause = MAccount.COLUMNNAME_Account_ID+"=?"; + POResultSet rs = new Query(getCtx(), MAccount.Table_Name, whereClause, get_TrxName()) + .setParameters(new Object[]{get_ID()}) + .scroll(); + try { + while(rs.hasNext()) { + rs.next().deleteEx(true); + } + } + finally { + rs.close(); } } return true; } // beforeSave - /** - * After Save - * @param newRecord new - * @param success success - * @return success - */ + @Override protected boolean afterSave (boolean newRecord, boolean success) { if (newRecord) @@ -234,7 +247,7 @@ public class MElementValue extends X_C_ElementValue } // Value/Name change - if (!newRecord && (is_ValueChanged("Value") || is_ValueChanged("Name"))) + if (!newRecord && (is_ValueChanged(COLUMNNAME_Value) || is_ValueChanged(COLUMNNAME_Name))) { MAccount.updateValueDescription(getCtx(), "Account_ID=" + getC_ElementValue_ID(),get_TrxName()); if ("Y".equals(Env.getContext(getCtx(), "$Element_U1"))) @@ -246,11 +259,7 @@ public class MElementValue extends X_C_ElementValue return success; } // afterSave - /** - * After Delete - * @param success - * @return deleted - */ + @Override protected boolean afterDelete (boolean success) { if (success) diff --git a/migration/352a-trunk/329_BF2320411.sql b/migration/352a-trunk/329_BF2320411.sql new file mode 100644 index 0000000000..9893c42c95 --- /dev/null +++ b/migration/352a-trunk/329_BF2320411.sql @@ -0,0 +1,15 @@ +-- 21.11.2008 14:21:33 EET +-- BF [ 2320411 ] Translate "Already posted to" message +INSERT INTO AD_Message (AD_Client_ID,AD_Message_ID,AD_Org_ID,Created,CreatedBy,EntityType,IsActive,MsgText,MsgType,Updated,UpdatedBy,Value) VALUES (0,53046,0,TO_DATE('2008-11-21 14:21:30','YYYY-MM-DD HH24:MI:SS'),0,'D','Y','Already posted to this account.','E',TO_DATE('2008-11-21 14:21:30','YYYY-MM-DD HH24:MI:SS'),0,'AlreadyPostedTo') +; + +-- 21.11.2008 14:21:33 EET +-- BF [ 2320411 ] Translate "Already posted to" message +INSERT INTO AD_Message_Trl (AD_Language,AD_Message_ID, MsgText,MsgTip, IsTranslated,AD_Client_ID,AD_Org_ID,Created,Createdby,Updated,UpdatedBy) SELECT l.AD_Language,t.AD_Message_ID, t.MsgText,t.MsgTip, 'N',t.AD_Client_ID,t.AD_Org_ID,t.Created,t.Createdby,t.Updated,t.UpdatedBy FROM AD_Language l, AD_Message t WHERE l.IsActive='Y' AND l.IsSystemLanguage='Y' AND l.IsBaseLanguage='N' AND t.AD_Message_ID=53046 AND EXISTS (SELECT * FROM AD_Message_Trl tt WHERE tt.AD_Language!=l.AD_Language OR tt.AD_Message_ID!=t.AD_Message_ID) +; + +-- 21.11.2008 14:22:08 EET +-- BF [ 2320411 ] Translate "Already posted to" message +UPDATE AD_Message_Trl SET IsTranslated='Y',MsgText='Exista inregistrari contabile pe acest cont.',Updated=TO_DATE('2008-11-21 14:22:08','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=0 WHERE AD_Message_ID=53046 AND AD_Language='ro_RO' +; + diff --git a/migration/352a-trunk/postgresql/329_BF2320411.sql b/migration/352a-trunk/postgresql/329_BF2320411.sql new file mode 100644 index 0000000000..d98f4c6227 --- /dev/null +++ b/migration/352a-trunk/postgresql/329_BF2320411.sql @@ -0,0 +1,15 @@ +-- 21.11.2008 14:21:33 EET +-- BF [ 2320411 ] Translate "Already posted to" message +INSERT INTO AD_Message (AD_Client_ID,AD_Message_ID,AD_Org_ID,Created,CreatedBy,EntityType,IsActive,MsgText,MsgType,Updated,UpdatedBy,Value) VALUES (0,53046,0,TO_TIMESTAMP('2008-11-21 14:21:30','YYYY-MM-DD HH24:MI:SS'),0,'D','Y','Already posted to this account.','E',TO_TIMESTAMP('2008-11-21 14:21:30','YYYY-MM-DD HH24:MI:SS'),0,'AlreadyPostedTo') +; + +-- 21.11.2008 14:21:33 EET +-- BF [ 2320411 ] Translate "Already posted to" message +INSERT INTO AD_Message_Trl (AD_Language,AD_Message_ID, MsgText,MsgTip, IsTranslated,AD_Client_ID,AD_Org_ID,Created,Createdby,Updated,UpdatedBy) SELECT l.AD_Language,t.AD_Message_ID, t.MsgText,t.MsgTip, 'N',t.AD_Client_ID,t.AD_Org_ID,t.Created,t.Createdby,t.Updated,t.UpdatedBy FROM AD_Language l, AD_Message t WHERE l.IsActive='Y' AND l.IsSystemLanguage='Y' AND l.IsBaseLanguage='N' AND t.AD_Message_ID=53046 AND EXISTS (SELECT * FROM AD_Message_Trl tt WHERE tt.AD_Language!=l.AD_Language OR tt.AD_Message_ID!=t.AD_Message_ID) +; + +-- 21.11.2008 14:22:08 EET +-- BF [ 2320411 ] Translate "Already posted to" message +UPDATE AD_Message_Trl SET IsTranslated='Y',MsgText='Exista inregistrari contabile pe acest cont.',Updated=TO_TIMESTAMP('2008-11-21 14:22:08','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=0 WHERE AD_Message_ID=53046 AND AD_Language='ro_RO' +; +