Search in sources :

Example 66 with StockMoveLine

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

the class ReservedQtyServiceImpl method updateReservedQty.

@Override
@Transactional(rollbackOn = { Exception.class })
public void updateReservedQty(SaleOrderLine saleOrderLine, BigDecimal newReservedQty) throws AxelorException {
    if (saleOrderLine.getProduct() == null || !saleOrderLine.getProduct().getStockManaged()) {
        return;
    }
    StockMoveLine stockMoveLine = getPlannedStockMoveLine(saleOrderLine);
    checkBeforeUpdatingQties(stockMoveLine, newReservedQty);
    if (Beans.get(AppSupplychainService.class).getAppSupplychain().getBlockDeallocationOnAvailabilityRequest()) {
        checkAvailabilityRequest(stockMoveLine, newReservedQty, false);
    }
    BigDecimal newRequestedReservedQty = newReservedQty.add(saleOrderLine.getDeliveredQty());
    // update requested reserved qty
    if (newRequestedReservedQty.compareTo(saleOrderLine.getRequestedReservedQty()) > 0 && newReservedQty.compareTo(BigDecimal.ZERO) > 0) {
        requestQty(saleOrderLine);
    }
    StockLocationLine stockLocationLine = stockLocationLineService.getOrCreateStockLocationLine(stockMoveLine.getStockMove().getFromStockLocation(), stockMoveLine.getProduct());
    BigDecimal availableQtyToBeReserved = stockLocationLine.getCurrentQty().subtract(stockLocationLine.getReservedQty());
    BigDecimal diffReservedQuantity = newReservedQty.subtract(saleOrderLine.getReservedQty());
    Product product = stockMoveLine.getProduct();
    BigDecimal diffReservedQuantityLocation = convertUnitWithProduct(saleOrderLine.getUnit(), stockLocationLine.getUnit(), diffReservedQuantity, product);
    if (availableQtyToBeReserved.compareTo(diffReservedQuantityLocation) < 0) {
        throw new AxelorException(TraceBackRepository.CATEGORY_INCONSISTENCY, I18n.get(IExceptionMessage.SALE_ORDER_LINE_QTY_NOT_AVAILABLE));
    }
    // update in stock move line and sale order line
    updateReservedQuantityInStockMoveLineFromSaleOrderLine(saleOrderLine, stockMoveLine.getProduct(), newReservedQty);
    // update in stock location line
    updateReservedQty(stockLocationLine);
}
Also used : AxelorException(com.axelor.exception.AxelorException) StockMoveLine(com.axelor.apps.stock.db.StockMoveLine) Product(com.axelor.apps.base.db.Product) StockLocationLine(com.axelor.apps.stock.db.StockLocationLine) BigDecimal(java.math.BigDecimal) Transactional(com.google.inject.persist.Transactional)

Example 67 with StockMoveLine

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

the class StockMoveLineSupplychainRepository method populate.

@Override
public Map<String, Object> populate(Map<String, Object> json, Map<String, Object> context) {
    Long stockMoveLineId = (Long) json.get("id");
    StockMoveLine stockMoveLine = find(stockMoveLineId);
    StockMove stockMove = stockMoveLine.getStockMove();
    Map<String, Object> stockMoveLineMap = super.populate(json, context);
    if (stockMove != null && stockMove.getStatusSelect() == StockMoveRepository.STATUS_REALIZED) {
        Beans.get(StockMoveLineServiceSupplychain.class).setInvoiceStatus(stockMoveLine);
        json.put("availableStatus", stockMoveLine.getProduct() != null && stockMoveLine.getProduct().getStockManaged() ? stockMoveLine.getAvailableStatus() : null);
        json.put("availableStatusSelect", stockMoveLine.getAvailableStatusSelect());
    }
    return stockMoveLineMap;
}
Also used : StockMoveLineServiceSupplychain(com.axelor.apps.supplychain.service.StockMoveLineServiceSupplychain) StockMove(com.axelor.apps.stock.db.StockMove) StockMoveLine(com.axelor.apps.stock.db.StockMoveLine)

Example 68 with StockMoveLine

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

