示例#1
0
  @Override
  public String modelChange(final PO po, final int type) throws Exception {
    if (type == TYPE_BEFORE_CHANGE) {
      final I_C_Order order = InterfaceWrapperHelper.create(po, I_C_Order.class);

      if (po.is_ValueChanged(I_C_Invoice_Candidate.COLUMNNAME_DateOrdered)) {
        final IOrderPA orderPA = Services.get(IOrderPA.class);
        final IInvoiceCandDAO invoiceCandDB = Services.get(IInvoiceCandDAO.class);

        for (final I_C_OrderLine ol : orderPA.retrieveOrderLines(order, I_C_OrderLine.class)) {
          for (final I_C_Invoice_Candidate icOfOl : invoiceCandDB.retrieveReferencing(ol)) {
            if (icOfOl.isToClear()) {
              // If the column was updatable, we would have to
              // *check if new and old term are the same
              // *check if ICAs need update, creation or deletion and do it;
              // *check which dataEntries' ActualQty needs update and make sure that they are not
              // yet
              // completed
              // *check is isToClear needs update;
              throw new AdempiereException(
                  Env.getAD_Language(po.getCtx()),
                  MSG_ORDER_DATE_ORDERED_CHANGE_FORBIDDEN_1P,
                  new Object[] {ol.getLine()});
            }
          }
        }
      }
    }
    return null;
  }
  @Override
  public I_C_AdvCommissionCondition retrieveForOrphanedSponsors(
      final Properties ctx, final I_C_AdvComSystem cAdvComSystem, final String trxName) {
    assert cAdvComSystem != null : "cAdvComSystem may not be null";

    final ICompositeQueryFilter<I_C_AdvCommissionCondition> filter =
        Services.get(IQueryBL.class)
            .createCompositeQueryFilter(I_C_AdvCommissionCondition.class)
            .addOnlyActiveRecordsFilter()
            .addEqualsFilter(
                I_C_AdvCommissionCondition.COLUMNNAME_C_AdvComSystem_ID,
                cAdvComSystem.getC_AdvComSystem_ID())
            .addEqualsFilter(
                I_C_AdvCommissionCondition.COLUMNNAME_IsDefaultForOrphandedSponsors, true);

    return Services.get(IQueryBL.class)
        .createQueryBuilder(I_C_AdvCommissionCondition.class, ctx, trxName)
        .filter(filter)
        .create()
        .firstOnly(I_C_AdvCommissionCondition.class);

    // final String wc = I_C_AdvCommissionCondition.COLUMNNAME_C_AdvComSystem_ID + "=? AND " +
    // I_C_AdvCommissionCondition.COLUMNNAME_IsDefaultForOrphandedSponsors + "='Y'";
    // return new Query(ctx, I_C_AdvCommissionCondition.Table_Name, wc, trxName)
    // .setParameters(cAdvComSystem.getC_AdvComSystem_ID())
    // .setOnlyActiveRecords(true)
    // .firstOnly(I_C_AdvCommissionCondition.class);
  }
示例#3
0
  /** Suggests the {@link I_M_HU_PI_Item_Product} for Order Quick Input */
  @Override
  public I_M_HU_PI_Item_Product getM_HU_PI_ItemProductFor(final Object document) {
    Check.assumeInstanceOf(document, I_C_Order.class, "param 'document'");

    final Properties ctx = InterfaceWrapperHelper.getCtx(document);
    final String trxName = InterfaceWrapperHelper.getTrxName(document);

    final I_C_Order order = InterfaceWrapperHelper.create(document, I_C_Order.class);

    final I_M_PriceList_Version plv = Services.get(IOrderBL.class).getPriceListVersion(order);

    final I_M_ProductPrice_Attribute productPriceAttribute =
        Services.get(IAttributePricingBL.class)
            .getDefaultAttributePriceOrNull(
                order, order.getM_Product_ID(), plv, false); // strictDefault

    if (null != productPriceAttribute) {
      final de.metas.handlingunits.model.I_M_ProductPrice_Attribute productPriceAttributeExt =
          InterfaceWrapperHelper.create(
              productPriceAttribute, de.metas.handlingunits.model.I_M_ProductPrice_Attribute.class);
      final I_M_HU_PI_Item_Product hu_pip =
          InterfaceWrapperHelper.create(
              ctx,
              productPriceAttributeExt.getM_HU_PI_Item_Product_ID(),
              I_M_HU_PI_Item_Product.class,
              trxName);
      return hu_pip;
    }

    return null;
  }
  @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);
  }
