Search in sources :

Example 1 with LogisticalFormError

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

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

use of com.axelor.apps.stock.exception.LogisticalFormError in project axelor-open-suite by axelor.

the class LogisticalFormController method checkLines.

public void checkLines(ActionRequest request, ActionResponse response) {
    try {
        LogisticalForm logisticalForm = request.getContext().asType(LogisticalForm.class);
        LogisticalFormService logisticalFormService = Beans.get(LogisticalFormService.class);
        logisticalFormService.sortLines(logisticalForm);
        logisticalFormService.checkLines(logisticalForm);
    } catch (LogisticalFormWarning e) {
        response.setAlert(e.getLocalizedMessage());
    } 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) LogisticalFormWarning(com.axelor.apps.stock.exception.LogisticalFormWarning)

Example 4 with LogisticalFormError

use of com.axelor.apps.stock.exception.LogisticalFormError in project axelor-open-suite by axelor.

the class LogisticalFormServiceImpl method checkEmptyParcelPalletLines.

protected void checkEmptyParcelPalletLines(LogisticalForm logisticalForm, List<String> errorMessageList) throws LogisticalFormError {
    if (logisticalForm.getLogisticalFormLineList() == null) {
        return;
    }
    Map<LogisticalFormLine, BigDecimal> qtyMap = new HashMap<>();
    LogisticalFormLine currentLine = null;
    for (LogisticalFormLine logisticalFormLine : logisticalForm.getLogisticalFormLineList()) {
        if (logisticalFormLine.getTypeSelect() != LogisticalFormLineRepository.TYPE_DETAIL) {
            currentLine = logisticalFormLine;
            qtyMap.put(currentLine, BigDecimal.ZERO);
        } else {
            if (currentLine == null) {
                throw new LogisticalFormError(logisticalForm, I18n.get(IExceptionMessage.LOGISTICAL_FORM_LINES_ORPHAN_DETAIL));
            }
            qtyMap.merge(currentLine, logisticalFormLine.getQty(), BigDecimal::add);
        }
    }
    for (Entry<LogisticalFormLine, BigDecimal> entry : qtyMap.entrySet()) {
        LogisticalFormLine logisticalFormLine = entry.getKey();
        BigDecimal qty = entry.getValue();
        if (qty.signum() <= 0) {
            String msg;
            if (logisticalFormLine.getTypeSelect() == LogisticalFormLineRepository.TYPE_PARCEL) {
                msg = I18n.get(IExceptionMessage.LOGISTICAL_FORM_LINES_EMPTY_PARCEL);
            } else {
                msg = I18n.get(IExceptionMessage.LOGISTICAL_FORM_LINES_EMPTY_PALLET);
            }
            String errorMessage = String.format(msg, logisticalFormLine.getParcelPalletNumber());
            errorMessageList.add(errorMessage);
        }
    }
}
Also used : HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) LogisticalFormLine(com.axelor.apps.stock.db.LogisticalFormLine) BigDecimal(java.math.BigDecimal) LogisticalFormError(com.axelor.apps.stock.exception.LogisticalFormError)

Aggregations

LogisticalFormError (com.axelor.apps.stock.exception.LogisticalFormError)4 LogisticalForm (com.axelor.apps.stock.db.LogisticalForm)2 LogisticalFormLine (com.axelor.apps.stock.db.LogisticalFormLine)2 LogisticalFormService (com.axelor.apps.stock.service.LogisticalFormService)2 BigDecimal (java.math.BigDecimal)2 StockMoveLine (com.axelor.apps.stock.db.StockMoveLine)1 LogisticalFormWarning (com.axelor.apps.stock.exception.LogisticalFormWarning)1 GroovyScriptHelper (com.axelor.script.GroovyScriptHelper)1 ScriptHelper (com.axelor.script.ScriptHelper)1 HashMap (java.util.HashMap)1 LinkedHashMap (java.util.LinkedHashMap)1