Search in sources :

Example 1 with ShipmentMode

use of com.axelor.apps.stock.db.ShipmentMode in project axelor-open-suite by axelor.

the class PurchaseOrderServiceSupplychainImpl method createShipmentCostLine.

@Override
public String createShipmentCostLine(PurchaseOrder purchaseOrder) throws AxelorException {
    List<PurchaseOrderLine> purchaseOrderLines = purchaseOrder.getPurchaseOrderLineList();
    ShipmentMode shipmentMode = purchaseOrder.getShipmentMode();
    if (shipmentMode == null) {
        return null;
    }
    Product shippingCostProduct = shipmentMode.getShippingCostsProduct();
    if (shipmentMode.getHasCarriagePaidPossibility()) {
        BigDecimal carriagePaidThreshold = shipmentMode.getCarriagePaidThreshold();
        if (computeExTaxTotalWithoutShippingLines(purchaseOrder).compareTo(carriagePaidThreshold) >= 0) {
            String message = removeShipmentCostLine(purchaseOrder);
            this.computePurchaseOrder(purchaseOrder);
            return message;
        }
    }
    if (alreadyHasShippingCostLine(purchaseOrder, shippingCostProduct)) {
        return null;
    }
    PurchaseOrderLine shippingCostLine = createShippingCostLine(purchaseOrder, shippingCostProduct);
    purchaseOrderLines.add(shippingCostLine);
    this.computePurchaseOrder(purchaseOrder);
    return null;
}
Also used : PurchaseOrderLine(com.axelor.apps.purchase.db.PurchaseOrderLine) Product(com.axelor.apps.base.db.Product) ShipmentMode(com.axelor.apps.stock.db.ShipmentMode) BigDecimal(java.math.BigDecimal)

Example 2 with ShipmentMode

use of com.axelor.apps.stock.db.ShipmentMode in project axelor-open-suite by axelor.

the class SaleOrderServiceSupplychainImpl method createShipmentCostLine.

@Override
public String createShipmentCostLine(SaleOrder saleOrder) throws AxelorException {
    List<SaleOrderLine> saleOrderLines = saleOrder.getSaleOrderLineList();
    Partner client = saleOrder.getClientPartner();
    ShipmentMode shipmentMode = saleOrder.getShipmentMode();
    if (shipmentMode == null) {
        return null;
    }
    Product shippingCostProduct = shipmentMode.getShippingCostsProduct();
    if (shippingCostProduct == null) {
        return null;
    }
    BigDecimal carriagePaidThreshold = shipmentMode.getCarriagePaidThreshold();
    if (client != null) {
        List<CustomerShippingCarriagePaid> carriagePaids = client.getCustomerShippingCarriagePaidList();
        for (CustomerShippingCarriagePaid customerShippingCarriagePaid : carriagePaids) {
            if (shipmentMode.getId() == customerShippingCarriagePaid.getShipmentMode().getId()) {
                if (customerShippingCarriagePaid.getShippingCostsProduct() != null) {
                    shippingCostProduct = customerShippingCarriagePaid.getShippingCostsProduct();
                }
                carriagePaidThreshold = customerShippingCarriagePaid.getCarriagePaidThreshold();
                break;
            }
        }
    }
    if (carriagePaidThreshold != null && shipmentMode.getHasCarriagePaidPossibility()) {
        if (computeExTaxTotalWithoutShippingLines(saleOrder).compareTo(carriagePaidThreshold) >= 0) {
            String message = removeShipmentCostLine(saleOrder);
            saleOrderComputeService.computeSaleOrder(saleOrder);
            saleOrderMarginService.computeMarginSaleOrder(saleOrder);
            return message;
        }
    }
    if (alreadyHasShippingCostLine(saleOrder, shippingCostProduct)) {
        return null;
    }
    SaleOrderLine shippingCostLine = createShippingCostLine(saleOrder, shippingCostProduct);
    saleOrderLines.add(shippingCostLine);
    saleOrderComputeService.computeSaleOrder(saleOrder);
    saleOrderMarginService.computeMarginSaleOrder(saleOrder);
    return null;
}
Also used : CustomerShippingCarriagePaid(com.axelor.apps.supplychain.db.CustomerShippingCarriagePaid) Product(com.axelor.apps.base.db.Product) SaleOrderLine(com.axelor.apps.sale.db.SaleOrderLine) Partner(com.axelor.apps.base.db.Partner) ShipmentMode(com.axelor.apps.stock.db.ShipmentMode) BigDecimal(java.math.BigDecimal)

Aggregations

Product (com.axelor.apps.base.db.Product)2 ShipmentMode (com.axelor.apps.stock.db.ShipmentMode)2 BigDecimal (java.math.BigDecimal)2 Partner (com.axelor.apps.base.db.Partner)1 PurchaseOrderLine (com.axelor.apps.purchase.db.PurchaseOrderLine)1 SaleOrderLine (com.axelor.apps.sale.db.SaleOrderLine)1 CustomerShippingCarriagePaid (com.axelor.apps.supplychain.db.CustomerShippingCarriagePaid)1