示例#5
0
  @Override
  protected String doIt() throws Exception {
    final long startTime = System.currentTimeMillis();

    // note: delete the scheds via API to make sure that the appropriate relations are also removed
    final List<MMPurchaseSchedule> schedsToDelete =
        new Query(getCtx(), I_M_PurchaseSchedule.Table_Name, "", get_TrxName())
            .setClient_ID()
            .list();
    for (final MMPurchaseSchedule sched : schedsToDelete) {
      // addLog("Deleting " + sched);
      sched.deleteEx(false);
    }

    final long afterDeleteTime = System.currentTimeMillis();
    addLog(
        "Deleted "
            + schedsToDelete.size()
            + " @M_PurchaseSchedule_ID@ records in "
            + TimeUtil.formatElapsed(afterDeleteTime - startTime));

    final IOrderPA orderPA = Services.get(IOrderPA.class);
    final IPurchaseScheduleBL purchaseScheduleBL = Services.get(IPurchaseScheduleBL.class);

    int createCounter = 0;
    for (final I_C_Order order :
        orderPA.retrieveOpenOrders(DocAction.STATUS_Completed, get_TrxName())) {
      if (!order.isSOTrx()) {
        continue;
      }

      final Collection<MMPurchaseSchedule> purchaseScheds =
          purchaseScheduleBL.retrieveOrCreateForSO(getCtx(), order, get_TrxName());
      for (final MMPurchaseSchedule ps : purchaseScheds) {
        purchaseScheduleBL.updateStorageData(getCtx(), ps, get_TrxName());
        purchaseScheduleBL.updateQtyToOrder(ps);
        ps.saveEx();
      }

      addLog(
          "Created "
              + purchaseScheds.size()
              + " @M_PurchaseSchedule_ID@ records for @C_Order_ID@ "
              + order.getDocumentNo());
      createCounter += purchaseScheds.size();
    }

    addLog(
        "Created "
            + createCounter
            + " purchase schedule records in "
            + TimeUtil.formatElapsed(System.currentTimeMillis() - afterDeleteTime));
    return "@Success@";
  }
示例#6
0
  @Override
  public void onBeforeClose(final I_M_ReceiptSchedule receiptSchedule) {
    // Services
    final IHUReceiptScheduleDAO huReceiptScheduleDAO = Services.get(IHUReceiptScheduleDAO.class);
    final IHUReceiptScheduleBL huReceiptScheduleBL = Services.get(IHUReceiptScheduleBL.class);

    final String trxName = InterfaceWrapperHelper.getTrxName(receiptSchedule);
    final List<I_M_ReceiptSchedule_Alloc> allocs =
        huReceiptScheduleDAO.retrieveHandlingUnitAllocations(receiptSchedule, trxName);

    huReceiptScheduleBL.destroyHandlingUnits(allocs, trxName);
  }
示例#7
0
  @DocValidate(timings = {ModelValidator.TIMING_BEFORE_COMPLETE})
  public void addInoutToBalance(final I_M_InOut inout) {

    final boolean isReversal = Services.get(IInOutBL.class).isReversal(inout);

    // do nothing in case of reversal
    if (!isReversal) {
      final IMaterialBalanceDetailBL materialBalanceDetailBL =
          Services.get(IMaterialBalanceDetailBL.class);

      materialBalanceDetailBL.addInOutToBalance(inout);
    }
  }
