Search in sources :

Example 1 with SupplyChainConfig

use of com.axelor.apps.supplychain.db.SupplyChainConfig in project axelor-open-suite by axelor.

the class SaleOrderLineServiceSupplyChainImpl method createSaleOrderLine.

@Override
public SaleOrderLine createSaleOrderLine(PackLine packLine, SaleOrder saleOrder, BigDecimal packQty, BigDecimal conversionRate, Integer sequence) {
    SaleOrderLine soLine = super.createSaleOrderLine(packLine, saleOrder, packQty, conversionRate, sequence);
    if (soLine != null && soLine.getProduct() != null) {
        soLine.setSaleSupplySelect(soLine.getProduct().getSaleSupplySelect());
        getAndComputeAnalyticDistribution(soLine, saleOrder);
        if (ObjectUtils.notEmpty(soLine.getAnalyticMoveLineList())) {
            soLine.getAnalyticMoveLineList().stream().forEach(analyticMoveLine -> analyticMoveLine.setSaleOrderLine(soLine));
        }
        try {
            SupplyChainConfig supplyChainConfig = Beans.get(SupplyChainConfigService.class).getSupplyChainConfig(saleOrder.getCompany());
            if (supplyChainConfig.getAutoRequestReservedQty()) {
                Beans.get(ReservedQtyService.class).requestQty(soLine);
            }
        } catch (AxelorException e) {
            TraceBackService.trace(e);
        }
    }
    return soLine;
}
Also used : AxelorException(com.axelor.exception.AxelorException) SupplyChainConfigService(com.axelor.apps.supplychain.service.config.SupplyChainConfigService) SupplyChainConfig(com.axelor.apps.supplychain.db.SupplyChainConfig) SaleOrderLine(com.axelor.apps.sale.db.SaleOrderLine)

Example 2 with SupplyChainConfig

use of com.axelor.apps.supplychain.db.SupplyChainConfig in project axelor-open-suite by axelor.

the class ReservedQtyServiceImpl method updateRequestedQuantityInToStockLocation.

@Override
public void updateRequestedQuantityInToStockLocation(StockMoveLine stockMoveLine, StockLocation stockLocation, Product product, int toStatus, BigDecimal qty) throws AxelorException {
    if (product == null || !product.getStockManaged()) {
        return;
    }
    StockLocationLine stockLocationLine = stockLocationLineService.getStockLocationLine(stockLocation, product);
    if (stockLocationLine == null) {
        return;
    }
    Company company = stockLocationLine.getStockLocation().getCompany();
    SupplyChainConfig supplyChainConfig = supplychainConfigService.getSupplyChainConfig(company);
    if (toStatus == StockMoveRepository.STATUS_REALIZED && supplyChainConfig.getAutoAllocateOnReceipt()) {
        reallocateQty(stockMoveLine, stockLocation, stockLocationLine, product, qty);
    }
    updateRequestedReservedQty(stockLocationLine);
    checkReservedQtyStocks(stockLocationLine, stockMoveLine, toStatus);
}
Also used : Company(com.axelor.apps.base.db.Company) StockLocationLine(com.axelor.apps.stock.db.StockLocationLine) SupplyChainConfig(com.axelor.apps.supplychain.db.SupplyChainConfig)

Example 3 with SupplyChainConfig

use of com.axelor.apps.supplychain.db.SupplyChainConfig in project axelor-open-suite by axelor.

the class StockMoveController method allocateAll.

/**
 * Called from stock move form view, on available qty boolean change. Only called if the user
 * accepted to allocate everything. Call {@link
 * StockMoveReservedQtyService#allocateAll(StockMove)}.
 *
 * @param request
 * @param response
 */
public void allocateAll(ActionRequest request, ActionResponse response) {
    try {
        StockMove stockMove = request.getContext().asType(StockMove.class);
        Company company = stockMove.getCompany();
        if (company == null) {
            return;
        }
        SupplyChainConfig supplyChainConfig = Beans.get(SupplyChainConfigService.class).getSupplyChainConfig(company);
        if (!Beans.get(AppSupplychainService.class).getAppSupplychain().getManageStockReservation() || !stockMove.getAvailabilityRequest() || !supplyChainConfig.getAutoAllocateOnAvailabilityRequest()) {
            return;
        }
        Beans.get(StockMoveReservedQtyService.class).allocateAll(stockMove);
    } catch (Exception e) {
        TraceBackService.trace(response, e);
    } finally {
        response.setReload(true);
    }
}
Also used : Company(com.axelor.apps.base.db.Company) StockMove(com.axelor.apps.stock.db.StockMove) StockMoveReservedQtyService(com.axelor.apps.supplychain.service.StockMoveReservedQtyService) SupplyChainConfigService(com.axelor.apps.supplychain.service.config.SupplyChainConfigService) SupplyChainConfig(com.axelor.apps.supplychain.db.SupplyChainConfig) AppSupplychainService(com.axelor.apps.supplychain.service.app.AppSupplychainService)

