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:
Carlos Ruiz 2024-02-03 13:30:54 +01:00
parent 8879c3fc10
commit 087b936e2b
3 changed files with 31 additions and 10 deletions

View File

@ -24,6 +24,7 @@ import java.util.List;
import java.util.Properties; import java.util.Properties;
import java.util.logging.Level; import java.util.logging.Level;
import org.adempiere.exceptions.AdempiereException;
import org.compiere.process.DocAction; import org.compiere.process.DocAction;
import org.compiere.process.DocumentEngine; import org.compiere.process.DocumentEngine;
import org.compiere.util.DB; import org.compiere.util.DB;
@ -329,7 +330,7 @@ public class MBankStatement extends X_C_BankStatement implements DocAction
return DocAction.STATUS_Invalid; return DocAction.STATUS_Invalid;
// Std Period open? // 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); MBankStatementLine[] lines = getLines(true);
if (lines.length == 0) if (lines.length == 0)
{ {
@ -457,7 +458,20 @@ public class MBankStatement extends X_C_BankStatement implements DocAction
if (dt.isOverwriteDateOnComplete()) { if (dt.isOverwriteDateOnComplete()) {
if (this.getProcessedOn().signum() == 0) { if (this.getProcessedOn().signum() == 0) {
setStatementDate(TimeUtil.getDay(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()) { if (dt.isOverwriteSeqOnComplete()) {
@ -501,7 +515,7 @@ public class MBankStatement extends X_C_BankStatement implements DocAction
// Std Period open? // Std Period open?
else 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()); MFactAcct.deleteEx(Table_ID, getC_BankStatement_ID(), get_TrxName());
} }

View File

@ -42,12 +42,12 @@ import org.compiere.util.Util;
*/ */
public class MBankStatementLine extends X_C_BankStatementLine 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 * UUID based Constructor
* @param ctx Context * @param ctx Context
* @param C_BankStatementLine_UU UUID key * @param C_BankStatementLine_UU UUID key
@ -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 * @return true if not using date from statement line or header and line is in the same financial period
*/ */
public boolean isDateConsistentIfUsedForPosting() { 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())) { 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()); 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(); return headerPeriod != null && linePeriod != null && headerPeriod.getC_Period_ID() == linePeriod.getC_Period_ID();

View File

@ -347,8 +347,6 @@ public class MPeriod extends X_C_Period implements ImmutablePOSupport
idxdate = po.get_ColumnIndex("MovementDate"); idxdate = po.get_ColumnIndex("MovementDate");
} else if ( tableID == MRequisition.Table_ID) { } else if ( tableID == MRequisition.Table_ID) {
idxdate = po.get_ColumnIndex("DateDoc"); idxdate = po.get_ColumnIndex("DateDoc");
} else if ( tableID == MBankStatement.Table_ID) {
idxdate = po.get_ColumnIndex("StatementDate");
} else if ( tableID == MAllocationHdr.Table_ID } else if ( tableID == MAllocationHdr.Table_ID
|| tableID == MMatchInv.Table_ID || tableID == MMatchInv.Table_ID
|| tableID == MMatchPO.Table_ID) { || tableID == MMatchPO.Table_ID) {