Search in sources :

Example 1 with StockMoveLine

use of com.axelor.apps.stock.db.StockMoveLine in project axelor-open-suite by axelor.

the class LogisticalFormServiceImpl method addDetailLines.

@Override
public void addDetailLines(LogisticalForm logisticalForm, StockMove stockMove) throws AxelorException {
    Objects.requireNonNull(logisticalForm);
    Objects.requireNonNull(stockMove);
    if (logisticalForm.getDeliverToCustomerPartner() != null && !logisticalForm.getDeliverToCustomerPartner().equals(stockMove.getPartner())) {
        throw new AxelorException(logisticalForm, TraceBackRepository.CATEGORY_INCONSISTENCY, I18n.get(IExceptionMessage.LOGISTICAL_FORM_PARTNER_MISMATCH), logisticalForm.getDeliverToCustomerPartner().getName());
    }
    if (stockMove.getStockMoveLineList() == null) {
        return;
    }
    StockMoveLineService stockMoveLineService = Beans.get(StockMoveLineService.class);
    List<Pair<StockMoveLine, BigDecimal>> toAddList = new ArrayList<>();
    for (StockMoveLine stockMoveLine : stockMove.getStockMoveLineList()) {
        BigDecimal spreadableQty = stockMoveLineService.computeSpreadableQtyOverLogisticalFormLines(stockMoveLine, logisticalForm);
        if (spreadableQty.signum() <= 0) {
            continue;
        }
        if (testForDetailLine(stockMoveLine)) {
            toAddList.add(Pair.of(stockMoveLine, spreadableQty));
        }
    }
    if (!toAddList.isEmpty()) {
        if (logisticalForm.getLogisticalFormLineList() == null || logisticalForm.getLogisticalFormLineList().isEmpty()) {
            addParcelPalletLine(logisticalForm, LogisticalFormLineRepository.TYPE_PARCEL);
        }
        toAddList.forEach(item -> addDetailLine(logisticalForm, item.getLeft(), item.getRight()));
    }
}
Also used : AxelorException(com.axelor.exception.AxelorException) ArrayList(java.util.ArrayList) StockMoveLine(com.axelor.apps.stock.db.StockMoveLine) BigDecimal(java.math.BigDecimal) Pair(org.apache.commons.lang3.tuple.Pair)

Example 2 with StockMoveLine

use of com.axelor.apps.stock.db.StockMoveLine in project axelor-open-suite by axelor.

the class LogisticalFormServiceImpl method getFullySpreadStockMoveLineList.

@Override
public List<StockMoveLine> getFullySpreadStockMoveLineList(LogisticalForm logisticalForm) {
    List<StockMoveLine> stockMoveLineList = new ArrayList<>();
    Map<StockMoveLine, BigDecimal> spreadableQtyMap = new HashMap<>();
    for (LogisticalForm item : findPendingLogisticalForms(logisticalForm)) {
        spreadableQtyMap.putAll(getSpreadableQtyMap(item));
    }
    for (Entry<StockMoveLine, BigDecimal> entry : spreadableQtyMap.entrySet()) {
        StockMoveLine stockMoveLine = entry.getKey();
        BigDecimal spreadableQty = entry.getValue();
        if (spreadableQty.signum() <= 0) {
            stockMoveLineList.add(stockMoveLine);
        }
    }
    return stockMoveLineList;
}
Also used : LogisticalForm(com.axelor.apps.stock.db.LogisticalForm) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) ArrayList(java.util.ArrayList) StockMoveLine(com.axelor.apps.stock.db.StockMoveLine) BigDecimal(java.math.BigDecimal)

Example 3 with StockMoveLine

use of com.axelor.apps.stock.db.StockMoveLine in project axelor-open-suite by axelor.

the class LogisticalFormServiceImpl method getSpreadableQtyMap.