the class StockMoveSupplychainRepository method copy.

@Override
public StockMove copy(StockMove entity, boolean deep) {
    StockMove copy = super.copy(entity, deep);
    copy.setInvoiceSet(null);
    copy.setOriginTypeSelect(null);
    copy.setOrigin(null);
    copy.setOriginId(null);
    if (copy.getStockMoveLineList() != null) {
        for (StockMoveLine stockMoveLine : copy.getStockMoveLineList()) {
            stockMoveLine.setReservedQty(BigDecimal.ZERO);
            stockMoveLine.setRequestedReservedQty(BigDecimal.ZERO);
            stockMoveLine.setIsQtyRequested(false);
            stockMoveLine.setReservationDateTime(null);
            stockMoveLine.setQtyInvoiced(null);
            stockMoveLine.setSaleOrderLine(null);
            stockMoveLine.setPurchaseOrderLine(null);
        }
    }
    copy.setInvoicingStatusSelect(StockMoveRepository.STATUS_NOT_INVOICED);
    return copy;
}
Also used : StockMove(com.axelor.apps.stock.db.StockMove) StockMoveLine(com.axelor.apps.stock.db.StockMoveLine)

Example 69 with StockMoveLine

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

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

the class LogisticalFormServiceImpl method checkInconsistentQties.

protected void checkInconsistentQties(LogisticalForm logisticalForm, List<String> errorMessageList) {
    Map<StockMoveLine, BigDecimal> spreadableQtyMap = getSpreadableQtyMap(logisticalForm);
    Map<StockMoveLine, BigDecimal> spreadQtyMap = getSpreadQtyMap(logisticalForm);
    Locale locale = AppFilter.getLocale();
    NumberFormat nf = NumberFormat.getInstance(locale);
    for (Entry<StockMoveLine, BigDecimal> entry : spreadableQtyMap.entrySet()) {
        StockMoveLine stockMoveLine = entry.getKey();
        BigDecimal spreadableQty = entry.getValue();
        if (spreadableQty.signum() != 0) {
            BigDecimal spreadQty = spreadQtyMap.getOrDefault(stockMoveLine, BigDecimal.ZERO);
            BigDecimal expectedQty = spreadQty.add(spreadableQty);
            String errorMessage = String.format(locale, I18n.get(IExceptionMessage.LOGISTICAL_FORM_LINES_INCONSISTENT_QUANTITY), String.format("%s (%s)", stockMoveLine.getProductName(), stockMoveLine.getStockMove().getStockMoveSeq()), nf.format(spreadQty), nf.format(expectedQty));
            errorMessageList.add(errorMessage);
        }
    }
}
Also used : Locale(java.util.Locale) StockMoveLine(com.axelor.apps.stock.db.StockMoveLine) BigDecimal(java.math.BigDecimal) NumberFormat(java.text.NumberFormat)

Aggregations

StockMoveLine (com.axelor.apps.stock.db.StockMoveLine)121 BigDecimal (java.math.BigDecimal)59 StockMove (com.axelor.apps.stock.db.StockMove)44 AxelorException (com.axelor.exception.AxelorException)41 Product (com.axelor.apps.base.db.Product)33 Transactional (com.google.inject.persist.Transactional)31 ArrayList (java.util.ArrayList)28 List (java.util.List)18 Company (com.axelor.apps.base.db.Company)16 StockMoveRepository (com.axelor.apps.stock.db.repo.StockMoveRepository)16 StockLocation (com.axelor.apps.stock.db.StockLocation)14 StockMoveLineService (com.axelor.apps.stock.service.StockMoveLineService)14 Unit (com.axelor.apps.base.db.Unit)13 Beans (com.axelor.inject.Beans)13 ProdProduct (com.axelor.apps.production.db.ProdProduct)12 StockMoveService (com.axelor.apps.stock.service.StockMoveService)12 I18n (com.axelor.i18n.I18n)12 Inject (com.google.inject.Inject)12 AppBaseService (com.axelor.apps.base.service.app.AppBaseService)10 SaleOrderLine (com.axelor.apps.sale.db.SaleOrderLine)10