From 08c3b3c1becf0884144caea7b5626736c8f2299f Mon Sep 17 00:00:00 2001 From: Nicolas Micoud <58596990+nmicoud@users.noreply.github.com> Date: Wed, 1 Jul 2020 21:34:51 +0200 Subject: [PATCH] =?UTF-8?q?IDEMPIERE-4351=20:=20MJournal/MJournalLine=20:?= =?UTF-8?q?=20fill=20mandatory=20values=20(if=20mi=E2=80=A6=20(#152)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * IDEMPIERE-4351 : MJournal/MJournalLine : fill mandatory values (if missing) in beforeSave methods GL_Journal.C_AcctSchema_ID GL_Journal.C_ConversionType_ID GL_JournalLine.C_Currency_ID GL_JournalLine.C_ConversionType_ID * IDEMPIERE-4351 : MJournal/MJournalLine : fill mandatory Based on Carlos's patch : Fix issues in PO.java that are not allowing the beforeSave methods that complete organization to work * This also has the effect of checking and setting the organization restrictions after beforeSave and EventHandlers have finished, potentially fixing developer errors on org not respecting the configuration on Client Share * In MJournalLine move the setting of org to the top because the getOrCreateCombination method works with the org value Co-Authored-By: Carlos Ruiz Co-authored-by: Carlos Ruiz --- .../src/org/compiere/model/MJournal.java | 4 ++ .../src/org/compiere/model/MJournalLine.java | 19 ++++--- .../src/org/compiere/model/PO.java | 55 ++++++++++--------- 3 files changed, 43 insertions(+), 35 deletions(-) diff --git a/org.adempiere.base/src/org/compiere/model/MJournal.java b/org.adempiere.base/src/org/compiere/model/MJournal.java index 625de44474..e47b50d7f2 100644 --- a/org.adempiere.base/src/org/compiere/model/MJournal.java +++ b/org.adempiere.base/src/org/compiere/model/MJournal.java @@ -332,6 +332,10 @@ public class MJournal extends X_GL_Journal implements DocAction if (getGL_Category_ID() == 0 && getC_DocType_ID() > 0) setGL_Category_ID(MDocType.get(getCtx(), getC_DocType_ID()).getGL_Category_ID()); + if (getC_AcctSchema_ID() == 0) + setC_AcctSchema_ID(MClientInfo.get(getCtx(), getAD_Client_ID()).getC_AcctSchema1_ID()); + if (getC_ConversionType_ID() == 0) + setC_ConversionType_ID(MConversionType.getDefault(getAD_Client_ID())); // IDEMPIERE-63 // for documents that can be reactivated we cannot allow changing diff --git a/org.adempiere.base/src/org/compiere/model/MJournalLine.java b/org.adempiere.base/src/org/compiere/model/MJournalLine.java index b4b84616d3..e5ab2b88e9 100644 --- a/org.adempiere.base/src/org/compiere/model/MJournalLine.java +++ b/org.adempiere.base/src/org/compiere/model/MJournalLine.java @@ -294,6 +294,16 @@ public class MJournalLine extends X_GL_JournalLine log.saveError("ParentComplete", Msg.translate(getCtx(), "GL_JournalLine")); return false; } + + if (getAD_Org_ID() <= 0) // Set Line Org to Doc Org if still not set + setAD_Org_ID(getParent().getAD_Org_ID()); + if (getLine() == 0) + setLine(DB.getSQLValueEx(get_TrxName(), "SELECT COALESCE(MAX(Line), 0) + 10 FROM GL_JournalLine WHERE GL_Journal_ID = ?", getGL_Journal_ID())); + if (getC_Currency_ID() == 0) + setC_Currency_ID(getParent().getC_Currency_ID()); + if (getC_ConversionType_ID() == 0) + setC_ConversionType_ID(getParent().getC_ConversionType_ID()); + // idempiere 344 - nmicoud if (!getOrCreateCombination()) return false; @@ -305,9 +315,6 @@ public class MJournalLine extends X_GL_JournalLine fillDimensionsFromCombination(); // end idempiere 344 - nmicoud - if (getLine() == 0) - setLine(DB.getSQLValueEx(get_TrxName(), "SELECT COALESCE(MAX(Line), 0) + 10 FROM GL_JournalLine WHERE GL_Journal_ID = ?", getGL_Journal_ID())); - // Acct Amts BigDecimal rate = getCurrencyRate(); BigDecimal amt = rate.multiply(getAmtSourceDr()); @@ -318,11 +325,7 @@ public class MJournalLine extends X_GL_JournalLine if (amt.scale() > getPrecision()) amt = amt.setScale(getPrecision(), RoundingMode.HALF_UP); setAmtAcctCr(amt); - // Set Line Org to Doc Org if still not set - if(getAD_Org_ID() <= 0) - { - setAD_Org_ID(getParent().getAD_Org_ID()); - } + return true; } // beforeSave diff --git a/org.adempiere.base/src/org/compiere/model/PO.java b/org.adempiere.base/src/org/compiere/model/PO.java index ba438a998a..7d5ee0fe06 100644 --- a/org.adempiere.base/src/org/compiere/model/PO.java +++ b/org.adempiere.base/src/org/compiere/model/PO.java @@ -2049,33 +2049,6 @@ public abstract class PO } } - // Organization Check - if (getAD_Org_ID() == 0 - && (get_AccessLevel() == ACCESSLEVEL_ORG - || (get_AccessLevel() == ACCESSLEVEL_CLIENTORG - && MClientShare.isOrgLevelOnly(getAD_Client_ID(), get_Table_ID())))) - { - log.saveError("FillMandatory", Msg.getElement(getCtx(), "AD_Org_ID")); - return false; - } - // Should be Org 0 - if (getAD_Org_ID() != 0) - { - boolean reset = get_AccessLevel() == ACCESSLEVEL_SYSTEM; - if (!reset && MClientShare.isClientLevelOnly(getAD_Client_ID(), get_Table_ID())) - { - reset = get_AccessLevel() == ACCESSLEVEL_CLIENT - || get_AccessLevel() == ACCESSLEVEL_SYSTEMCLIENT - || get_AccessLevel() == ACCESSLEVEL_ALL - || get_AccessLevel() == ACCESSLEVEL_CLIENTORG; - } - if (reset) - { - log.warning("Set Org to 0"); - setAD_Org_ID(0); - } - } - Trx localTrx = null; Trx trx = null; Savepoint savepoint = null; @@ -2172,6 +2145,34 @@ public abstract class PO } return false; } + + // Organization Check + if (getAD_Org_ID() == 0 + && (get_AccessLevel() == ACCESSLEVEL_ORG + || (get_AccessLevel() == ACCESSLEVEL_CLIENTORG + && MClientShare.isOrgLevelOnly(getAD_Client_ID(), get_Table_ID())))) + { + log.saveError("FillMandatory", Msg.getElement(getCtx(), "AD_Org_ID")); + return false; + } + // Should be Org 0 + if (getAD_Org_ID() != 0) + { + boolean reset = get_AccessLevel() == ACCESSLEVEL_SYSTEM; + if (!reset && MClientShare.isClientLevelOnly(getAD_Client_ID(), get_Table_ID())) + { + reset = get_AccessLevel() == ACCESSLEVEL_CLIENT + || get_AccessLevel() == ACCESSLEVEL_SYSTEMCLIENT + || get_AccessLevel() == ACCESSLEVEL_ALL + || get_AccessLevel() == ACCESSLEVEL_CLIENTORG; + } + if (reset) + { + log.warning("Set Org to 0"); + setAD_Org_ID(0); + } + } + // Save if (newRecord) {