Search in sources :

Example 1 with LogisticalForm

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

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

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

the class LogisticalFormController method computeTotals.

public void computeTotals(ActionRequest request, ActionResponse response) {
    try {
        LogisticalForm logisticalForm = request.getContext().asType(LogisticalForm.class);
        Beans.get(LogisticalFormService.class).computeTotals(logisticalForm);
        response.setValue("totalNetMass", logisticalForm.getTotalNetMass());
        response.setValue("totalGrossMass", logisticalForm.getTotalGrossMass());
        response.setValue("totalVolume", logisticalForm.getTotalVolume());
    } catch (LogisticalFormError e) {
        response.setError(e.getLocalizedMessage());
    } catch (Exception e) {
        TraceBackService.trace(response, e);
    }
}
Also used : LogisticalForm(com.axelor.apps.stock.db.LogisticalForm) LogisticalFormService(com.axelor.apps.stock.service.LogisticalFormService) LogisticalFormError(com.axelor.apps.stock.exception.LogisticalFormError)

Example 4 with LogisticalForm

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

the class LogisticalFormController method addStockMove.

public void addStockMove(ActionRequest request, ActionResponse response) {
    try {
        @SuppressWarnings("unchecked") Map<String, Object> stockMoveMap = (Map<String, Object>) request.getContext().get("stockMove");
        if (stockMoveMap != null) {
            StockMove stockMove = Mapper.toBean(StockMove.class, stockMoveMap);
            stockMove = Beans.get(StockMoveRepository.class).find(stockMove.getId());
            if (stockMove.getStockMoveLineList() != null) {
                LogisticalForm logisticalForm = request.getContext().asType(LogisticalForm.class);
                LogisticalFormService logisticalFormService = Beans.get(LogisticalFormService.class);
                logisticalFormService.addDetailLines(logisticalForm, stockMove);
                response.setValue("logisticalFormLineList", logisticalForm.getLogisticalFormLineList());
                response.setValue("$stockMove", null);
            }
        }
    } catch (Exception e) {
        TraceBackService.trace(response, e);
    }
}
Also used : StockMove(com.axelor.apps.stock.db.StockMove) LogisticalForm(com.axelor.apps.stock.db.LogisticalForm) LogisticalFormService(com.axelor.apps.stock.service.LogisticalFormService) Map(java.util.Map)

Example 5 with LogisticalForm

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

the class LogisticalFormController method setCustomerAccountNumberToCarrier.

public void setCustomerAccountNumberToCarrier(ActionRequest request, ActionResponse response) {
    try {
        LogisticalForm logisticalForm = request.getContext().asType(LogisticalForm.class);
        Optional<String> customerAccountNumberToCarrier = Beans.get(LogisticalFormService.class).getCustomerAccountNumberToCarrier(logisticalForm);
        response.setValue("customerAccountNumberToCarrier", customerAccountNumberToCarrier.orElse(null));
    } catch (Exception e) {
        TraceBackService.trace(response, e);
    }
}
Also used : LogisticalForm(com.axelor.apps.stock.db.LogisticalForm) LogisticalFormService(com.axelor.apps.stock.service.LogisticalFormService)

Aggregations

LogisticalForm (com.axelor.apps.stock.db.LogisticalForm)12 LogisticalFormService (com.axelor.apps.stock.service.LogisticalFormService)7 LogisticalFormError (com.axelor.apps.stock.exception.LogisticalFormError)5 StockMoveLine (com.axelor.apps.stock.db.StockMoveLine)4 BigDecimal (java.math.BigDecimal)4 ArrayList (java.util.ArrayList)4 LogisticalFormLine (com.axelor.apps.stock.db.LogisticalFormLine)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 LogisticalFormWarning (com.axelor.apps.stock.exception.LogisticalFormWarning)3 StringTool (com.axelor.apps.tool.StringTool)3 I18n (com.axelor.i18n.I18n)3 Beans (com.axelor.inject.Beans)3 ScriptHelper (com.axelor.script.ScriptHelper)3 AppFilter (com.axelor.app.internal.AppFilter)2 Product (com.axelor.apps.base.db.Product)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