示例#8
0
  private void setupMRPExecutorService() {
    mrpExecutor = new MockedMRPExecutor();

    Services.registerService(
        IMRPExecutorService.class,
        new MRPExecutorService() {
          @Override
          protected IMRPExecutor createMRPExecutor() {
            return mrpExecutor;
          }
        });
    mrpExecutorService = (MRPExecutorService) Services.get(IMRPExecutorService.class);
    LogManager.setLoggerLevel(getMRPLogger(), Level.INFO);
  }
示例#9
0
 @Override
 public void addAsync(
     final Properties ctx,
     final int M_Warehouse_ID,
     final int M_Locator_ID,
     final int M_Product_ID,
     final int M_AttributeSetInstance_ID,
     final int reservationAttributeSetInstance_ID,
     final BigDecimal diffQtyOnHand,
     final BigDecimal diffQtyReserved,
     final BigDecimal diffQtyOrdered,
     final String trxName) {
   // @formatter:off
   Services.get(IWorkPackageQueueFactory.class)
       .getQueueForEnqueuing(ctx, M_Storage_Add.class)
       .newBlock()
       .newWorkpackage()
       .bindToTrxName(trxName)
       .parameters()
       .setParameter(M_Storage_Add.WP_PARAM_M_Warehouse_ID, M_Warehouse_ID)
       .setParameter(M_Storage_Add.WP_PARAM_M_Locator_ID, M_Locator_ID)
       .setParameter(M_Storage_Add.WP_PARAM_M_Product_ID, M_Product_ID)
       .setParameter(M_Storage_Add.WP_PARAM_M_AttributeSetInstance_ID, M_AttributeSetInstance_ID)
       .setParameter(
           M_Storage_Add.WP_PARAM_reservationAttributeSetInstance_ID,
           reservationAttributeSetInstance_ID)
       .setParameter(M_Storage_Add.WP_PARAM_diffQtyOnHand, diffQtyOnHand)
       .setParameter(M_Storage_Add.WP_PARAM_diffQtyReserved, diffQtyReserved)
       .setParameter(M_Storage_Add.WP_PARAM_diffQtyOrdered, diffQtyOrdered)
       .end()
       .build();
   // @formatter:on
 }
 /**
  * Create/Update MRP record based in Distribution Order.
  *
  * <p>Actally it is calling {@link #createUpdateMRPRecords(I_DD_OrderLine)} for each line.
  *
  * @param I_DD_Order Distribution Order
  */
 private void createUpdateMRPRecords(final I_DD_Order ddOrder) {
   final IDDOrderDAO ddOrderDAO = Services.get(IDDOrderDAO.class);
   final List<I_DD_OrderLine> ddOrderLines = ddOrderDAO.retrieveLines(ddOrder);
   for (final I_DD_OrderLine ddOrderLine : ddOrderLines) {
     createUpdateMRPRecords(ddOrderLine);
   }
 }
示例#11
0
  @Override
  public boolean hasMoreLUAssigmentsForSameModelType(final I_M_HU_Assignment luAssignment) {
    Check.assumeNotNull(luAssignment, "luAssignment not null");
    final int luHUId = luAssignment.getM_LU_HU_ID();
    if (luHUId <= 0) {
      return false;
    }

    final int adTableId = luAssignment.getAD_Table_ID();
    final int recordId = luAssignment.getRecord_ID();

    return Services.get(IQueryBL.class)
        .createQueryBuilder(I_M_HU_Assignment.class, luAssignment)
        .addOnlyActiveRecordsFilter() // only active assignments are counted
        .addEqualsFilter(I_M_HU_Assignment.COLUMN_AD_Table_ID, adTableId) // for same kind of model
        .addCompareFilter(
            I_M_HU_Assignment.COLUMN_Record_ID,
            Operator.LESS,
            recordId) // on a model which was created before ours
        .addEqualsFilter(I_M_HU_Assignment.COLUMN_M_LU_HU_ID, luHUId) // for our LU
        .addEqualsFilter(
            I_M_HU_Assignment.COLUMNNAME_VHU_ID,
            luAssignment.getVHU_ID()) // 08564 : also check the vhu
        //
        .create()
        .match();
  }
