use of com.axelor.apps.sale.db.ComplementaryProduct in project axelor-open-suite by axelor.
the class SaleOrderLineServiceImpl method fillComplementaryProductList.
@Override
public void fillComplementaryProductList(SaleOrderLine saleOrderLine) {
if (saleOrderLine.getProduct() != null && saleOrderLine.getProduct().getComplementaryProductList() != null) {
if (saleOrderLine.getSelectedComplementaryProductList() == null) {
saleOrderLine.setSelectedComplementaryProductList(new ArrayList<>());
}
saleOrderLine.clearSelectedComplementaryProductList();
for (ComplementaryProduct complProduct : saleOrderLine.getProduct().getComplementaryProductList()) {
ComplementaryProductSelected newComplProductLine = new ComplementaryProductSelected();
newComplProductLine.setProduct(complProduct.getProduct());
newComplProductLine.setQty(complProduct.getQty());
newComplProductLine.setOptional(complProduct.getOptional());
newComplProductLine.setIsSelected(!complProduct.getOptional());
newComplProductLine.setSaleOrderLine(saleOrderLine);
saleOrderLine.addSelectedComplementaryProductListItem(newComplProductLine);
}
}
}
use of com.axelor.apps.sale.db.ComplementaryProduct in project axelor-open-suite by axelor.
the class SaleOrderLineServiceImpl method manageComplementaryProductSaleOrderLine.
@Override
public List<SaleOrderLine> manageComplementaryProductSaleOrderLine(SaleOrderLine saleOrderLine, SaleOrder saleOrder, List<ComplementaryProduct> complementaryProducts) throws AxelorException {
List<SaleOrderLine> newComplementarySOLines = new ArrayList<>();
if (saleOrderLine.getComplementarySaleOrderLineList() == null) {
saleOrderLine.setComplementarySaleOrderLineList(new ArrayList<>());
}
for (ComplementaryProduct complementaryProduct : complementaryProducts) {
Product product = complementaryProduct.getProduct();
if (product == null) {
continue;
}
SaleOrderLine complementarySOLine;
Optional<SaleOrderLine> complementarySOLineOpt = saleOrderLine.getComplementarySaleOrderLineList().stream().filter(line -> line.getMainSaleOrderLine() != null && line.getProduct().equals(product)).findFirst();
if (complementarySOLineOpt.isPresent()) {
complementarySOLine = complementarySOLineOpt.get();
} else {
complementarySOLine = new SaleOrderLine();
complementarySOLine.setSequence(saleOrderLine.getSequence());
complementarySOLine.setProduct(complementaryProduct.getProduct());
saleOrderLine.addComplementarySaleOrderLineListItem(complementarySOLine);
newComplementarySOLines.add(complementarySOLine);
}
complementarySOLine.setQty(complementaryProduct.getQty());
this.computeProductInformation(complementarySOLine, saleOrder);
this.computeValues(saleOrder, complementarySOLine);
saleOrderLineRepo.save(complementarySOLine);
}
return newComplementarySOLines;
}
use of com.axelor.apps.sale.db.ComplementaryProduct in project axelor-open-suite by axelor.
the class SaleOrderServiceImpl method manageComplementaryProductSOLines.
@Override
public void manageComplementaryProductSOLines(SaleOrder saleOrder) throws AxelorException {
if (saleOrder.getClientPartner() == null || CollectionUtils.isEmpty(saleOrder.getSaleOrderLineList()) || CollectionUtils.isEmpty(saleOrder.getClientPartner().getComplementaryProductList())) {
return;
}
List<SaleOrderLine> newComplementarySOLines = new ArrayList<>();
List<ComplementaryProduct> complementaryProducts = saleOrder.getClientPartner().getComplementaryProductList();
for (SaleOrderLine saleOrderLine : saleOrder.getSaleOrderLineList()) {
if (saleOrderLine.getMainSaleOrderLine() != null) {
continue;
}
newComplementarySOLines.addAll(saleOrderLineService.manageComplementaryProductSaleOrderLine(saleOrderLine, saleOrder, complementaryProducts));
}
newComplementarySOLines.stream().forEach(line -> saleOrder.addSaleOrderLineListItem(line));
Beans.get(SaleOrderComputeService.class).computeSaleOrder(saleOrder);
}
Aggregations