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));
}
}
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);
}
}
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);
}
}
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);
}
}
}
Aggregations