Search in sources :

Example 21 with SaleOrderLine

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

the class SaleOrderComputeServiceImpl method _computeSaleOrder.

/**
 * Compute the sale order total amounts
 *
 * @param saleOrder
 * @throws AxelorException
 */
@Override
public void _computeSaleOrder(SaleOrder saleOrder) throws AxelorException {
    saleOrder.setExTaxTotal(BigDecimal.ZERO);
    saleOrder.setCompanyExTaxTotal(BigDecimal.ZERO);
    saleOrder.setTaxTotal(BigDecimal.ZERO);
    saleOrder.setInTaxTotal(BigDecimal.ZERO);
    for (SaleOrderLine saleOrderLine : saleOrder.getSaleOrderLineList()) {
        // skip title lines in computing total amounts
        if (saleOrderLine.getTypeSelect() != SaleOrderLineRepository.TYPE_NORMAL) {
            continue;
        }
        saleOrder.setExTaxTotal(saleOrder.getExTaxTotal().add(saleOrderLine.getExTaxTotal()));
        // In the company accounting currency
        saleOrder.setCompanyExTaxTotal(saleOrder.getCompanyExTaxTotal().add(saleOrderLine.getCompanyExTaxTotal()));
    }
    for (SaleOrderLineTax saleOrderLineVat : saleOrder.getSaleOrderLineTaxList()) {
        // In the sale order currency
        saleOrder.setTaxTotal(saleOrder.getTaxTotal().add(saleOrderLineVat.getTaxTotal()));
    }
    saleOrder.setInTaxTotal(saleOrder.getExTaxTotal().add(saleOrder.getTaxTotal()));
    saleOrder.setAdvanceTotal(computeTotalAdvancePayment(saleOrder));
    logger.debug("Montant de la facture: HTT = {},  HT = {}, Taxe = {}, TTC = {}", new Object[] { saleOrder.getExTaxTotal(), saleOrder.getTaxTotal(), saleOrder.getInTaxTotal() });
}
Also used : SaleOrderLineTax(com.axelor.apps.sale.db.SaleOrderLineTax) SaleOrderLine(com.axelor.apps.sale.db.SaleOrderLine)

Example 22 with SaleOrderLine

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

the class SaleOrderCreateServiceImpl method attachToNewSaleOrder.

// Attachment of all sale order lines to new sale order
protected void attachToNewSaleOrder(List<SaleOrder> saleOrderList, SaleOrder saleOrderMerged) {
    for (SaleOrder saleOrder : saleOrderList) {
        int countLine = 1;
        for (SaleOrderLine saleOrderLine : saleOrder.getSaleOrderLineList()) {
            saleOrderLine.setSequence(countLine * 10);
            saleOrderMerged.addSaleOrderLineListItem(saleOrderLine);
            countLine++;
        }
    }
}
Also used : SaleOrder(com.axelor.apps.sale.db.SaleOrder) SaleOrderLine(com.axelor.apps.sale.db.SaleOrderLine)

Example 23 with SaleOrderLine

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

the class SaleOrderLineServiceImpl method createStartOfPackAndEndOfPackTypeSaleOrderLine.

@Override
public SaleOrderLine createStartOfPackAndEndOfPackTypeSaleOrderLine(Pack pack, SaleOrder saleOrder, BigDecimal packqty, PackLine packLine, Integer typeSelect, Integer sequence) {
    SaleOrderLine saleOrderLine = new SaleOrderLine();
    saleOrderLine.setTypeSelect(typeSelect);
    switch(typeSelect) {
        case SaleOrderLineRepository.TYPE_START_OF_PACK:
            saleOrderLine.setProductName(packLine == null ? pack.getName() : packLine.getProductName());
            saleOrderLine.setQty(packLine != null && packLine.getQuantity() != null ? packLine.getQuantity().multiply(packqty).setScale(appBaseService.getNbDecimalDigitForQty(), RoundingMode.HALF_EVEN) : packqty);
            break;
        case SaleOrderLineRepository.TYPE_END_OF_PACK:
            saleOrderLine.setProductName(packLine == null ? I18n.get(ITranslation.SALE_ORDER_LINE_END_OF_PACK) : packLine.getProductName());
            saleOrderLine.setIsShowTotal(pack.getIsShowTotal());
            saleOrderLine.setIsHideUnitAmounts(pack.getIsHideUnitAmounts());
            break;
        default:
            return null;
    }
    saleOrderLine.setSaleOrder(saleOrder);
    saleOrderLine.setSequence(sequence);
    return saleOrderLine;
}
Also used : SaleOrderLine(com.axelor.apps.sale.db.SaleOrderLine)

Example 24 with SaleOrderLine

use of com.axelor.apps.sale.db.SaleOrderLine 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 25 with SaleOrderLine

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

the class SaleOrderLineServiceImpl method createNonStandardSOLineFromPack.

@Override
public List<SaleOrderLine> createNonStandardSOLineFromPack(Pack pack, SaleOrder saleOrder, BigDecimal packQty, List<SaleOrderLine> saleOrderLineList, Integer sequence) {
    SaleOrderLine saleOrderLine;
    Set<Integer> packLineTypeSet = getPackLineTypes(pack.getComponents());
    int typeSelect = SaleOrderLineRepository.TYPE_START_OF_PACK;
    for (int i = 0; i < 2; i++) {
        if (packLineTypeSet == null || !packLineTypeSet.contains(typeSelect)) {
            saleOrderLine = this.createStartOfPackAndEndOfPackTypeSaleOrderLine(pack, saleOrder, packQty, null, typeSelect, sequence);
            saleOrderLineList.add(saleOrderLine);
        }
        if (typeSelect == SaleOrderLineRepository.TYPE_START_OF_PACK) {
            sequence += pack.getComponents().size() + 1;
            typeSelect = SaleOrderLineRepository.TYPE_END_OF_PACK;
        }
    }
    return saleOrderLineList;
}
Also used : SaleOrderLine(com.axelor.apps.sale.db.SaleOrderLine)

Aggregations

SaleOrderLine (com.axelor.apps.sale.db.SaleOrderLine)116 AxelorException (com.axelor.exception.AxelorException)41 BigDecimal (java.math.BigDecimal)39 SaleOrder (com.axelor.apps.sale.db.SaleOrder)33 ArrayList (java.util.ArrayList)24 Transactional (com.google.inject.persist.Transactional)23 Product (com.axelor.apps.base.db.Product)21 Context (com.axelor.rpc.Context)16 SaleOrderLineService (com.axelor.apps.sale.service.saleorder.SaleOrderLineService)14 PurchaseOrderLine (com.axelor.apps.purchase.db.PurchaseOrderLine)9 Partner (com.axelor.apps.base.db.Partner)8 StockMoveLine (com.axelor.apps.stock.db.StockMoveLine)8 TaxLine (com.axelor.apps.account.db.TaxLine)7 Unit (com.axelor.apps.base.db.Unit)7 HashMap (java.util.HashMap)7 AnalyticMoveLine (com.axelor.apps.account.db.AnalyticMoveLine)6 InvoiceLine (com.axelor.apps.account.db.InvoiceLine)6 SaleOrderLineRepository (com.axelor.apps.sale.db.repo.SaleOrderLineRepository)6 ReservedQtyService (com.axelor.apps.supplychain.service.ReservedQtyService)6 List (java.util.List)6