IDEMPIERE-813 DateAcct in GL_JournalLine is not validated to be within the same period of GL_Journal

This commit is contained in:
Carlos Ruiz 2019-12-23 15:11:53 +01:00
parent ce48eda1e5
commit 7b2c99fa86
1 changed files with 38 additions and 26 deletions

View File

@ -20,6 +20,7 @@ import java.io.File;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.sql.ResultSet; import java.sql.ResultSet;
import java.sql.Timestamp; import java.sql.Timestamp;
import java.text.SimpleDateFormat;
import java.util.List; import java.util.List;
import java.util.Properties; import java.util.Properties;
import java.util.logging.Level; import java.util.logging.Level;
@ -457,34 +458,10 @@ public class MJournal extends X_GL_Journal implements DocAction
m_processMsg = ModelValidationEngine.get().fireDocValidate(this, ModelValidator.TIMING_BEFORE_PREPARE); m_processMsg = ModelValidationEngine.get().fireDocValidate(this, ModelValidator.TIMING_BEFORE_PREPARE);
if (m_processMsg != null) if (m_processMsg != null)
return DocAction.STATUS_Invalid; return DocAction.STATUS_Invalid;
MDocType dt = MDocType.get(getCtx(), getC_DocType_ID());
// Get Period m_processMsg = validatePeriod(getDateAcct());
MPeriod period = (MPeriod) getC_Period(); if (m_processMsg != null)
if (! period.isInPeriod(getDateAcct())) {
period = MPeriod.get (getCtx(), getDateAcct(), getAD_Org_ID(), get_TrxName());
if (period == null)
{
log.warning("No Period for " + getDateAcct());
m_processMsg = "@PeriodNotFound@";
return DocAction.STATUS_Invalid;
}
// Standard Period
if (period.getC_Period_ID() != getC_Period_ID()
&& period.isStandardPeriod())
{
m_processMsg = "@PeriodNotValid@";
return DocAction.STATUS_Invalid;
}
}
boolean open = period.isOpen(dt.getDocBaseType(), getDateAcct());
if (!open)
{
log.warning(period.getName()
+ ": Not open for " + dt.getDocBaseType() + " (" + getDateAcct() + ")");
m_processMsg = "@PeriodClosed@";
return DocAction.STATUS_Invalid; return DocAction.STATUS_Invalid;
}
// Lines // Lines
MJournalLine[] lines = getLines(true); MJournalLine[] lines = getLines(true);
@ -502,6 +479,12 @@ public class MJournal extends X_GL_Journal implements DocAction
MJournalLine line = lines[i]; MJournalLine line = lines[i];
if (!isActive()) if (!isActive())
continue; continue;
if (! line.getDateAcct().equals(getDateAcct())) {
m_processMsg = validatePeriod(line.getDateAcct());
if (m_processMsg != null)
return DocAction.STATUS_Invalid;
}
// bcahya, BF [2789319] No check of Actual, Budget, Statistical attribute // bcahya, BF [2789319] No check of Actual, Budget, Statistical attribute
if (!line.getAccountElementValue().isActive()) if (!line.getAccountElementValue().isActive())
@ -584,6 +567,35 @@ public class MJournal extends X_GL_Journal implements DocAction
return DocAction.STATUS_InProgress; return DocAction.STATUS_InProgress;
} // prepareIt } // prepareIt
private String validatePeriod(Timestamp dateAcct) {
// Get Period
MDocType dt = MDocType.get(getCtx(), getC_DocType_ID());
MPeriod period = (MPeriod) getC_Period();
SimpleDateFormat dateFormat = DisplayType.getDateFormat(DisplayType.Date);
if (! period.isInPeriod(dateAcct)) {
period = MPeriod.get (getCtx(), dateAcct, getAD_Org_ID(), get_TrxName());
if (period == null)
{
log.warning("No Period for " + dateAcct);
return "@PeriodNotFound@ -> " + dateFormat.format(dateAcct);
}
// Standard Period
if (period.getC_Period_ID() != getC_Period_ID() && period.isStandardPeriod())
{
log.warning("No Period for " + dateAcct);
return "@PeriodNotValid@ -> " + dateFormat.format(dateAcct);
}
}
boolean open = period.isOpen(dt.getDocBaseType(), dateAcct);
if (!open)
{
log.warning(period.getName() + ": Not open for " + dt.getDocBaseType() + " (" + dateAcct + ")");
return "@PeriodClosed@ -> " + dateFormat.format(dateAcct);
}
return null;
}
/** /**
* Approve Document * Approve Document
* @return true if success * @return true if success