@Override
public Map<StockMoveLine, BigDecimal> getSpreadableQtyMap(LogisticalForm logisticalForm) {
    Set<StockMove> stockMoveSet = new LinkedHashSet<>();
    Map<StockMoveLine, BigDecimal> spreadableQtyMap = new LinkedHashMap<>();
    if (logisticalForm.getLogisticalFormLineList() != null) {
        StockMoveLineService stockMoveLineService = Beans.get(StockMoveLineService.class);
        logisticalForm.getLogisticalFormLineList().stream().filter(logisticalFormLine -> logisticalFormLine.getTypeSelect() == LogisticalFormLineRepository.TYPE_DETAIL && logisticalFormLine.getStockMoveLine() != null && logisticalFormLine.getStockMoveLine().getStockMove() != null).forEach(logisticalFormLine -> stockMoveSet.add(logisticalFormLine.getStockMoveLine().getStockMove()));
        for (StockMove stockMove : stockMoveSet) {
            if (stockMove.getStockMoveLineList() == null) {
                continue;
            }
            for (StockMoveLine stockMoveLine : stockMove.getStockMoveLineList()) {
                BigDecimal spreadableQty = stockMoveLineService.computeSpreadableQtyOverLogisticalFormLines(stockMoveLine, logisticalForm);
                spreadableQtyMap.put(stockMoveLine, spreadableQty);
            }
        }
    }
    return spreadableQtyMap;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) Inject(com.google.inject.Inject) GroovyScriptHelper(com.axelor.script.GroovyScriptHelper) Mapper(com.axelor.db.mapper.Mapper) Transactional(com.google.inject.persist.Transactional) BigDecimal(java.math.BigDecimal) Pair(org.apache.commons.lang3.tuple.Pair) Locale(java.util.Locale) Map(java.util.Map) FreightCarrierCustomerAccountNumber(com.axelor.apps.stock.db.FreightCarrierCustomerAccountNumber) RoundingMode(java.math.RoundingMode) LogisticalForm(com.axelor.apps.stock.db.LogisticalForm) StockConfig(com.axelor.apps.stock.db.StockConfig) StockMove(com.axelor.apps.stock.db.StockMove) StockMoveRepository(com.axelor.apps.stock.db.repo.StockMoveRepository) Set(java.util.Set) Collectors(java.util.stream.Collectors) Objects(java.util.Objects) LogisticalFormLineRepository(com.axelor.apps.stock.db.repo.LogisticalFormLineRepository) List(java.util.List) Product(com.axelor.apps.base.db.Product) ScriptHelper(com.axelor.script.ScriptHelper) Entry(java.util.Map.Entry) Optional(java.util.Optional) AppFilter(com.axelor.app.internal.AppFilter) LogisticalFormError(com.axelor.apps.stock.exception.LogisticalFormError) IExceptionMessage(com.axelor.apps.stock.exception.IExceptionMessage) ProductRepository(com.axelor.apps.base.db.repo.ProductRepository) HashMap(java.util.HashMap) OptionalInt(java.util.OptionalInt) TypedQuery(javax.persistence.TypedQuery) NumberFormat(java.text.NumberFormat) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) LinkedHashMap(java.util.LinkedHashMap) Lists(com.google.common.collect.Lists) AxelorException(com.axelor.exception.AxelorException) ContextEntity(com.axelor.rpc.ContextEntity) I18n(com.axelor.i18n.I18n) LogisticalFormRepository(com.axelor.apps.stock.db.repo.LogisticalFormRepository) LinkedHashSet(java.util.LinkedHashSet) StringTool(com.axelor.apps.tool.StringTool) JPA(com.axelor.db.JPA) LogisticalFormLine(com.axelor.apps.stock.db.LogisticalFormLine) TraceBackRepository(com.axelor.exception.db.repo.TraceBackRepository) LogisticalFormWarning(com.axelor.apps.stock.exception.LogisticalFormWarning) QueryBuilder(com.axelor.apps.tool.QueryBuilder) StockConfigService(com.axelor.apps.stock.service.config.StockConfigService) StockMoveLine(com.axelor.apps.stock.db.StockMoveLine) Beans(com.axelor.inject.Beans) Preconditions(com.google.common.base.Preconditions) Comparator(java.util.Comparator) Context(com.axelor.rpc.Context) StockMove(com.axelor.apps.stock.db.StockMove) StockMoveLine(com.axelor.apps.stock.db.StockMoveLine) BigDecimal(java.math.BigDecimal) LinkedHashMap(java.util.LinkedHashMap)

Example 4 with StockMoveLine

use of com.axelor.apps.stock.db.StockMoveLine in project axelor-open-suite by axelor.

the class LogisticalFormServiceImpl method computeTotals.

