use of org.eevolution.model.MWMDefinition in project adempiere by adempiere.
the class WMRuleEngine method applyDefinition.
/**
* Apply Definition for Warehouse Strategy
* @param inOutBoundLine Order Bound Line
* @param warehouseAreaTypeId Area Type Id
* @param warehouseSectionTypeId Section Type Id
* */
private MWMStrategy applyDefinition(MWMInOutBoundLine inOutBoundLine, int warehouseAreaTypeId, int warehouseSectionTypeId) {
StringBuffer whereClause = new StringBuffer("(");
whereClause.append(MWMDefinition.COLUMNNAME_M_Product_ID + " IN (0,?) OR ");
whereClause.append(MWMDefinition.COLUMNNAME_M_Product_ID + " IS NULL");
whereClause.append(") AND ");
whereClause.append("(");
whereClause.append(MWMDefinition.COLUMNNAME_M_Product_Category_ID + " IN (0,?) OR ");
whereClause.append(MWMDefinition.COLUMNNAME_M_Product_Category_ID + " IS NULL");
whereClause.append(") AND ");
whereClause.append("(");
whereClause.append(MWMDefinition.COLUMNNAME_Group1 + " IN ('',?) OR ");
whereClause.append(MWMDefinition.COLUMNNAME_Group1 + " IS NULL");
whereClause.append(") AND ");
whereClause.append("(");
whereClause.append(MWMDefinition.COLUMNNAME_Group2 + " IN ('',?) OR ");
whereClause.append(MWMDefinition.COLUMNNAME_Group2 + " IS NULL");
whereClause.append(") AND ");
whereClause.append("(");
whereClause.append(MWMDefinition.COLUMNNAME_Classification + " IN ('',?) OR ");
whereClause.append(MWMDefinition.COLUMNNAME_Classification + " IS NULL");
whereClause.append(") AND ");
whereClause.append("(");
whereClause.append(MWMDefinition.COLUMNNAME_C_BPartner_ID + " IN (0,?) OR ");
whereClause.append(MWMDefinition.COLUMNNAME_C_BPartner_ID + " IS NULL");
whereClause.append(") AND ");
whereClause.append("(");
whereClause.append(MWMDefinition.COLUMNNAME_C_BP_Group_ID + " IN (0,?) OR ");
whereClause.append(MWMDefinition.COLUMNNAME_C_BP_Group_ID + " IS NULL");
whereClause.append(") AND ");
whereClause.append("(");
whereClause.append(MWMDefinition.COLUMNNAME_WM_Area_Type_ID + " IN (0,?) OR ");
whereClause.append(MWMDefinition.COLUMNNAME_WM_Area_Type_ID + " IS NULL");
whereClause.append(") AND ");
whereClause.append("(");
whereClause.append(MWMDefinition.COLUMNNAME_WM_Section_Type_ID + " IN (0,?) OR ");
whereClause.append(MWMDefinition.COLUMNNAME_WM_Section_Type_ID + " IS NULL");
whereClause.append(")");
whereClause.append(" AND EXISTS (SELECT 1 FROM " + MWMStrategy.Table_Name);
whereClause.append(" WHERE ");
whereClause.append(MWMStrategy.Table_Name + "." + MWMStrategy.COLUMNNAME_WM_Strategy_ID + "=");
whereClause.append(MWMDefinition.Table_Name + "." + MWMDefinition.COLUMNNAME_WM_Strategy_ID);
whereClause.append(" AND ");
whereClause.append(MWMStrategy.COLUMNNAME_InOutBoundType + "=?");
whereClause.append(")");
MProduct product = inOutBoundLine.getMProduct();
MBPartner partner = inOutBoundLine.getBPartner();
MWMDefinition definition = new Query(inOutBoundLine.getCtx(), MWMDefinition.Table_Name, whereClause.toString(), inOutBoundLine.get_TrxName()).setClient_ID().setParameters(product.getM_Product_ID(), product.getM_Product_Category_ID(), product.getGroup1(), product.getGroup2(), product.getClassification(), partner.getC_BPartner_ID(), partner.getC_BP_Group_ID(), warehouseAreaTypeId, warehouseSectionTypeId, MWMStrategy.INOUTBOUNDTYPE_OutboundOperation).first();
if (definition == null) {
throw new AdempiereException("@WM_Definition_ID@ @NotFound@");
}
return definition.getWarehouseStrategy();
}
Aggregations