Skip to content

Commit

Permalink
#2450 Forecast Run has an issue generating the first run when the For…
Browse files Browse the repository at this point in the history
…ecast Run Master table is empty. Currently, it will only generate new entries if entries already exist. (#2451)

See #2450
Fixes #2450
  • Loading branch information
mckayERP authored and yamelsenih committed Aug 17, 2019
1 parent ffe26b6 commit 2798e20
Showing 1 changed file with 32 additions and 3 deletions.
Expand Up @@ -162,6 +162,8 @@ private int createForecastRunResult(int M_Warehouse_ID) {
DataSet series = new DataSet();
series.setPeriods(m_run.getPeriodHistory());
MProduct product = MProduct.get(getCtx(), master.getM_Product_ID());
if (product == null)
continue;

List<MPPForecastRunDetail> details = MPPForecastRunMaster
.getDetails(getCtx(), master.get_ID(), get_TrxName());
Expand Down Expand Up @@ -250,7 +252,8 @@ private int generateForecastRunMaster(MPPForecastRun run,
int count = 0;
for (MPPForecastDefinitionLine fdl : fd.getLines(true)) {
final StringBuffer select = new StringBuffer(
"SELECT DISTINCT sh.M_Product_ID , sh.M_Warehouse_ID FROM C_SalesHistory sh LEFT JOIN PP_ForecastRunMaster m ON (m.M_Product_ID=sh.M_Product_ID AND ");
"SELECT DISTINCT sh.M_Product_ID , sh.M_Warehouse_ID FROM C_SalesHistory sh "
+ "LEFT JOIN PP_ForecastRunMaster m ON (m.M_Product_ID=sh.M_Product_ID AND ");
select.append(MPPForecastRunMaster.COLUMNNAME_PP_ForecastRun_ID);
select.append("=").append(run.get_ID()).append(" ) WHERE ");
select.append(fdl.getSQlWhere(run.getM_WarehouseSource_ID(), "sh"));
Expand All @@ -260,6 +263,7 @@ private int generateForecastRunMaster(MPPForecastRun run,
select.append(" AND ");
select.append(DB.TO_DATE(end.getEndDate()));

MPPForecastRunMaster master = null;
PreparedStatement pstmt = null;
ResultSet rs = null;
try {
Expand All @@ -268,12 +272,14 @@ private int generateForecastRunMaster(MPPForecastRun run,
while (rs.next()) {
count++;
int M_Product_ID = rs.getInt("M_Product_ID");
MPPForecastRunMaster master = MPPForecastRunMaster
master = MPPForecastRunMaster
.getByProduct(getCtx(), run.getPP_ForecastRun_ID(),
M_Product_ID, get_TrxName());
if (master != null)
{
continue;

}

master = new MPPForecastRunMaster(getCtx(), 0,
get_TrxName());

Expand All @@ -290,6 +296,7 @@ private int generateForecastRunMaster(MPPForecastRun run,
master.setFactorScale(fdl.getFactorScale());
master.setFactorUser(fdl.getFactorUser());
master.saveEx();

}
} catch (Exception e) {
log.log(Level.SEVERE, select.toString(), e);
Expand All @@ -300,6 +307,28 @@ private int generateForecastRunMaster(MPPForecastRun run,
rs = null;
pstmt = null;
}

if (master == null)
{
count++;
master = new MPPForecastRunMaster(getCtx(), 0,
get_TrxName());

master.setAD_Org_ID(run.getAD_Org_ID());
master.setPP_ForecastRun_ID(run.get_ID());
master.setPP_ForecastDefinitionLine_ID(fdl
.getPP_ForecastDefinitionLine_ID());
master.setM_Product_ID(fdl.getM_Product_ID()); // TODO - may be zero?
master.setM_Warehouse_ID(run.getM_Warehouse_ID());
master.setFactorAlpha(fdl.getFactorAlpha());
master.setFactorGamma(fdl.getFactorGamma());
master.setFactorBeta(fdl.getFactorBeta());
master.setFactorMultiplier(fdl.getFactorMultiplier());
master.setFactorScale(fdl.getFactorScale());
master.setFactorUser(fdl.getFactorUser());
master.saveEx();

}
}
return count;
}
Expand Down

0 comments on commit 2798e20

Please sign in to comment.