Example 4 with SupplyChainConfig

use of com.axelor.apps.supplychain.db.SupplyChainConfig in project axelor-open-suite by axelor.

the class StockMoveInvoiceController method openInvoicingWizard.

public void openInvoicingWizard(ActionRequest request, ActionResponse response) {
    try {
        response.setReload(true);
        StockMove stockMove = request.getContext().asType(StockMove.class);
        stockMove = Beans.get(StockMoveRepository.class).find(stockMove.getId());
        StockMoveInvoiceService stockMoveInvoiceService = Beans.get(StockMoveInvoiceService.class);
        List<Map<String, Object>> stockMoveLines = stockMoveInvoiceService.getStockMoveLinesToInvoice(stockMove);
        Company company = stockMove.getCompany();
        SupplyChainConfig supplyChainConfig = Beans.get(SupplyChainConfigService.class).getSupplyChainConfig(company);
        boolean isPartialInvoicingActivated = (stockMove.getTypeSelect() == StockMoveRepository.TYPE_INCOMING && supplyChainConfig.getActivateIncStockMovePartialInvoicing()) || (stockMove.getTypeSelect() == StockMoveRepository.TYPE_OUTGOING && supplyChainConfig.getActivateOutStockMovePartialInvoicing());
        if (isPartialInvoicingActivated && !stockMoveLines.isEmpty()) {
            // open wizard view for partial invoicing
            response.setView(ActionView.define(I18n.get(ITranslation.INVOICING)).model(StockMove.class.getName()).add("form", "stock-move-invoicing-wizard-form").param("popup", "reload").param("show-toolbar", "false").param("show-confirm", "false").param("width", "large").param("popup-save", "false").context("_id", stockMove.getId()).map());
        } else if (!stockMoveLines.isEmpty()) {
            // invoice everything if config is disabled.
            Invoice invoice = stockMoveInvoiceService.createInvoice(stockMove, StockMoveRepository.INVOICE_ALL, null);
            if (invoice != null) {
                response.setView(ActionView.define(I18n.get(ITranslation.INVOICE)).model(Invoice.class.getName()).add("grid", "invoice-grid").add("form", "invoice-form").param("search-filters", "customer-invoices-filters").param("forceEdit", "true").context("_showRecord", String.valueOf(invoice.getId())).context("_operationTypeSelect", invoice.getOperationTypeSelect()).context("todayDate", Beans.get(AppSupplychainService.class).getTodayDate(company)).map());
            }
        } else {
            response.setAlert(I18n.get(IExceptionMessage.STOCK_MOVE_INVOICE_ERROR));
        }
    } catch (Exception e) {
        TraceBackService.trace(response, e);
    }
}
Also used : Company(com.axelor.apps.base.db.Company) StockMove(com.axelor.apps.stock.db.StockMove) Invoice(com.axelor.apps.account.db.Invoice) SupplyChainConfigService(com.axelor.apps.supplychain.service.config.SupplyChainConfigService) SupplyChainConfig(com.axelor.apps.supplychain.db.SupplyChainConfig) StockMoveInvoiceService(com.axelor.apps.supplychain.service.StockMoveInvoiceService) Map(java.util.Map) AppSupplychainService(com.axelor.apps.supplychain.service.app.AppSupplychainService)

Example 5 with SupplyChainConfig

use of com.axelor.apps.supplychain.db.SupplyChainConfig in project axelor-open-suite by axelor.

the class SaleOrderStockServiceImpl method createStockMove.

