Search in sources :

Example 6 with LogisticalForm

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

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

the class LogisticalFormLineServiceImpl method getStockMoveLineDomain.

@Override
public String getStockMoveLineDomain(LogisticalFormLine logisticalFormLine) {
    long partnerId = 0;
    List<String> domainList = new ArrayList<>();
    LogisticalForm logisticalForm = logisticalFormLine.getLogisticalForm();
    if (logisticalForm != null) {
        Partner deliverToCustomerPartner = logisticalForm.getDeliverToCustomerPartner();
        if (deliverToCustomerPartner != null) {
            partnerId = deliverToCustomerPartner.getId();
        }
    }
    domainList.add(String.format("self.stockMove.partner.id = %d", partnerId));
    domainList.add(String.format("self.stockMove.typeSelect = %d", StockMoveRepository.TYPE_OUTGOING));
    domainList.add(String.format("self.stockMove.statusSelect in (%d, %d)", StockMoveRepository.STATUS_PLANNED, StockMoveRepository.STATUS_REALIZED));
    domainList.add("self.realQty > 0");
    domainList.add("COALESCE(self.stockMove.fullySpreadOverLogisticalFormsFlag, FALSE) = FALSE");
    if (logisticalForm.getStockLocation() != null) {
        domainList.add(String.format("self.stockMove.fromStockLocation.id = %d", logisticalForm.getStockLocation().getId()));
    }
    List<StockMoveLine> fullySpreadStockMoveLineList = Beans.get(LogisticalFormService.class).getFullySpreadStockMoveLineList(logisticalForm);
    if (!fullySpreadStockMoveLineList.isEmpty()) {
        String idListString = StringTool.getIdListString(fullySpreadStockMoveLineList);
        domainList.add(String.format("self.id NOT IN (%s)", idListString));
    }
    return domainList.stream().map(domain -> String.format("(%s)", domain)).collect(Collectors.joining(" AND "));
}
Also used : StringTool(com.axelor.apps.tool.StringTool) LogisticalForm(com.axelor.apps.stock.db.LogisticalForm) LogisticalFormLine(com.axelor.apps.stock.db.LogisticalFormLine) IExceptionMessage(com.axelor.apps.stock.exception.IExceptionMessage) StockMoveRepository(com.axelor.apps.stock.db.repo.StockMoveRepository) Collectors(java.util.stream.Collectors) ArrayList(java.util.ArrayList) StockMoveLine(com.axelor.apps.stock.db.StockMoveLine) Strings(com.google.common.base.Strings) BigDecimal(java.math.BigDecimal) List(java.util.List) Beans(com.axelor.inject.Beans) ScriptHelper(com.axelor.script.ScriptHelper) I18n(com.axelor.i18n.I18n) Pattern(java.util.regex.Pattern) Partner(com.axelor.apps.base.db.Partner) LogisticalFormError(com.axelor.apps.stock.exception.LogisticalFormError) LogisticalForm(com.axelor.apps.stock.db.LogisticalForm) ArrayList(java.util.ArrayList) StockMoveLine(com.axelor.apps.stock.db.StockMoveLine) Partner(com.axelor.apps.base.db.Partner)

Example 8 with LogisticalForm

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

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

the class LogisticalFormController method print.

public void print(ActionRequest request, ActionResponse response) {
    try {
        LogisticalForm logisticalForm = request.getContext().asType(LogisticalForm.class);
        String name = String.format("%s %s", I18n.get("Packing list"), logisticalForm.getDeliveryNumberSeq());
        String fileLink = ReportFactory.createReport(IReport.PACKING_LIST, name + " - ${date}").addParam("LogisticalFormId", logisticalForm.getId()).addParam("Timezone", logisticalForm.getCompany() != null ? logisticalForm.getCompany().getTimezone() : null).addParam("Locale", ReportSettings.getPrintingLocale(logisticalForm.getDeliverToCustomerPartner())).generate().getFileLink();
        response.setView(ActionView.define(name).add("html", fileLink).map());
    } catch (Exception e) {
        TraceBackService.trace(response, e);
    }
}
Also used : LogisticalForm(com.axelor.apps.stock.db.LogisticalForm)

Example 10 with LogisticalForm

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

the class LogisticalFormController method processCollected.

public void processCollected(ActionRequest request, ActionResponse response) {
    try {
        LogisticalForm logisticalForm = request.getContext().asType(LogisticalForm.class);
        logisticalForm = Beans.get(LogisticalFormRepository.class).find(logisticalForm.getId());
        Beans.get(LogisticalFormService.class).processCollected(logisticalForm);
        response.setReload(true);
    } 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