/**
  * Set Product
  *
  * @param product product
  */
 public void setProduct(MProduct product) {
   m_product = product;
   if (m_product != null) {
     setM_Product_ID(m_product.getM_Product_ID());
     setC_UOM_ID(m_product.getC_UOM_ID());
   } else {
     setM_Product_ID(0);
     setC_UOM_ID(0);
   }
   setM_AttributeSetInstance_ID(0);
 } //	setProduct
Beispiel #2
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;
  }
Beispiel #3
0
 /**
  * Quantity UOM
  *
  * @return Transaction or Storage M_UOM_ID
  */
 public int getC_UOM_ID() {
   //	Trx UOM
   int index = p_po.get_ColumnIndex("C_UOM_ID");
   if (index != -1) {
     Integer ii = (Integer) p_po.get_Value(index);
     if (ii != null) return ii.intValue();
   }
   //  Storage UOM
   MProduct product = getProduct();
   if (product != null) return product.getC_UOM_ID();
   //
   return 0;
 } //  getC_UOM