예제 #1
0
  @Override
  public I_M_DeliveryDay_Alloc getCreateDeliveryDayAlloc(
      final IContextAware context, final IDeliveryDayAllocable model) {
    final IDeliveryDayDAO deliveryDayDAO = Services.get(IDeliveryDayDAO.class);

    final PlainDeliveryDayQueryParams deliveryDayMatchingParams =
        createDeliveryDayQueryParams(model);

    //
    //
    I_M_DeliveryDay_Alloc deliveryDayAlloc =
        deliveryDayDAO.retrieveDeliveryDayAllocForModel(context, model);
    if (deliveryDayAlloc != null) {
      final I_M_DeliveryDay deliveryDayCurrent = deliveryDayAlloc.getM_DeliveryDay();

      if (!deliveryDayDAO.isDeliveryDayMatches(deliveryDayCurrent, deliveryDayMatchingParams)) {
        // Delivery Date is not matching anymore => we need to destroy this allocation
        InterfaceWrapperHelper.delete(deliveryDayAlloc);
        deliveryDayAlloc = null;
      }
    }

    //
    // Create a new Delivery Day Allocation if we don't have one yet
    // ... and get the the Delivery Day record
    if (deliveryDayAlloc == null) {
      deliveryDayMatchingParams.setProcessed(false); // only not processed delivery days
      final I_M_DeliveryDay deliveryDay =
          deliveryDayDAO.retrieveDeliveryDay(context, deliveryDayMatchingParams);
      if (deliveryDay != null) {
        deliveryDayAlloc = createDeliveryDayAlloc(context, deliveryDay, model);
      }
    }

    return deliveryDayAlloc;
  }
예제 #2
0
  private I_M_DeliveryDay_Alloc createDeliveryDayAlloc(
      final IContextAware context,
      final I_M_DeliveryDay deliveryDay,
      final IDeliveryDayAllocable deliveryDayAllocable) {
    Check.assume(
        !deliveryDay.isProcessed(), "Delivery day shall not be processed: {0}", deliveryDay);

    final String tableName = deliveryDayAllocable.getTableName();
    final int adTableId = Services.get(IADTableDAO.class).retrieveTableId(tableName);

    final I_M_DeliveryDay_Alloc deliveryDayAlloc =
        InterfaceWrapperHelper.newInstance(I_M_DeliveryDay_Alloc.class, context);
    deliveryDayAlloc.setAD_Org_ID(deliveryDayAllocable.getAD_Org_ID());
    deliveryDayAlloc.setM_DeliveryDay(deliveryDay);
    deliveryDayAlloc.setAD_Table_ID(adTableId);
    deliveryDayAlloc.setRecord_ID(deliveryDayAllocable.getRecord_ID());
    deliveryDayAlloc.setM_Product_ID(deliveryDayAllocable.getM_Product_ID());

    deliveryDayHandlers.updateDeliveryDayAllocFromModel(deliveryDayAlloc, deliveryDayAllocable);

    InterfaceWrapperHelper.save(deliveryDayAlloc);

    return deliveryDayAlloc;
  }