示例#12
0
 /**
  * Set Price for Product and PriceList
  *
  * @param M_PriceList_ID price list
  */
 public void setPrice(int M_PriceList_ID) {
   if (getM_Product_ID() <= 0) return;
   //
   final de.metas.interfaces.I_C_OrderLine ol =
       InterfaceWrapperHelper.create(this, de.metas.interfaces.I_C_OrderLine.class);
   Services.get(IOrderLineBL.class).updatePrices(ol);
 } // setPrice
示例#13
0
 /**
  * Set Product
  *
  * @param product product
  */
 public void setProduct(MProduct product) {
   Services.get(IOrderLineBL.class)
       .setM_Product_ID(
           InterfaceWrapperHelper.create(this, de.metas.interfaces.I_C_OrderLine.class),
           product.getM_Product_ID(),
           true);
 } // setProduct
示例#14
0
 public void assertNothingLocked() {
   final PlainLockManager lockManager = (PlainLockManager) Services.get(ILockManager.class);
   final PlainLockDatabase lockDatabase = lockManager.getLockDatabase();
   Assert.assertTrue(
       "No locks expecteded\n" + lockDatabase.getLockedObjectsInfo(),
       lockDatabase.getLocks().isEmpty());
 }
示例#15
0
  /**
   * Update Tax & Header
   *
   * @return true if header updated
   */
  private boolean updateHeaderTax() {
    // Recalculate Tax for this Tax
    if (!getParent().isProcessed()) {
      if (!updateOrderTax(false)) {
        return false;
      }
    }

    // task 08999:
    // Avoid a possible deadlock by updating the C_Order *after* the current transaction, because at
    // this point we might already hold a lot of locks to different objects.
    // The updates in updateHeader0 will try aggregate and obtain any number of additional shared
    // locks.
    // Concrete, we observed a deadlock between this code and
    // M_ReceiptSchedule.propagateQtysToOrderLine()
    final ITrxManager trxManager = Services.get(ITrxManager.class);
    trxManager
        .getTrxListenerManager(get_TrxName())
        .registerListener(
            new TrxListenerAdapter() {
              @Override
              public void afterCommit(final ITrx trx) {
                trxManager.run(
                    new TrxRunnableAdapter() {
                      @Override
                      public void run(final String localTrxName) throws Exception {
                        updateHeader0(getC_Order_ID());
                      }
                    });
              }
            });
    return true;
  } // updateHeaderTax
示例#16
0
  @Override
  @Cached(cacheName = I_C_ConversionType_Default.Table_Name + "#by#Dimension")
  public I_C_ConversionType retrieveDefaultConversionType(
      @CacheCtx final Properties ctx, final int adClientId, final int adOrgId, final Date date) {
    // NOTE to developer: keep in sync with: getDefaultConversionType_ID database function

    Check.assumeNotNull(date, "date not null");
    final Date dateDay = TimeUtil.trunc(date, TimeUtil.TRUNC_DAY);

    return Services.get(IQueryBL.class)
        .createQueryBuilder(I_C_ConversionType_Default.class, ctx, ITrx.TRXNAME_None)
        .addOnlyActiveRecordsFilter()
        .addInArrayFilter(
            I_C_ConversionType_Default.COLUMN_AD_Client_ID,
            adClientId,
            Env.CTXVALUE_AD_Client_ID_System)
        .addInArrayFilter(
            I_C_ConversionType_Default.COLUMN_AD_Org_ID, adClientId, Env.CTXVALUE_AD_Org_ID_System)
        .addCompareFilter(
            I_C_ConversionType_Default.COLUMN_ValidFrom, Operator.LESS_OR_EQUAL, dateDay)
        //
        .orderBy()
        .addColumn(I_C_ConversionType_Default.COLUMN_ValidFrom, Direction.Descending, Nulls.Last)
        .addColumn(I_C_ConversionType_Default.COLUMN_AD_Client_ID, Direction.Descending, Nulls.Last)
        .addColumn(I_C_ConversionType_Default.COLUMN_AD_Org_ID, Direction.Descending, Nulls.Last)
        .endOrderBy()
        //
        .setLimit(1) // only the first one
        //
        .andCollect(I_C_ConversionType_Default.COLUMN_C_ConversionType_ID)
        .create()
        .firstOnlyNotNull(I_C_ConversionType.class);
  }
