Search in sources :

Example 11 with LogisticalFormLine

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

Example 12 with LogisticalFormLine

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

the class LogisticalFormServiceImpl method addDetailLine.

protected void addDetailLine(LogisticalForm logisticalForm, StockMoveLine stockMoveLine, BigDecimal qty) {
    Preconditions.checkNotNull(logisticalForm);
    Preconditions.checkNotNull(stockMoveLine);
    LogisticalFormLine logisticalFormLine = createLogisticalFormLine(logisticalForm, stockMoveLine, qty);
    addLogisticalFormLineListItem(logisticalForm, logisticalFormLine);
}
Also used : LogisticalFormLine(com.axelor.apps.stock.db.LogisticalFormLine)

Example 13 with LogisticalFormLine

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

the class LogisticalFormServiceImpl method processCollected.

@Override
@Transactional(rollbackOn = { Exception.class })
public void processCollected(LogisticalForm logisticalForm) throws AxelorException {
    if (logisticalForm.getLogisticalFormLineList() == null) {
        return;
    }
    Set<StockMove> stockMoveSet = new HashSet<>();
    logisticalForm.getLogisticalFormLineList().stream().filter(logisticalFormLine -> logisticalFormLine.getTypeSelect() == LogisticalFormLineRepository.TYPE_DETAIL && logisticalFormLine.getStockMoveLine() != null && logisticalFormLine.getStockMoveLine().getStockMove() != null).forEach(logisticalFormLine -> stockMoveSet.add(logisticalFormLine.getStockMoveLine().getStockMove()));
    StockMoveService stockMoveService = Beans.get(StockMoveService.class);
    stockMoveSet.forEach(stockMoveService::updateFullySpreadOverLogisticalFormsFlag);
    StockConfigService stockConfigService = Beans.get(StockConfigService.class);
    StockConfig stockConfig = stockConfigService.getStockConfig(logisticalForm.getCompany());
    if (stockConfig.getRealizeStockMovesUponParcelPalletCollection()) {
        for (StockMove stockMove : stockMoveSet) {
            if (stockMove.getFullySpreadOverLogisticalFormsFlag()) {
                stockMoveService.realize(stockMove);
            }
        }
    }
    logisticalForm.setStatusSelect(LogisticalFormRepository.STATUS_COLLECTED);
}
Also used : 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) StockConfig(com.axelor.apps.stock.db.StockConfig) StockConfigService(com.axelor.apps.stock.service.config.StockConfigService) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet) Transactional(com.google.inject.persist.Transactional)

Example 14 with LogisticalFormLine

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

the class LogisticalFormLineController method setStockMoveLineDomain.

public void setStockMoveLineDomain(ActionRequest request, ActionResponse response) {
    try {
        LogisticalFormLine logisticalFormLine = getLogisticalFormLine(request);
        String domain = Beans.get(LogisticalFormLineService.class).getStockMoveLineDomain(logisticalFormLine);
        response.setAttr("stockMoveLine", "domain", domain);
    } catch (Exception e) {
        TraceBackService.trace(response, e);
    }
}
Also used : LogisticalFormLineService(com.axelor.apps.stock.service.LogisticalFormLineService) LogisticalFormLine(com.axelor.apps.stock.db.LogisticalFormLine)

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