IDEMPIERE-4351 : MJournal/MJournalLine : fill mandatory values (if mi… (#152)

* 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 <carg67@gmail.com>

Co-authored-by: Carlos Ruiz <carg67@gmail.com>
This commit is contained in:
Nicolas Micoud 2020-07-01 21:34:51 +02:00 committed by GitHub
parent 11c9ad6c59
commit 08c3b3c1be
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 43 additions and 35 deletions

View File

@ -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

View File

@ -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

View File

@ -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)
{