示例#17
0
  /**
   * Method returns true if the given gridTab is a {@link I_C_OLCand} with the correct data
   * destination.
   *
   * @param gridTab
   */
  @Override
  public boolean isPreconditionApplicable(final GridTab gridTab) {
    if (!I_C_OLCand.Table_Name.equals(gridTab.get_TableName())) {
      return false;
    }

    final I_C_OLCand olCand = GridTabWrapper.create(gridTab, I_C_OLCand.class);
    if (olCand.isError()) {
      return false;
    }

    final IInputDataSourceDAO inputDataSourceDAO = Services.get(IInputDataSourceDAO.class);

    final I_AD_InputDataSource dest =
        inputDataSourceDAO.retrieveInputDataSource(
            Env.getCtx(), Contracts_Constants.DATA_DESTINATION_INTERNAL_NAME, false, get_TrxName());
    if (dest == null) {
      return false;
    }
    if (dest.getAD_InputDataSource_ID() != olCand.getAD_DataDestination_ID()) {
      return false;
    }

    return true;
  }
示例#18
0
  private void createPInstance() {
    DB.saveConstraints();
    try {
      DB.getConstraints().setOnlyAllowedTrxNamePrefixes(false);

      final IADPInstanceDAO adPInstanceDAO = Services.get(IADPInstanceDAO.class);
      this.pinstance =
          adPInstanceDAO.createAD_PInstance(helper.getCtx(), processId, tableId, recordId);

      //
      // Add parameters:
      final List<ProcessInfoParameter> piParams = new ArrayList<>();
      for (Map.Entry<String, Object> e : parameters.entrySet()) {
        final String name = e.getKey();
        final Object value = e.getValue();
        if (value == null) {
          continue;
        }

        piParams.add(ProcessInfoParameter.ofValueObject(name, value));
      }

      adPInstanceDAO.saveParameterToDB(pinstance.getAD_PInstance_ID(), piParams);
    } finally {
      DB.restoreConstraints();
    }
  }
示例#19
0
  /**
   * ActionListener
   *
   * @param e ActionEvent
   */
  @Override
  public void actionPerformed(ActionEvent e) {
    //	Warehouse/Product
    int only_Warehouse_ID = getOnly_Warehouse_ID();
    int only_Product_ID = getOnly_Product_ID();
    log.info("Only Warehouse_ID=" + only_Warehouse_ID + ", Product_ID=" + only_Product_ID);

    //	Text Entry ok
    if (e.getSource() == m_text && actionText(only_Warehouse_ID, only_Product_ID)) return;

    //	 Button - Start Dialog
    int M_Locator_ID = 0;
    if (m_value instanceof Integer) M_Locator_ID = ((Integer) m_value).intValue();
    //
    m_mLocator.setOnly_Warehouse_ID(only_Warehouse_ID);
    m_mLocator.setOnly_Product_ID(getOnly_Product_ID());
    VLocatorDialog ld =
        new VLocatorDialog(
            Env.getFrame(this),
            Services.get(IMsgBL.class).translate(Env.getCtx(), m_columnName),
            m_mLocator,
            M_Locator_ID,
            isMandatory(),
            only_Warehouse_ID);
    //	display
    ld.setVisible(true);
    m_mLocator.setOnly_Warehouse_ID(0);

    //	redisplay
    if (!ld.isChanged()) return;
    setValue(ld.getValue(), true);
  } //	actionPerformed
