IDEMPIERE-3117 Wrong period validation on Bank Statement (#2225)
* IDEMPIERE-3117 Wrong period validation on Bank Statement - change statementDate to dateAcct on testPeriod * - peer review --------- Co-authored-by: zuhriutama <zuhriutama@gmail.com>
This commit is contained in:
parent
8879c3fc10
commit
087b936e2b
|
@ -24,6 +24,7 @@ import java.util.List;
|
|||
import java.util.Properties;
|
||||
import java.util.logging.Level;
|
||||
|
||||
import org.adempiere.exceptions.AdempiereException;
|
||||
import org.compiere.process.DocAction;
|
||||
import org.compiere.process.DocumentEngine;
|
||||
import org.compiere.util.DB;
|
||||
|
@ -329,7 +330,7 @@ public class MBankStatement extends X_C_BankStatement implements DocAction
|
|||
return DocAction.STATUS_Invalid;
|
||||
|
||||
// Std Period open?
|
||||
MPeriod.testPeriodOpen(getCtx(), getStatementDate(), getC_DocType_ID(), getAD_Org_ID());
|
||||
MPeriod.testPeriodOpen(getCtx(), getDateAcct(), getC_DocType_ID(), getAD_Org_ID());
|
||||
MBankStatementLine[] lines = getLines(true);
|
||||
if (lines.length == 0)
|
||||
{
|
||||
|
@ -457,7 +458,20 @@ public class MBankStatement extends X_C_BankStatement implements DocAction
|
|||
if (dt.isOverwriteDateOnComplete()) {
|
||||
if (this.getProcessedOn().signum() == 0) {
|
||||
setStatementDate(TimeUtil.getDay(0));
|
||||
MPeriod.testPeriodOpen(getCtx(), getStatementDate(), getC_DocType_ID(), getAD_Org_ID());
|
||||
if (getDateAcct().before(getStatementDate())) {
|
||||
setDateAcct(getStatementDate());
|
||||
MPeriod.testPeriodOpen(getCtx(), getDateAcct(), getC_DocType_ID(), getAD_Org_ID());
|
||||
if (isPostWithDateFromLine(getAD_Client_ID())) {
|
||||
// because the accounting date changed we need to validate again if each line still lands in the same period
|
||||
for (MBankStatementLine bl : getLines(false)) {
|
||||
if (!bl.isDateConsistentIfUsedForPosting(getDateAcct())) {
|
||||
throw new AdempiereException(
|
||||
Msg.getMsg(getCtx(), "ParentCannotChange", new Object[] {Msg.getElement(getCtx(), "DateAcct")}) + " - " +
|
||||
Msg.getMsg(getCtx(), "BankStatementLinePeriodNotSameAsHeader", new Object[] {bl.getLine()}));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (dt.isOverwriteSeqOnComplete()) {
|
||||
|
@ -501,7 +515,7 @@ public class MBankStatement extends X_C_BankStatement implements DocAction
|
|||
// Std Period open?
|
||||
else
|
||||
{
|
||||
MPeriod.testPeriodOpen(getCtx(), getStatementDate(), getC_DocType_ID(), getAD_Org_ID());
|
||||
MPeriod.testPeriodOpen(getCtx(), getDateAcct(), getC_DocType_ID(), getAD_Org_ID());
|
||||
MFactAcct.deleteEx(Table_ID, getC_BankStatement_ID(), get_TrxName());
|
||||
}
|
||||
|
||||
|
|
|
@ -43,9 +43,9 @@ import org.compiere.util.Util;
|
|||
public class MBankStatementLine extends X_C_BankStatementLine
|
||||
{
|
||||
/**
|
||||
* generated serial id
|
||||
*
|
||||
*/
|
||||
private static final long serialVersionUID = -4479911757321927051L;
|
||||
private static final long serialVersionUID = 2604381588523683439L;
|
||||
|
||||
/**
|
||||
* UUID based Constructor
|
||||
|
@ -313,8 +313,17 @@ import org.compiere.util.Util;
|
|||
* @return true if not using date from statement line or header and line is in the same financial period
|
||||
*/
|
||||
public boolean isDateConsistentIfUsedForPosting() {
|
||||
return isDateConsistentIfUsedForPosting(getParent().getDateAcct());
|
||||
}
|
||||
|
||||
/**
|
||||
* If the posting is based on the date of the line (ie SysConfig BANK_STATEMENT_POST_WITH_DATE_FROM_LINE = Y), make sure line and header dates are in the same financial period
|
||||
* @param headerDateAcct
|
||||
* @return true if not using date from statement line or header and line is in the same financial period
|
||||
*/
|
||||
public boolean isDateConsistentIfUsedForPosting(Timestamp headerDateAcct) {
|
||||
if (MBankStatement.isPostWithDateFromLine(getAD_Client_ID())) {
|
||||
MPeriod headerPeriod = MPeriod.get(getCtx(), getParent().getDateAcct(), getParent().getAD_Org_ID(), get_TrxName());
|
||||
MPeriod headerPeriod = MPeriod.get(getCtx(), headerDateAcct, getParent().getAD_Org_ID(), get_TrxName());
|
||||
MPeriod linePeriod = MPeriod.get(getCtx(), getDateAcct(), getParent().getAD_Org_ID(), get_TrxName());
|
||||
|
||||
return headerPeriod != null && linePeriod != null && headerPeriod.getC_Period_ID() == linePeriod.getC_Period_ID();
|
||||
|
|
|
@ -347,8 +347,6 @@ public class MPeriod extends X_C_Period implements ImmutablePOSupport
|
|||
idxdate = po.get_ColumnIndex("MovementDate");
|
||||
} else if ( tableID == MRequisition.Table_ID) {
|
||||
idxdate = po.get_ColumnIndex("DateDoc");
|
||||
} else if ( tableID == MBankStatement.Table_ID) {
|
||||
idxdate = po.get_ColumnIndex("StatementDate");
|
||||
} else if ( tableID == MAllocationHdr.Table_ID
|
||||
|| tableID == MMatchInv.Table_ID
|
||||
|| tableID == MMatchPO.Table_ID) {
|
||||
|
|
Loading…
Reference in New Issue