protected Optional<StockMove> createStockMove(SaleOrder saleOrder, LocalDate estimatedDeliveryDate, List<SaleOrderLine> saleOrderLineList) throws AxelorException {
    StockMove stockMove = this.createStockMove(saleOrder, saleOrder.getCompany(), estimatedDeliveryDate);
    stockMove.setDeliveryCondition(saleOrder.getDeliveryCondition());
    for (SaleOrderLine saleOrderLine : saleOrderLineList) {
        if (saleOrderLine.getProduct() != null) {
            BigDecimal qty = saleOrderLineServiceSupplyChain.computeUndeliveredQty(saleOrderLine);
            if (qty.signum() > 0 && !existActiveStockMoveForSaleOrderLine(saleOrderLine)) {
                createStockMoveLine(stockMove, saleOrderLine, qty);
            }
        }
    }
    if (stockMove.getStockMoveLineList() == null || stockMove.getStockMoveLineList().isEmpty()) {
        return Optional.empty();
    }
    if (stockMove.getStockMoveLineList().stream().noneMatch(stockMoveLine -> stockMoveLine.getSaleOrderLine() != null && stockMoveLine.getSaleOrderLine().getTypeSelect() == SaleOrderLineRepository.TYPE_NORMAL)) {
        stockMove.setFullySpreadOverLogisticalFormsFlag(true);
    }
    boolean isNeedingConformityCertificate = saleOrder.getIsNeedingConformityCertificate();
    stockMove.setIsNeedingConformityCertificate(isNeedingConformityCertificate);
    if (isNeedingConformityCertificate) {
        stockMove.setSignatoryUser(stockConfigService.getStockConfig(stockMove.getCompany()).getSignatoryUser());
    }
    SupplyChainConfig supplychainConfig = Beans.get(SupplyChainConfigService.class).getSupplyChainConfig(saleOrder.getCompany());
    if (supplychainConfig.getDefaultEstimatedDate() != null && supplychainConfig.getDefaultEstimatedDate() == SupplyChainConfigRepository.CURRENT_DATE && stockMove.getEstimatedDate() == null) {
        stockMove.setEstimatedDate(appBaseService.getTodayDate(saleOrder.getCompany()));
    } else if (supplychainConfig.getDefaultEstimatedDate() == SupplyChainConfigRepository.CURRENT_DATE_PLUS_DAYS && stockMove.getEstimatedDate() == null) {
        stockMove.setEstimatedDate(appBaseService.getTodayDate(saleOrder.getCompany()).plusDays(supplychainConfig.getNumberOfDays().longValue()));
    }
    setReservationDateTime(stockMove, saleOrder);
    stockMoveService.plan(stockMove);
    return Optional.of(stockMove);
}
Also used : StockMove(com.axelor.apps.stock.db.StockMove) SupplyChainConfigService(com.axelor.apps.supplychain.service.config.SupplyChainConfigService) SupplyChainConfig(com.axelor.apps.supplychain.db.SupplyChainConfig) SaleOrderLine(com.axelor.apps.sale.db.SaleOrderLine) BigDecimal(java.math.BigDecimal)

Aggregations

SupplyChainConfig (com.axelor.apps.supplychain.db.SupplyChainConfig)11 Company (com.axelor.apps.base.db.Company)8 SupplyChainConfigService (com.axelor.apps.supplychain.service.config.SupplyChainConfigService)7 StockMove (com.axelor.apps.stock.db.StockMove)5 SaleOrderLine (com.axelor.apps.sale.db.SaleOrderLine)3 Product (com.axelor.apps.base.db.Product)2 StockMoveLine (com.axelor.apps.stock.db.StockMoveLine)2 AppSupplychainService (com.axelor.apps.supplychain.service.app.AppSupplychainService)2 AxelorException (com.axelor.exception.AxelorException)2 BigDecimal (java.math.BigDecimal)2 Invoice (com.axelor.apps.account.db.Invoice)1 Address (com.axelor.apps.base.db.Address)1 Partner (com.axelor.apps.base.db.Partner)1 PartnerService (com.axelor.apps.base.service.PartnerService)1 AppBaseService (com.axelor.apps.base.service.app.AppBaseService)1 ProdProduct (com.axelor.apps.production.db.ProdProduct)1 PurchaseOrderLine (com.axelor.apps.purchase.db.PurchaseOrderLine)1 StockLocation (com.axelor.apps.stock.db.StockLocation)1 StockLocationLine (com.axelor.apps.stock.db.StockLocationLine)1 StockMoveInvoiceService (com.axelor.apps.supplychain.service.StockMoveInvoiceService)1