示例#20
0
  @Override
  public List<I_M_HU_Attribute> retrieveAttributesOrdered(final I_M_HU hu) {
    // NOTE: don't cache on this level. Caching is handled on upper levels

    // there are only some dozen attributes at most, so i think it'S fine to order them after
    // loading
    final List<I_M_HU_Attribute> huAttributes =
        Services.get(IQueryBL.class)
            .createQueryBuilder(I_M_HU_Attribute.class, hu)
            .filter(
                new EqualsQueryFilter<I_M_HU_Attribute>(
                    I_M_HU_Attribute.COLUMNNAME_M_HU_ID, hu.getM_HU_ID()))
            .create()
            .setOnlyActiveRecords(true)
            .list(I_M_HU_Attribute.class);

    // Optimization: set M_HU link
    for (final I_M_HU_Attribute huAttribute : huAttributes) {
      huAttribute.setM_HU(hu);
    }

    // Make sure they are sorted
    Collections.sort(huAttributes, HUAttributesBySeqNoComparator.instance);

    return huAttributes;
  }
示例#21
0
  /**
   * @param conversionCtx
   * @param CurFrom_ID
   * @param CurTo_ID
   * @return query which is finding the best matching {@link I_C_Conversion_Rate} for given
   *     parameters.
   */
  protected final IQueryBuilder<I_C_Conversion_Rate> retrieveRateQuery(
      final ICurrencyConversionContext conversionCtx, final int CurFrom_ID, final int CurTo_ID) {
    final Properties ctx = Env.getCtx();
    final int conversionTypeId = conversionCtx.getC_ConversionType_ID();
    final Date conversionDate = conversionCtx.getConversionDate();

    return Services.get(IQueryBL.class)
        .createQueryBuilder(I_C_Conversion_Rate.class, ctx, ITrx.TRXNAME_None)
        .addEqualsFilter(I_C_Conversion_Rate.COLUMN_C_Currency_ID, CurFrom_ID)
        .addEqualsFilter(I_C_Conversion_Rate.COLUMN_C_Currency_ID_To, CurTo_ID)
        .addEqualsFilter(I_C_Conversion_Rate.COLUMN_C_ConversionType_ID, conversionTypeId)
        .addCompareFilter(
            I_C_Conversion_Rate.COLUMN_ValidFrom, Operator.LESS_OR_EQUAL, conversionDate)
        .addCompareFilter(
            I_C_Conversion_Rate.COLUMN_ValidTo, Operator.GREATER_OR_EQUAL, conversionDate)
        .addInArrayFilter(
            I_C_Conversion_Rate.COLUMN_AD_Client_ID, 0, conversionCtx.getAD_Client_ID())
        .addInArrayFilter(I_C_Conversion_Rate.COLUMN_AD_Org_ID, 0, conversionCtx.getAD_Org_ID())
        //
        .orderBy()
        .addColumn(I_C_Conversion_Rate.COLUMN_AD_Client_ID, Direction.Descending, Nulls.Last)
        .addColumn(I_C_Conversion_Rate.COLUMN_AD_Org_ID, Direction.Descending, Nulls.Last)
        .addColumn(I_C_Conversion_Rate.COLUMN_ValidFrom, Direction.Descending, Nulls.Last)
        .endOrderBy()
        //
        .setLimit(1) // first only
    ;
  }
