Search in sources :

Example 1 with CustomerShippingCarriagePaid

use of com.axelor.apps.supplychain.db.CustomerShippingCarriagePaid 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

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