private int getAD_Client_ID_ToUse() { if (_adClientId != null) { return _adClientId; } else if (_mrpContext != null) { return _mrpContext.getAD_Client_ID(); } return -1; }
@Override public void cleanup(final IMRPContext mrpContext, final IMRPExecutor executor) { // If DRP module is not activated, then skip the cleanup if (!mrpContext.isRequireDRP()) { return; } final IQueryBL queryBL = Services.get(IQueryBL.class); // // Delete generated distribution orders // (i.e. Distribution Order with Draft Status) final ICompositeQueryFilter<I_DD_Order> filters = queryBL.createCompositeQueryFilter(I_DD_Order.class); filters.addEqualsFilter(I_DD_Order.COLUMNNAME_DocStatus, X_DD_Order.DOCSTATUS_Drafted); // // Only those which were generated by MRP filters.addEqualsFilter(I_DD_Order.COLUMN_MRP_Generated, true); // Only those which are allowed to be deleted by MRP cleanup filters.addEqualsFilter(I_DD_Order.COLUMN_MRP_AllowCleanup, true); // // Only for our AD_Client_ID filters.addEqualsFilter(I_DD_Order.COLUMNNAME_AD_Client_ID, mrpContext.getAD_Client_ID()); // // Only for our AD_Org_ID filters.addEqualsFilter(I_DD_Order.COLUMNNAME_AD_Org_ID, mrpContext.getAD_Org().getAD_Org_ID()); // // Only those DD Orders which are from our Plant or does not have a plant at all filters.addInArrayFilter( I_DD_Order.COLUMNNAME_PP_Plant_ID, null, mrpContext.getPlant().getS_Resource_ID()); // // Only those which have a line with Destination Warehouse same as our warehouse final int targetWarehouseId = mrpContext.getM_Warehouse().getM_Warehouse_ID(); filters.addFilter( Services.get(IDDOrderDAO.class) .getDDOrdersForTargetWarehouseQueryFilter(targetWarehouseId)); // // If we are running in an constrained MRP Context, filter only those documents if (mrpContext.getEnforced_PP_MRP_Demand_ID() > 0) { final IQuery<I_PP_MRP> mrpQuery = createMRPQueryBuilderForCleanup(mrpContext, executor) .createQueryBuilder() .addEqualsFilter(I_PP_MRP.COLUMN_TypeMRP, X_PP_MRP.TYPEMRP_Supply) .create(); filters.addInSubQueryFilter( I_DD_Order.COLUMN_DD_Order_ID, I_PP_MRP.COLUMN_DD_Order_ID, mrpQuery); } deletePO(mrpContext, executor, I_DD_Order.class, filters); }