示例#22
0
  /**
   * Generate movements from receipt (if needed).
   *
   * <p>This is the counter-part of {@link #reverseMovements(I_M_InOut)}.
   *
   * @param inout
   */
  @DocValidate(timings = {ModelValidator.TIMING_AFTER_COMPLETE})
  public void generateMovement(final I_M_InOut inout) {
    // We are generating movements only for receipts
    if (inout.isSOTrx()) {
      return;
    }

    // Don't generate movements for a reversal document
    if (Services.get(IInOutBL.class).isReversal(inout)) {
      return;
    }

    // Actually generate the movements
    final IInOutMovementBL inoutMovementBL = Services.get(IInOutMovementBL.class);
    inoutMovementBL.generateMovementFromReceipt(inout);
  }
  @Override
  public void onNew(final ICalloutRecord calloutRecord) {
    final I_M_ShipperTransportation shipperTransportation =
        calloutRecord.getModel(I_M_ShipperTransportation.class);

    Services.get(IShipperTransportationBL.class).setC_DocType(shipperTransportation);
  }
  @Override
  protected String validateAction() {

    String validate = null;

    DefaultMutableTreeNode node =
        (DefaultMutableTreeNode) tree.getSelectionPath().getLastPathComponent();
    BOMLineWrapper line = null;
    if (!(node.getUserObject() instanceof BOMLineWrapper)) {

      validate =
          "'"
              + node.getUserObject().getClass().getName()
              + "' isn't a type of 'BOMLineWrapper'(ClassCastException)";
    } else {

      line = (BOMLineWrapper) node.getUserObject();
      MProduct p = new MProduct(Env.getCtx(), line.getM_Product_ID(), null);

      if (p.getM_AttributeSet_ID() == 0) {

        validate = Services.get(IMsgBL.class).getMsg(Env.getCtx(), "PAttributeNoAttributeSet");
      }
    }

    return validate;
  }
示例#25
0
  /**
   * Set Header Info
   *
   * @param order order
   */
  public void setHeaderInfo(final MOrder order) {
    final IOrderBL orderBL = Services.get(IOrderBL.class);

    m_precision = orderBL.getPrecision(order);
    m_M_PriceList_ID = orderBL.retrievePriceListId(order);
    m_IsSOTrx = order.isSOTrx();
  } // setHeaderInfo
示例#26
0
  @Override
  public Timestamp calculatePreparationDateOrNull(
      IContextAware context,
      boolean isSOTrx,
      Timestamp datePromised,
      final int bpartnerLocationId) {
    // task 09004: add the current time as parameter and fetch the closest next fit delivery day
    final Timestamp calculationTime = SystemTime.asTimestamp();

    //
    // Create Delivery Day Query Parameters
    final PlainDeliveryDayQueryParams deliveryDayQueryParams = new PlainDeliveryDayQueryParams();
    deliveryDayQueryParams.setC_BPartner_Location_ID(bpartnerLocationId);
    deliveryDayQueryParams.setDeliveryDate(datePromised);
    deliveryDayQueryParams.setToBeFetched(!isSOTrx);
    deliveryDayQueryParams.setProcessed(false);
    deliveryDayQueryParams.setCalculationTime(calculationTime);

    //
    // Find matching delivery day record
    final IDeliveryDayDAO deliveryDayDAO = Services.get(IDeliveryDayDAO.class);
    final I_M_DeliveryDay dd = deliveryDayDAO.retrieveDeliveryDay(context, deliveryDayQueryParams);

    //
    // Extract PreparationDate from DeliveryDay record
    final Timestamp preparationDate;
    if (dd == null) {
      preparationDate = null;
    } else {
      preparationDate = dd.getDeliveryDate();
    }

    return preparationDate;
  }
示例#27
0
  /**
   * Get Currency Precision from Currency
   *
   * @return precision
   */
  public int getPrecision() {
    if (m_precision != null) {
      return m_precision;
    }

    //
    if (getC_Currency_ID() == 0) {
      setOrder(getParent());
      if (m_precision != null) return m_precision;
    }
    if (getC_Currency_ID() > 0) {
      final I_C_Currency cur =
          Services.get(ICurrencyDAO.class).retrieveCurrency(getCtx(), getC_Currency_ID());
      if (cur.getC_Currency_ID() != 0) {
        m_precision = cur.getStdPrecision();
        return m_precision;
      }
    }

    //
    // Fallback
    // FIXME: drop this, i guess is not used AT ALL
    final String sql =
        "SELECT c.StdPrecision "
            + "FROM C_Currency c INNER JOIN C_Order x ON (x.C_Currency_ID=c.C_Currency_ID) "
            + "WHERE x.C_Order_ID=?";
    m_precision = DB.getSQLValue(get_TrxName(), sql, getC_Order_ID());
    return m_precision;
  } // getPrecision
