コード例 #1
0
  public static MOrderLine createOrderLine(
      Properties ctx,
      MOrder order,
      int productId,
      BigDecimal qty,
      BigDecimal discount,
      BigDecimal lineNet)
      throws OperationException {
    if (qty == null) {
      qty = Env.ONE;
    }

    MOrderLine orderLine = new MOrderLine(order);

    MProduct product = new MProduct(ctx, productId, order.get_TrxName());
    MTax tax =
        TaxManager.getTaxFromCategory(ctx, product.getC_TaxCategory_ID(), order.get_TrxName());
    orderLine.setC_Tax_ID(tax.get_ID());
    orderLine.setC_UOM_ID(product.getC_UOM_ID());
    orderLine.setC_BPartner_ID(order.getC_BPartner_ID());
    // Must set Product Id before quantity Ordered.
    orderLine.setM_Product_ID(productId);
    orderLine.setQty(qty);
    orderLine.setPrice();

    // Bug fix, set price to 2dp
    MPriceList orderPriceList = MPriceList.get(ctx, order.getM_PriceList_ID(), order.get_TrxName());

    if (!orderPriceList.isTaxIncluded()) {
      BigDecimal taxAmt = tax.calculateTax(lineNet, true, 12);
      BigDecimal lineNetWithoutTax = lineNet.subtract(taxAmt);
      orderLine.setLineNetAmt(lineNetWithoutTax);

      BigDecimal unitPriceWithoutTax =
          lineNetWithoutTax.divide(qty, 12, BigDecimal.ROUND_HALF_DOWN);

      orderLine.setPriceEntered(unitPriceWithoutTax.setScale(2, BigDecimal.ROUND_HALF_UP));
      orderLine.setPriceActual(unitPriceWithoutTax.setScale(2, BigDecimal.ROUND_HALF_UP));
    } else {
      BigDecimal unitPrice = lineNet.divide(qty, 12, BigDecimal.ROUND_HALF_DOWN);
      orderLine.setLineNetAmt(lineNet.setScale(2, BigDecimal.ROUND_HALF_UP));
      orderLine.setPriceEntered(unitPrice.setScale(2, BigDecimal.ROUND_HALF_UP));
      orderLine.setPriceActual(unitPrice.setScale(2, BigDecimal.ROUND_HALF_UP));
    }

    if (discount.doubleValue() != 0.0) {
      orderLine.setDiscount();
    }

    PoManager.save(orderLine);

    return orderLine;
  }
コード例 #2
0
ファイル: MOrderLine.java プロジェクト: metasfresh/metasfresh
  /**
   * Before Delete
   *
   * @return true if it can be deleted
   */
  @Override
  protected boolean beforeDelete() {
    // R/O Check - Something delivered. etc.
    if (Env.ZERO.compareTo(getQtyDelivered()) != 0) {
      throw new AdempiereException("@DeleteError@ @QtyDelivered@=" + getQtyDelivered());
    }
    if (Env.ZERO.compareTo(getQtyInvoiced()) != 0) {
      throw new AdempiereException("@DeleteError@ @QtyInvoiced@=" + getQtyInvoiced());
    }
    if (Env.ZERO.compareTo(getQtyReserved()) != 0) {
      // metas: attempt to unreserve stock
      BigDecimal oldVal = getQtyOrdered();
      if (oldVal.signum() != 0) {
        setQty(Env.ZERO);
        setLineNetAmt(Env.ZERO);
        saveEx(get_TrxName());
      }

      if (!getParent().reserveStock(null, new MOrderLine[] {this})) {
        throw new AdempiereException("@DeleteError@ @QtyReserved@=" + getQtyReserved());
      }
      // metas end
    }

    // UnLink All Requisitions
    MRequisitionLine.unlinkC_OrderLine_ID(getCtx(), get_ID(), get_TrxName());

    return true;
  } // beforeDelete
コード例 #3
0
ファイル: MOrderLine.java プロジェクト: metasfresh/metasfresh
 /**
  * ************************************************************************ Default Constructor
  *
  * @param ctx context
  * @param C_OrderLine_ID order line to load
  * @param trxName trx name
  */
 public MOrderLine(Properties ctx, int C_OrderLine_ID, String trxName) {
   super(ctx, C_OrderLine_ID, trxName);
   if (C_OrderLine_ID == 0) {
     // setC_Order_ID (0);
     // setLine (0);
     // setM_Warehouse_ID (0); // @M_Warehouse_ID@
     // setC_BPartner_ID(0);
     // setC_BPartner_Location_ID (0); // @C_BPartner_Location_ID@
     // setC_Currency_ID (0); // @C_Currency_ID@
     // setDateOrdered (new Timestamp(System.currentTimeMillis())); // @DateOrdered@
     //
     // setC_Tax_ID (0);
     // setC_UOM_ID (0);
     //
     setFreightAmt(Env.ZERO);
     setLineNetAmt(Env.ZERO);
     //
     setPriceEntered(Env.ZERO);
     setPriceActual(Env.ZERO);
     setPriceLimit(Env.ZERO);
     setPriceList(Env.ZERO);
     //
     setM_AttributeSetInstance_ID(0);
     //
     setQtyEntered(Env.ZERO);
     setQtyOrdered(Env.ZERO); // 1
     setQtyDelivered(Env.ZERO);
     setQtyInvoiced(Env.ZERO);
     // task 09358: get rid of this; instead, update qtyReserved at one central place
     // setQtyReserved(Env.ZERO);
     //
     setIsDescription(false); // N
     setProcessed(false);
     setLine(0);
   }
 } // MOrderLine