IDEMPIERE-3854 Conversion rate must validate period overlapping

This commit is contained in:
Carlos Ruiz 2018-12-25 21:39:51 +01:00
parent f3851b4688
commit 426951381c
3 changed files with 162 additions and 3 deletions

View File

@ -0,0 +1,55 @@
SET SQLBLANKLINES ON
SET DEFINE OFF
-- IDEMPIERE-3853 Bug in Auto Allocation
-- Dec 25, 2018, 8:48:26 PM CET
UPDATE C_Conversion_Rate SET IsActive='N',Updated=TO_DATE('2018-12-25 20:48:26','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=100 WHERE C_Conversion_Rate_ID=137
;
-- Dec 25, 2018, 8:48:28 PM CET
UPDATE C_Conversion_Rate SET IsActive='N',Updated=TO_DATE('2018-12-25 20:48:28','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=100 WHERE C_Conversion_Rate_ID=138
;
-- Dec 25, 2018, 8:56:17 PM CET
UPDATE AD_TableIndex SET IsUnique='Y',Updated=TO_DATE('2018-12-25 20:56:17','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=100 WHERE AD_TableIndex_ID=200400
;
-- Dec 25, 2018, 8:56:20 PM CET
DROP INDEX c_conversionrate_once
;
-- Dec 25, 2018, 8:56:20 PM CET
CREATE UNIQUE INDEX c_conversionrate_once ON C_Conversion_Rate (AD_Client_ID,AD_Org_ID,C_Currency_ID,C_Currency_ID_To,C_ConversionType_ID,ValidFrom)
;
-- Dec 25, 2018, 9:34:13 PM CET
UPDATE AD_Column SET IsUpdateable='N',Updated=TO_DATE('2018-12-25 21:34:13','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=100 WHERE AD_Column_ID=10294
;
-- Dec 25, 2018, 9:34:19 PM CET
UPDATE AD_Column SET IsUpdateable='N',Updated=TO_DATE('2018-12-25 21:34:19','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=100 WHERE AD_Column_ID=786
;
-- Dec 25, 2018, 9:34:23 PM CET
UPDATE AD_Column SET IsUpdateable='N',Updated=TO_DATE('2018-12-25 21:34:23','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=100 WHERE AD_Column_ID=787
;
-- Dec 25, 2018, 9:34:34 PM CET
UPDATE AD_Column SET IsUpdateable='N',Updated=TO_DATE('2018-12-25 21:34:34','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=100 WHERE AD_Column_ID=453
;
-- Dec 25, 2018, 9:34:49 PM CET
UPDATE AD_Column SET IsUpdateable='N',Updated=TO_DATE('2018-12-25 21:34:49','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=100 WHERE AD_Column_ID=454
;
-- Dec 25, 2018, 9:35:46 PM CET
UPDATE AD_Field SET IsMandatory='Y', AD_Reference_Value_ID=NULL, AD_Val_Rule_ID=NULL, IsToolbarButton=NULL,Updated=TO_DATE('2018-12-25 21:35:46','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=100 WHERE AD_Field_ID=436
;
-- Dec 25, 2018, 9:35:47 PM CET
UPDATE AD_Field SET IsMandatory='Y', AD_Reference_Value_ID=NULL, AD_Val_Rule_ID=NULL, IsToolbarButton=NULL,Updated=TO_DATE('2018-12-25 21:35:47','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=100 WHERE AD_Field_ID=1339
;
SELECT register_migration_script('201812252049_IDEMPIERE-3853.sql') FROM dual
;

View File

@ -0,0 +1,52 @@
-- IDEMPIERE-3853 Bug in Auto Allocation
-- Dec 25, 2018, 8:48:26 PM CET
UPDATE C_Conversion_Rate SET IsActive='N',Updated=TO_TIMESTAMP('2018-12-25 20:48:26','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=100 WHERE C_Conversion_Rate_ID=137
;
-- Dec 25, 2018, 8:48:28 PM CET
UPDATE C_Conversion_Rate SET IsActive='N',Updated=TO_TIMESTAMP('2018-12-25 20:48:28','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=100 WHERE C_Conversion_Rate_ID=138
;
-- Dec 25, 2018, 8:56:17 PM CET
UPDATE AD_TableIndex SET IsUnique='Y',Updated=TO_TIMESTAMP('2018-12-25 20:56:17','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=100 WHERE AD_TableIndex_ID=200400
;
-- Dec 25, 2018, 8:56:20 PM CET
DROP INDEX c_conversionrate_once
;
-- Dec 25, 2018, 8:56:20 PM CET
CREATE UNIQUE INDEX c_conversionrate_once ON C_Conversion_Rate (AD_Client_ID,AD_Org_ID,C_Currency_ID,C_Currency_ID_To,C_ConversionType_ID,ValidFrom)
;
-- Dec 25, 2018, 9:34:13 PM CET
UPDATE AD_Column SET IsUpdateable='N',Updated=TO_TIMESTAMP('2018-12-25 21:34:13','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=100 WHERE AD_Column_ID=10294
;
-- Dec 25, 2018, 9:34:19 PM CET
UPDATE AD_Column SET IsUpdateable='N',Updated=TO_TIMESTAMP('2018-12-25 21:34:19','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=100 WHERE AD_Column_ID=786
;
-- Dec 25, 2018, 9:34:23 PM CET
UPDATE AD_Column SET IsUpdateable='N',Updated=TO_TIMESTAMP('2018-12-25 21:34:23','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=100 WHERE AD_Column_ID=787
;
-- Dec 25, 2018, 9:34:34 PM CET
UPDATE AD_Column SET IsUpdateable='N',Updated=TO_TIMESTAMP('2018-12-25 21:34:34','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=100 WHERE AD_Column_ID=453
;
-- Dec 25, 2018, 9:34:49 PM CET
UPDATE AD_Column SET IsUpdateable='N',Updated=TO_TIMESTAMP('2018-12-25 21:34:49','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=100 WHERE AD_Column_ID=454
;
-- Dec 25, 2018, 9:35:46 PM CET
UPDATE AD_Field SET IsMandatory='Y', AD_Reference_Value_ID=NULL, AD_Val_Rule_ID=NULL, IsToolbarButton=NULL,Updated=TO_TIMESTAMP('2018-12-25 21:35:46','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=100 WHERE AD_Field_ID=436
;
-- Dec 25, 2018, 9:35:47 PM CET
UPDATE AD_Field SET IsMandatory='Y', AD_Reference_Value_ID=NULL, AD_Val_Rule_ID=NULL, IsToolbarButton=NULL,Updated=TO_TIMESTAMP('2018-12-25 21:35:47','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=100 WHERE AD_Field_ID=1339
;
SELECT register_migration_script('201812252049_IDEMPIERE-3853.sql') FROM dual
;

View File

@ -46,7 +46,7 @@ public class MConversionRate extends X_C_Conversion_Rate
/**
*
*/
private static final long serialVersionUID = -7938144674700640228L;
private static final long serialVersionUID = -3866898973541150020L;
/** Logger */
private static CLogger s_log = CLogger.getCLogger (MConversionRate.class);
@ -442,7 +442,59 @@ public class MConversionRate extends X_C_Conversion_Rate
return false;
}
if (isActive()) {
String whereClause = "(? BETWEEN ValidFrom AND ValidTo OR ? BETWEEN ValidFrom AND ValidTo) "
+ "AND C_Currency_ID=? AND C_Currency_ID_To=? "
+ "AND C_Conversiontype_ID=? "
+ "AND AD_Client_ID=? AND AD_Org_ID=?";
List<MConversionRate> convs = new Query(getCtx(), MConversionRate.Table_Name, whereClause, get_TrxName())
.setOnlyActiveRecords(true)
.setParameters(getValidFrom(), getValidTo(),
getC_Currency_ID(), getC_Currency_ID_To(),
getC_ConversionType_ID(),
getAD_Client_ID(), getAD_Org_ID())
.list();
for (MConversionRate conv : convs) {
if (conv.getC_Conversion_Rate_ID() != getC_Conversion_Rate_ID()) {
log.saveError("Error", "Conversion rate overlaps with: " + conv.getValidFrom());
return false;
}
}
}
return true;
} // beforeSave
@Override
protected boolean afterSave(boolean newRecord, boolean success) {
if (success) {
String whereClause = "ValidFrom=? AND ValidTo=? "
+ "AND C_Currency_ID=? AND C_Currency_ID_To=? "
+ "AND C_ConversionType_ID=? "
+ "AND AD_Client_ID=? AND AD_Org_ID=?";
MConversionRate reciprocal = new Query(getCtx(), MConversionRate.Table_Name, whereClause, get_TrxName())
.setParameters(getValidFrom(), getValidTo(),
getC_Currency_ID_To(), getC_Currency_ID(),
getC_ConversionType_ID(),
getAD_Client_ID(), getAD_Org_ID())
.firstOnly();
if (reciprocal == null) {
// create reciprocal rate
reciprocal = new MConversionRate(getCtx(), 0, get_TrxName());
reciprocal.setValidFrom(getValidFrom());
reciprocal.setValidTo(getValidTo());
reciprocal.setC_ConversionType_ID(getC_ConversionType_ID());
reciprocal.setAD_Client_ID(getAD_Client_ID());
reciprocal.setAD_Org_ID(getAD_Org_ID());
// invert
reciprocal.setC_Currency_ID(getC_Currency_ID_To());
reciprocal.setC_Currency_ID_To(getC_Currency_ID());
}
reciprocal.setDivideRate(getMultiplyRate());
reciprocal.setMultiplyRate(getDivideRate());
reciprocal.saveEx();
}
return success;
}
} // MConversionRate