示例#28
0
  @Override
  public List<I_M_HU_Assignment> retrieveIncludedHUAssignments(final I_M_HU_Assignment assignment) {
    final IQueryBL queryBL = Services.get(IQueryBL.class);
    final IQueryBuilder<I_M_HU_Assignment> queryBuilder =
        queryBL.createQueryBuilder(I_M_HU_Assignment.class, assignment);

    queryBuilder
        // references same record..
        .addEqualsFilter(I_M_HU_Assignment.COLUMN_AD_Table_ID, assignment.getAD_Table_ID())
        .addEqualsFilter(I_M_HU_Assignment.COLUMN_Record_ID, assignment.getRecord_ID())
        // ..and same toplevel-HU..
        .addEqualsFilter(I_M_HU_Assignment.COLUMN_M_HU_ID, assignment.getM_HU_ID());

    // ..but additionally references one of the HU's components (TU or LU)
    final ICompositeQueryFilter<I_M_HU_Assignment> subFilter =
        queryBL.createCompositeQueryFilter(I_M_HU_Assignment.class);
    subFilter
        .setJoinOr()
        .addNotEqualsFilter(I_M_HU_Assignment.COLUMN_M_LU_HU_ID, null)
        .addNotEqualsFilter(I_M_HU_Assignment.COLUMN_M_TU_HU_ID, null);

    queryBuilder.filter(subFilter);

    //
    return queryBuilder.create().list(I_M_HU_Assignment.class);
  }
  @Override
  public <T extends IAttributeStrategy> T retrieveStrategy(
      final Properties ctx, final int adJavaClassId, final Class<T> strategyClass) {
    final I_AD_JavaClass javaClass =
        Services.get(IJavaClassDAO.class).retriveJavaClassOrNull(ctx, adJavaClassId);

    if (javaClass == null) {
      return getDefaultStrategy(strategyClass);
    }

    final String classname = javaClass.getClassname();
    if (Check.isEmpty(classname, true)) {
      throw new AdempiereException("Java Class name is empty for " + javaClass);
    }

    //
    // Check if we have defined a static strategy
    @SuppressWarnings("unchecked")
    final T strategyInstance = (T) classname2strategy.get(classname);
    if (strategyInstance != null) {
      return strategyInstance;
    }

    return Util.getInstance(strategyClass, classname);
  }
示例#30
0
  @Override
  public void deleteHUAssignments(
      final Object model, final Collection<I_M_HU> husToUnAssign, final String trxName) {
    Check.assumeNotNull(model, "model not null");
    Check.assumeNotNull(husToUnAssign, "husToUnAssign not null");

    final Properties ctx = InterfaceWrapperHelper.getCtx(model);
    final int adTableId = InterfaceWrapperHelper.getModelTableId(model);
    final int recordId = InterfaceWrapperHelper.getId(model);

    final Set<Integer> huIds = new HashSet<Integer>(husToUnAssign.size());
    for (final I_M_HU hu : husToUnAssign) {
      huIds.add(hu.getM_HU_ID());
    }

    if (huIds.isEmpty()) {
      return;
    }

    final IQueryBuilder<I_M_HU_Assignment> queryBuilder =
        Services.get(IQueryBL.class).createQueryBuilder(I_M_HU_Assignment.class, ctx, trxName);

    //
    // Note that here we don't want to skip anything; we want the HUAssignmentBL to do it's job, so
    // we clean everything up
    queryBuilder
        .addEqualsFilter(I_M_HU_Assignment.COLUMN_AD_Table_ID, adTableId)
        .addEqualsFilter(I_M_HU_Assignment.COLUMN_Record_ID, recordId)
        .addInArrayFilter(I_M_HU_Assignment.COLUMN_M_HU_ID, huIds)
        .create()
        .delete();
  }