AX2009如果想按照批处理号预留,它默认是按照InventBatchId排序的,但并不是InventBatchd小的批次的生产日期就早,所以这个逻辑得改一下,让它按照InventBatch的ProdDate排序。
需要修改几个方法
1.修改InventSum的newQuery
最好创建一个新的方法
client server static Query ERM_NewQuery(
Query query,
ItemId itemId,
InventDim inventDimCriteria,
InventDimParm inventDimParmCriteria,
InventDimParm inventDimParmGroupBy,
container dimFields = InventDim::dimFieldList()
)
{
QueryBuildDataSource qbsSum;
QueryBuildDataSource qbsDim;
//<ERM>
QueryBuildDataSource qbsBatch;
//</ERM>
QueryBuildRange queryRange;
boolean doFindRange;
;
if (!query)
query = new Query();
if (query.dataSourceTable(tablenum(InventSum)))
{
qbsSum = query.dataSourceTable(tablenum(InventSum));
qbsSum.sortClear();
doFindRange = true;
}
else
qbsSum = query.addDataSource(tablenum(InventSum));
if (query.dataSourceTable(tablenum(InventDim)))
{
qbsDim = query.dataSourceTable(tablenum(InventDim));
qbsDim.sortClear();
doFindRange = true;
}
else
qbsDim = qbsSum.addDataSource(tablenum(InventDim));
qbsDim.joinMode(JoinMode::InnerJoin);
qbsDim.relations(true);
//<ERM>
if(query.dataSourceTable(tableNum(InventBatch)))
{
qbsBatch = query.dataSourceTable(tablenum(InventBatch));
qbsBatch.sortClear();
}
else
qbsBatch = qbsDim.addDataSource(tableNum(InventBatch));
qbsBatch.joinMode(JoinMode::InnerJoin);
qbsBatch.relations(true);
//</ERM>
if (!inventDimParmCriteria.ClosedFlag)
{
queryRange = SysQuery::findOrCreateRange(qbsSum, fieldnum(InventSum,Closed));
queryRange.value(queryValue(NoYes::No));
}
if (inventDimParmCriteria.ItemIdFlag)
{
queryRange = doFindRange ? qbsSum.findRange(fieldnum(InventSum,ItemId)) : null;
if (! queryRange)
queryRange = qbsSum.addRange(fieldnum(InventSum,ItemId));
if (itemId)
queryRange.value(queryValue(itemId));
else
queryRange.value(SysQuery::valueEmptyString());
}
if (inventDimParmGroupBy.ItemIdFlag)
{
qbsSum.addSortField(fieldnum(InventSum,ItemId));
qbsSum.orderMode(OrderMode::GroupBy);
}
InventSum::queryAddSumFields(qbsSum);
InventDim::ERM_queryDatasourceAddRangeSortFromParms(qbsDim,qbsBatch,doFindRange,inventDimCriteria,inventDimParmCriteria,inventDimParmGroupBy,dimFields);
InventSum::queryAddHint(query,inventDimCriteria,inventDimParmCriteria,qbsSum,qbsDim);
//info(qbsSum.toString());
return query;
}
主要是增加InventBatch的关联。
2.修改queryDatasourceAddRangeSortFromParms方法,增加ProdDate排序字段
static public void ERM_queryDatasourceAddRangeSortFromParms(
QueryBuildDataSource qbsDim,
QUeryBuildDataSource qbsBatch,
boolean doFindRange,
InventDim inventDimCriteria,
InventDimParm inventDimParmCriteria,
InventDimParm inventDimParmGroupBy,
container dimFields = InventDim::dimFieldList()
)
{
Counter h;
fieldId x,y;
QueryBuildRange queryRange;
boolean doGroupByDim;
for (h=1;h<=conlen(dimFields);h++)
{
y = conpeek(dimFields, h);
x = InventDim::dim2dimParm(conpeek(dimFields, h));
if (inventDimParmCriteria.(x))
{
queryRange = doFindRange ? qbsDim.findRange(y) : null;
if (! queryRange)
queryRange = qbsDim.addRange(y);
if (inventDimCriteria.(y))
queryRange.value(queryValue(inventDimCriteria.(y)));
else
queryRange.value(SysQuery::valueEmptyString());
}
if (inventDimParmGroupBy.(x))
{
qbsDim.addSortField(y);
doGroupByDim = true;
}
}
qbsBatch.addGroupByField(fieldNum(InventBatch,ProdDate));
qbsBatch.addOrderByField(fieldNum(InventBatch,ProdDate),SortOrder::Ascending);
if (doGroupByDim)
qbsDim.orderMode(OrderMode::GroupBy);
else
qbsDim.orderMode(OrderMode::OrderBy);
}
3.修改InventUpd_Reservation的updateMore方法,调用InventSum刚刚创建的newQuery方法构造查询。