Search in sources :

Example 1 with LogisticalFormLine

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

the class LogisticalFormServiceImpl method updateProductNetMass.

public void updateProductNetMass(LogisticalForm logisticalForm) {
    BigDecimal totalNetMass = BigDecimal.ZERO;
    if (logisticalForm.getLogisticalFormLineList() != null) {
        for (LogisticalFormLine logisticalFormLine : logisticalForm.getLogisticalFormLineList()) {
            if (logisticalFormLine.getStockMoveLine() != null && logisticalFormLine.getStockMoveLine().getProduct() != null && logisticalFormLine.getTypeSelect().equals(LogisticalFormLineRepository.TYPE_DETAIL)) {
                Product product = productRepository.find(logisticalFormLine.getStockMoveLine().getProduct().getId());
                logisticalFormLine.setUnitNetMass(product.getNetMass());
                totalNetMass = totalNetMass.add(logisticalFormLine.getQty().multiply(product.getNetMass()));
            }
        }
        logisticalForm.setTotalNetMass(totalNetMass);
    }
}
Also used : Product(com.axelor.apps.base.db.Product) LogisticalFormLine(com.axelor.apps.stock.db.LogisticalFormLine) BigDecimal(java.math.BigDecimal)

Example 2 with LogisticalFormLine

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

the class LogisticalFormServiceImpl method addParcelPalletLine.

@Override
public void addParcelPalletLine(LogisticalForm logisticalForm, int typeSelect) {
    LogisticalFormLine logisticalFormLine = new LogisticalFormLine();
    logisticalFormLine.setTypeSelect(typeSelect);
    logisticalFormLine.setParcelPalletNumber(getNextParcelPalletNumber(logisticalForm, typeSelect));
    logisticalFormLine.setSequence(getNextLineSequence(logisticalForm));
    addLogisticalFormLineListItem(logisticalForm, logisticalFormLine);
}
Also used : LogisticalFormLine(com.axelor.apps.stock.db.LogisticalFormLine)

Example 3 with LogisticalFormLine

use of com.axelor.apps.stock.db.LogisticalFormLine 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 LogisticalFormLine

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

the class LogisticalFormServiceImpl method createLogisticalFormLine.

protected LogisticalFormLine createLogisticalFormLine(LogisticalForm logisticalForm, StockMoveLine stockMoveLine, BigDecimal qty) {
    LogisticalFormLine logisticalFormLine = new LogisticalFormLine();
    logisticalFormLine.setTypeSelect(LogisticalFormLineRepository.TYPE_DETAIL);
    logisticalFormLine.setStockMoveLine(stockMoveLine);
    logisticalFormLine.setQty(qty);
    logisticalFormLine.setSequence(getNextLineSequence(logisticalForm));
    logisticalFormLine.setUnitNetMass(stockMoveLine.getNetMass());
    return logisticalFormLine;
}
Also used : LogisticalFormLine(com.axelor.apps.stock.db.LogisticalFormLine)

Example 5 with LogisticalFormLine

use of com.axelor.apps.stock.db.LogisticalFormLine 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)

Aggregations

LogisticalFormLine (com.axelor.apps.stock.db.LogisticalFormLine)14 BigDecimal (java.math.BigDecimal)7 LogisticalFormError (com.axelor.apps.stock.exception.LogisticalFormError)5 StockMoveLine (com.axelor.apps.stock.db.StockMoveLine)4 ScriptHelper (com.axelor.script.ScriptHelper)4 Product (com.axelor.apps.base.db.Product)3 LogisticalForm (com.axelor.apps.stock.db.LogisticalForm)3 StockMove (com.axelor.apps.stock.db.StockMove)3 StockMoveRepository (com.axelor.apps.stock.db.repo.StockMoveRepository)3 IExceptionMessage (com.axelor.apps.stock.exception.IExceptionMessage)3 LogisticalFormLineService (com.axelor.apps.stock.service.LogisticalFormLineService)3 StringTool (com.axelor.apps.tool.StringTool)3 I18n (com.axelor.i18n.I18n)3 Beans (com.axelor.inject.Beans)3 GroovyScriptHelper (com.axelor.script.GroovyScriptHelper)3 ArrayList (java.util.ArrayList)3 AppFilter (com.axelor.app.internal.AppFilter)2 ProductRepository (com.axelor.apps.base.db.repo.ProductRepository)2 FreightCarrierCustomerAccountNumber (com.axelor.apps.stock.db.FreightCarrierCustomerAccountNumber)2 StockConfig (com.axelor.apps.stock.db.StockConfig)2