@Override
public void computeTotals(LogisticalForm logisticalForm) throws LogisticalFormError {
    BigDecimal totalNetMass = BigDecimal.ZERO;
    BigDecimal totalGrossMass = BigDecimal.ZERO;
    BigDecimal totalVolume = BigDecimal.ZERO;
    if (logisticalForm.getLogisticalFormLineList() != null) {
        ScriptHelper scriptHelper = getScriptHelper(logisticalForm);
        LogisticalFormLineService logisticalFormLineService = Beans.get(LogisticalFormLineService.class);
        for (LogisticalFormLine logisticalFormLine : logisticalForm.getLogisticalFormLineList()) {
            StockMoveLine stockMoveLine = logisticalFormLine.getStockMoveLine();
            if (logisticalFormLine.getTypeSelect() != LogisticalFormLineRepository.TYPE_DETAIL) {
                if (logisticalFormLine.getGrossMass() != null) {
                    totalGrossMass = totalGrossMass.add(logisticalFormLine.getGrossMass());
                }
                BigDecimal toAdd = logisticalFormLineService.evalVolume(logisticalFormLine, scriptHelper);
                if (toAdd == null) {
                    throw new LogisticalFormError(logisticalForm, I18n.get(IExceptionMessage.LOGISTICAL_FORM_INVALID_DIMENSIONS));
                } else {
                    totalVolume = totalVolume.add(toAdd);
                }
            } else if (stockMoveLine != null) {
                totalNetMass = totalNetMass.add(logisticalFormLine.getQty().multiply(stockMoveLine.getNetMass()));
            }
        }
        totalVolume = totalVolume.divide(new BigDecimal(1_000_000), 10, RoundingMode.HALF_UP);
        logisticalForm.setTotalNetMass(totalNetMass.setScale(3, RoundingMode.HALF_UP));
        logisticalForm.setTotalGrossMass(totalGrossMass.setScale(3, RoundingMode.HALF_UP));
        logisticalForm.setTotalVolume(totalVolume.setScale(3, RoundingMode.HALF_UP));
    }
}
Also used : StockMoveLine(com.axelor.apps.stock.db.StockMoveLine) LogisticalFormLine(com.axelor.apps.stock.db.LogisticalFormLine) GroovyScriptHelper(com.axelor.script.GroovyScriptHelper) ScriptHelper(com.axelor.script.ScriptHelper) BigDecimal(java.math.BigDecimal) LogisticalFormError(com.axelor.apps.stock.exception.LogisticalFormError)

Example 5 with StockMoveLine

use of com.axelor.apps.stock.db.StockMoveLine in project axelor-open-suite by axelor.

the class PartnerProductQualityRatingServiceImpl method undoCalculation.

@Override
@Transactional(rollbackOn = { Exception.class })
public void undoCalculation(StockMove stockMove) throws AxelorException {
    Partner partner = stockMove.getPartner();
    if (partner == null || !partner.getIsSupplier()) {
        return;
    }
    List<StockMoveLine> stockMoveLines = stockMove.getStockMoveLineList();
    if (stockMoveLines != null) {
        for (StockMoveLine stockMoveLine : stockMoveLines) {
            Product product = stockMoveLine.getProduct();
            Optional<PartnerProductQualityRating> optional = searchPartnerProductQualityRating(partner, product);
            if (optional.isPresent()) {
                PartnerProductQualityRating partnerProductQualityRating = optional.get();
                updatePartnerProductQualityRating(partnerProductQualityRating, stockMoveLine, true);
            }
        }
    }
    updateSupplier(partner);
}
Also used : PartnerProductQualityRating(com.axelor.apps.stock.db.PartnerProductQualityRating) StockMoveLine(com.axelor.apps.stock.db.StockMoveLine) Product(com.axelor.apps.base.db.Product) Partner(com.axelor.apps.base.db.Partner) Transactional(com.google.inject.persist.Transactional)

Aggregations

StockMoveLine (com.axelor.apps.stock.db.StockMoveLine)121 BigDecimal (java.math.BigDecimal)59 StockMove (com.axelor.apps.stock.db.StockMove)44 AxelorException (com.axelor.exception.AxelorException)41 Product (com.axelor.apps.base.db.Product)33 Transactional (com.google.inject.persist.Transactional)31 ArrayList (java.util.ArrayList)28 List (java.util.List)18 Company (com.axelor.apps.base.db.Company)16 StockMoveRepository (com.axelor.apps.stock.db.repo.StockMoveRepository)16 StockLocation (com.axelor.apps.stock.db.StockLocation)14 StockMoveLineService (com.axelor.apps.stock.service.StockMoveLineService)14 Unit (com.axelor.apps.base.db.Unit)13 Beans (com.axelor.inject.Beans)13 ProdProduct (com.axelor.apps.production.db.ProdProduct)12 StockMoveService (com.axelor.apps.stock.service.StockMoveService)12 I18n (com.axelor.i18n.I18n)12 Inject (com.google.inject.Inject)12 AppBaseService (com.axelor.apps.base.service.app.AppBaseService)10 SaleOrderLine (com.axelor.apps.sale.db.SaleOrderLine)10