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;
}
Aggregations