Search in sources :

Example 1 with ComplementaryProductSelected

use of com.axelor.apps.sale.db.ComplementaryProductSelected 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);
        }
    }
}
Also used : ComplementaryProduct(com.axelor.apps.sale.db.ComplementaryProduct) ComplementaryProductSelected(com.axelor.apps.sale.db.ComplementaryProductSelected)

Example 2 with ComplementaryProductSelected

use of com.axelor.apps.sale.db.ComplementaryProductSelected in project axelor-open-suite by axelor.

the class SaleOrderServiceImpl method handleComplementaryProducts.

@Override
public List<SaleOrderLine> handleComplementaryProducts(SaleOrder saleOrder) throws AxelorException {
    List<SaleOrderLine> saleOrderLineList = saleOrder.getSaleOrderLineList();
    if (saleOrderLineList == null) {
        saleOrderLineList = new ArrayList<>();
    }
    SaleOrderLine originSoLine = null;
    for (SaleOrderLine soLine : saleOrderLineList) {
        if (soLine.getIsComplementaryProductsUnhandledYet()) {
            originSoLine = soLine;
            if (originSoLine.getManualId() == null || originSoLine.getManualId().equals("")) {
                this.setNewManualId(originSoLine);
            }
            break;
        }
    }
    if (originSoLine != null && originSoLine.getProduct() != null && originSoLine.getSelectedComplementaryProductList() != null) {
        SaleOrderLineService saleOrderLineService = Beans.get(SaleOrderLineService.class);
        AppBaseService appBaseService = Beans.get(AppBaseService.class);
        for (ComplementaryProductSelected compProductSelected : originSoLine.getSelectedComplementaryProductList()) {
            // Search if there is already a line for this product to modify or remove
            SaleOrderLine newSoLine = null;
            for (SaleOrderLine soLine : saleOrderLineList) {
                if (originSoLine.getManualId().equals(soLine.getParentId()) && soLine.getProduct() != null && soLine.getProduct().equals(compProductSelected.getProduct())) {
                    // exists and is no longer selected
                    if (compProductSelected.getIsSelected()) {
                        newSoLine = soLine;
                    } else {
                        saleOrderLineList.remove(soLine);
                    }
                    break;
                }
            }
            if (newSoLine == null) {
                if (compProductSelected.getIsSelected()) {
                    newSoLine = new SaleOrderLine();
                    newSoLine.setProduct(compProductSelected.getProduct());
                    newSoLine.setSaleOrder(saleOrder);
                    newSoLine.setQty(originSoLine.getQty().multiply(compProductSelected.getQty()).setScale(appBaseService.getNbDecimalDigitForQty(), RoundingMode.HALF_EVEN));
                    saleOrderLineService.computeProductInformation(newSoLine, newSoLine.getSaleOrder());
                    saleOrderLineService.computeValues(newSoLine.getSaleOrder(), newSoLine);
                    newSoLine.setParentId(originSoLine.getManualId());
                    int targetIndex = saleOrderLineList.indexOf(originSoLine) + 1;
                    saleOrderLineList.add(targetIndex, newSoLine);
                }
            } else {
                newSoLine.setQty(originSoLine.getQty().multiply(compProductSelected.getQty()).setScale(appBaseService.getNbDecimalDigitForQty(), RoundingMode.HALF_EVEN));
                saleOrderLineService.computeProductInformation(newSoLine, newSoLine.getSaleOrder());
                saleOrderLineService.computeValues(newSoLine.getSaleOrder(), newSoLine);
            }
        }
        originSoLine.setIsComplementaryProductsUnhandledYet(false);
    }
    for (int i = 0; i < saleOrderLineList.size(); i++) {
        saleOrderLineList.get(i).setSequence(i);
    }
    return saleOrderLineList;
}
Also used : ComplementaryProductSelected(com.axelor.apps.sale.db.ComplementaryProductSelected) AppBaseService(com.axelor.apps.base.service.app.AppBaseService) SaleOrderLine(com.axelor.apps.sale.db.SaleOrderLine)

Aggregations

ComplementaryProductSelected (com.axelor.apps.sale.db.ComplementaryProductSelected)2 AppBaseService (com.axelor.apps.base.service.app.AppBaseService)1 ComplementaryProduct (com.axelor.apps.sale.db.ComplementaryProduct)1 SaleOrderLine (com.axelor.apps.sale.db.SaleOrderLine)1