Search in sources :

Example 1 with ComplementaryProduct

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

Example 2 with ComplementaryProduct

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;
}
Also used : Inject(com.google.inject.Inject) LoggerFactory(org.slf4j.LoggerFactory) PriceListService(com.axelor.apps.base.service.PriceListService) HashMap(java.util.HashMap) CurrencyService(com.axelor.apps.base.service.CurrencyService) ProductCompanyService(com.axelor.apps.base.service.ProductCompanyService) ArrayList(java.util.ArrayList) PriceListLine(com.axelor.apps.base.db.PriceListLine) SaleOrderLineRepository(com.axelor.apps.sale.db.repo.SaleOrderLineRepository) HashSet(java.util.HashSet) BigDecimal(java.math.BigDecimal) SaleOrderRepository(com.axelor.apps.sale.db.repo.SaleOrderRepository) AxelorException(com.axelor.exception.AxelorException) TaxLine(com.axelor.apps.account.db.TaxLine) ActionResponse(com.axelor.rpc.ActionResponse) Map(java.util.Map) I18n(com.axelor.i18n.I18n) SaleOrder(com.axelor.apps.sale.db.SaleOrder) PackLineRepository(com.axelor.apps.sale.db.repo.PackLineRepository) PriceListLineRepository(com.axelor.apps.base.db.repo.PriceListLineRepository) RoundingMode(java.math.RoundingMode) ITranslation(com.axelor.apps.sale.translation.ITranslation) AccountManagementService(com.axelor.apps.base.service.tax.AccountManagementService) AppSaleService(com.axelor.apps.sale.service.app.AppSaleService) Logger(org.slf4j.Logger) ProductCategoryService(com.axelor.apps.base.service.ProductCategoryService) MethodHandles(java.lang.invoke.MethodHandles) TaxEquiv(com.axelor.apps.account.db.TaxEquiv) TraceBackService(com.axelor.exception.service.TraceBackService) Set(java.util.Set) PackLine(com.axelor.apps.sale.db.PackLine) AppBaseService(com.axelor.apps.base.service.app.AppBaseService) Currency(com.axelor.apps.base.db.Currency) List(java.util.List) Pack(com.axelor.apps.sale.db.Pack) SaleOrderLine(com.axelor.apps.sale.db.SaleOrderLine) ModuleManager(com.axelor.meta.loader.ModuleManager) Beans(com.axelor.inject.Beans) Product(com.axelor.apps.base.db.Product) Unit(com.axelor.apps.base.db.Unit) ComplementaryProductSelected(com.axelor.apps.sale.db.ComplementaryProductSelected) ObjectUtils(com.axelor.common.ObjectUtils) PriceList(com.axelor.apps.base.db.PriceList) ProductMultipleQtyService(com.axelor.apps.base.service.ProductMultipleQtyService) ComplementaryProduct(com.axelor.apps.sale.db.ComplementaryProduct) Optional(java.util.Optional) FiscalPosition(com.axelor.apps.account.db.FiscalPosition) Context(com.axelor.rpc.Context) ComplementaryProduct(com.axelor.apps.sale.db.ComplementaryProduct) ArrayList(java.util.ArrayList) Product(com.axelor.apps.base.db.Product) ComplementaryProduct(com.axelor.apps.sale.db.ComplementaryProduct) SaleOrderLine(com.axelor.apps.sale.db.SaleOrderLine)

Example 3 with ComplementaryProduct

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);
}
Also used : ComplementaryProduct(com.axelor.apps.sale.db.ComplementaryProduct) ArrayList(java.util.ArrayList) SaleOrderLine(com.axelor.apps.sale.db.SaleOrderLine)

Aggregations

ComplementaryProduct (com.axelor.apps.sale.db.ComplementaryProduct)3 ComplementaryProductSelected (com.axelor.apps.sale.db.ComplementaryProductSelected)2 SaleOrderLine (com.axelor.apps.sale.db.SaleOrderLine)2 ArrayList (java.util.ArrayList)2 FiscalPosition (com.axelor.apps.account.db.FiscalPosition)1 TaxEquiv (com.axelor.apps.account.db.TaxEquiv)1 TaxLine (com.axelor.apps.account.db.TaxLine)1 Currency (com.axelor.apps.base.db.Currency)1 PriceList (com.axelor.apps.base.db.PriceList)1 PriceListLine (com.axelor.apps.base.db.PriceListLine)1 Product (com.axelor.apps.base.db.Product)1 Unit (com.axelor.apps.base.db.Unit)1 PriceListLineRepository (com.axelor.apps.base.db.repo.PriceListLineRepository)1 CurrencyService (com.axelor.apps.base.service.CurrencyService)1 PriceListService (com.axelor.apps.base.service.PriceListService)1 ProductCategoryService (com.axelor.apps.base.service.ProductCategoryService)1 ProductCompanyService (com.axelor.apps.base.service.ProductCompanyService)1 ProductMultipleQtyService (com.axelor.apps.base.service.ProductMultipleQtyService)1 AppBaseService (com.axelor.apps.base.service.app.AppBaseService)1 AccountManagementService (com.axelor.apps.base.service.tax.AccountManagementService)1