Search in sources :

Example 11 with StockLocation

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

the class InventoryController method setInventorySequence.

public void setInventorySequence(ActionRequest request, ActionResponse response) {
    try {
        Inventory inventory = request.getContext().asType(Inventory.class);
        SequenceService sequenceService = Beans.get(SequenceService.class);
        if (sequenceService.isEmptyOrDraftSequenceNumber(inventory.getInventorySeq())) {
            StockLocation stockLocation = inventory.getStockLocation();
            response.setValue("inventorySeq", Beans.get(InventoryService.class).getInventorySequence(stockLocation.getCompany()));
        }
    } catch (Exception e) {
        TraceBackService.trace(response, e);
    }
}
Also used : StockLocation(com.axelor.apps.stock.db.StockLocation) SequenceService(com.axelor.apps.base.service.administration.SequenceService) Inventory(com.axelor.apps.stock.db.Inventory) BirtException(org.eclipse.birt.core.exception.BirtException) NoResultException(javax.persistence.NoResultException) AxelorException(com.axelor.exception.AxelorException) IOException(java.io.IOException)

Example 12 with StockLocation

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

the class StockRulesServiceImpl method generatePurchaseOrder.

@Override
@Transactional(rollbackOn = { Exception.class })
public void generatePurchaseOrder(Product product, BigDecimal qty, StockLocationLine stockLocationLine, int type) throws AxelorException {
    StockLocation stockLocation = stockLocationLine.getStockLocation();
    // TODO à supprimer après suppression des variantes
    if (stockLocation == null) {
        return;
    }
    StockRules stockRules = this.getStockRules(product, stockLocation, type, StockRulesRepository.USE_CASE_STOCK_CONTROL);
    if (stockRules == null) {
        return;
    }
    if (this.useMinStockRules(stockLocationLine, stockRules, qty, type)) {
        if (stockRules.getOrderAlertSelect() == StockRulesRepository.ORDER_ALERT_ALERT) {
        // TODO
        }
    }
}
Also used : StockLocation(com.axelor.apps.stock.db.StockLocation) StockRules(com.axelor.apps.stock.db.StockRules) Transactional(com.google.inject.persist.Transactional)

Example 13 with StockLocation

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

the class OperationOrderStockMoveService method _createToConsumeStockMove.

protected StockMove _createToConsumeStockMove(OperationOrder operationOrder, Company company) throws AxelorException {
    StockConfigProductionService stockConfigService = Beans.get(StockConfigProductionService.class);
    StockConfig stockConfig = stockConfigService.getStockConfig(company);
    StockLocation virtualStockLocation = stockConfigService.getProductionVirtualStockLocation(stockConfig, operationOrder.getManufOrder().getProdProcess().getOutsourcing());
    StockLocation fromStockLocation;
    ProdProcessLine prodProcessLine = operationOrder.getProdProcessLine();
    if (operationOrder.getManufOrder().getIsConsProOnOperation() && prodProcessLine != null && prodProcessLine.getStockLocation() != null) {
        fromStockLocation = prodProcessLine.getStockLocation();
    } else if (!operationOrder.getManufOrder().getIsConsProOnOperation() && prodProcessLine != null && prodProcessLine.getProdProcess() != null && prodProcessLine.getProdProcess().getStockLocation() != null) {
        fromStockLocation = prodProcessLine.getProdProcess().getStockLocation();
    } else {
        fromStockLocation = stockConfigService.getComponentDefaultStockLocation(stockConfig);
    }
    return stockMoveService.createStockMove(null, null, company, fromStockLocation, virtualStockLocation, null, operationOrder.getPlannedStartDateT().toLocalDate(), null, StockMoveRepository.TYPE_INTERNAL);
}
Also used : StockConfig(com.axelor.apps.stock.db.StockConfig) StockLocation(com.axelor.apps.stock.db.StockLocation) StockConfigProductionService(com.axelor.apps.production.service.config.StockConfigProductionService) ProdProcessLine(com.axelor.apps.production.db.ProdProcessLine)

Example 14 with StockLocation

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

the class ManufOrderServiceImpl method getBuildingQtyForAProduct.

@Override
public String getBuildingQtyForAProduct(Long productId, Long companyId, Long stockLocationId) {
    List<Integer> statusList = getMOFiltersOnProductionConfig();
    String statusListQuery = statusList.stream().map(String::valueOf).collect(Collectors.joining(","));
    String query = "self.product.id = " + productId + " AND self.stockMove.statusSelect = " + StockMoveRepository.STATUS_PLANNED + " AND self.stockMove.toStockLocation.typeSelect != " + StockLocationRepository.TYPE_VIRTUAL + " AND self.producedManufOrder IS NOT NULL " + " AND self.producedManufOrder.statusSelect IN ( " + statusListQuery + " )";
    if (companyId != 0L) {
        query += "AND self.stockMove.company.id = " + companyId;
        if (stockLocationId != 0L) {
            StockLocation stockLocation = Beans.get(StockLocationRepository.class).find(stockLocationId);
            List<StockLocation> stockLocationList = Beans.get(StockLocationService.class).getAllLocationAndSubLocation(stockLocation, false);
            if (!stockLocationList.isEmpty() && stockLocation.getCompany().getId().equals(companyId)) {
                query += " AND self.stockMove.toStockLocation.id IN (" + StringTool.getIdListString(stockLocationList) + ") ";
            }
        }
    }
    return query;
}
Also used : StockLocationService(com.axelor.apps.stock.service.StockLocationService) StockLocation(com.axelor.apps.stock.db.StockLocation) StockLocationRepository(com.axelor.apps.stock.db.repo.StockLocationRepository)

Example 15 with StockLocation

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

the class ReservedQtyServiceImpl method allocateReservedQuantityInSaleOrderLines.

/**
 * The new parameter allocated stock move line is used if we are allocating a stock move line.
 * This method will reallocate the lines with the same stock move (and the same product) before
 * other stock move lines.
 *
 * <p>We are using an optional because in the basic use of the method, the argument is empty.
 */
protected BigDecimal allocateReservedQuantityInSaleOrderLines(BigDecimal qtyToAllocate, StockLocation stockLocation, Product product, Unit stockLocationLineUnit, Optional<StockMoveLine> allocatedStockMoveLine) throws AxelorException {
    List<StockMoveLine> stockMoveLineListToAllocate = stockMoveLineRepository.all().filter("self.stockMove.fromStockLocation.id = :stockLocationId " + "AND self.product.id = :productId " + "AND self.stockMove.statusSelect = :planned " + "AND self.reservationDateTime IS NOT NULL " + "AND self.reservedQty < self.requestedReservedQty").bind("stockLocationId", stockLocation.getId()).bind("productId", product.getId()).bind("planned", StockMoveRepository.STATUS_PLANNED).order("reservationDateTime").order("stockMove.estimatedDate").fetch();
    // put stock move lines with the same stock move on the beginning of the list.
    allocatedStockMoveLine.ifPresent(stockMoveLine -> stockMoveLineListToAllocate.sort(// Note: this comparator imposes orderings that are inconsistent with equals.
    (sml1, sml2) -> {
        if (sml1.getStockMove().equals(sml2.getStockMove())) {
            return 0;
        } else if (sml1.getStockMove().equals(stockMoveLine.getStockMove())) {
            return -1;
        } else if (sml2.getStockMove().equals(stockMoveLine.getStockMove())) {
            return 1;
        } else {
            return 0;
        }
    }));
    BigDecimal leftQtyToAllocate = qtyToAllocate;
    for (StockMoveLine stockMoveLine : stockMoveLineListToAllocate) {
        BigDecimal leftQtyToAllocateStockMove = convertUnitWithProduct(stockLocationLineUnit, stockMoveLine.getUnit(), leftQtyToAllocate, product);
        BigDecimal neededQtyToAllocate = stockMoveLine.getRequestedReservedQty().subtract(stockMoveLine.getReservedQty());
        BigDecimal allocatedStockMoveQty = leftQtyToAllocateStockMove.min(neededQtyToAllocate);
        BigDecimal allocatedQty = convertUnitWithProduct(stockMoveLine.getUnit(), stockLocationLineUnit, allocatedStockMoveQty, product);
        // update reserved qty in stock move line and sale order line
        updateReservedQuantityFromStockMoveLine(stockMoveLine, product, allocatedStockMoveQty);
        // update left qty to allocate
        leftQtyToAllocate = leftQtyToAllocate.subtract(allocatedQty);
    }
    return qtyToAllocate.subtract(leftQtyToAllocate);
}
Also used : Company(com.axelor.apps.base.db.Company) StockLocationRepository(com.axelor.apps.stock.db.repo.StockLocationRepository) StockMoveLineRepository(com.axelor.apps.stock.db.repo.StockMoveLineRepository) IExceptionMessage(com.axelor.apps.supplychain.exception.IExceptionMessage) Inject(com.google.inject.Inject) Transactional(com.google.inject.persist.Transactional) BigDecimal(java.math.BigDecimal) AxelorException(com.axelor.exception.AxelorException) UnitConversionService(com.axelor.apps.base.service.UnitConversionService) StockLocation(com.axelor.apps.stock.db.StockLocation) CancelReason(com.axelor.apps.base.db.CancelReason) I18n(com.axelor.i18n.I18n) StockLocationLineService(com.axelor.apps.stock.service.StockLocationLineService) TraceBackRepository(com.axelor.exception.db.repo.TraceBackRepository) StockMove(com.axelor.apps.stock.db.StockMove) StockMoveRepository(com.axelor.apps.stock.db.repo.StockMoveRepository) AppBaseService(com.axelor.apps.base.service.app.AppBaseService) Collectors(java.util.stream.Collectors) SupplyChainConfig(com.axelor.apps.supplychain.db.SupplyChainConfig) Objects(java.util.Objects) StockMoveLine(com.axelor.apps.stock.db.StockMoveLine) List(java.util.List) SaleOrderLine(com.axelor.apps.sale.db.SaleOrderLine) StockLocationLine(com.axelor.apps.stock.db.StockLocationLine) Beans(com.axelor.inject.Beans) Product(com.axelor.apps.base.db.Product) Unit(com.axelor.apps.base.db.Unit) Optional(java.util.Optional) AppSupplychainService(com.axelor.apps.supplychain.service.app.AppSupplychainService) Comparator(java.util.Comparator) SupplyChainConfigService(com.axelor.apps.supplychain.service.config.SupplyChainConfigService) StockMoveLine(com.axelor.apps.stock.db.StockMoveLine) BigDecimal(java.math.BigDecimal)

Aggregations

StockLocation (com.axelor.apps.stock.db.StockLocation)56 Company (com.axelor.apps.base.db.Company)19 BigDecimal (java.math.BigDecimal)18 Product (com.axelor.apps.base.db.Product)15 AxelorException (com.axelor.exception.AxelorException)13 Transactional (com.google.inject.persist.Transactional)13 StockMove (com.axelor.apps.stock.db.StockMove)12 StockLocationRepository (com.axelor.apps.stock.db.repo.StockLocationRepository)12 ArrayList (java.util.ArrayList)12 StockConfig (com.axelor.apps.stock.db.StockConfig)10 StockConfigProductionService (com.axelor.apps.production.service.config.StockConfigProductionService)9 StockMoveLine (com.axelor.apps.stock.db.StockMoveLine)8 StockLocationService (com.axelor.apps.stock.service.StockLocationService)8 List (java.util.List)8 Partner (com.axelor.apps.base.db.Partner)6 Unit (com.axelor.apps.base.db.Unit)6 StockLocationLine (com.axelor.apps.stock.db.StockLocationLine)6 LocalDate (java.time.LocalDate)6 UnitConversionService (com.axelor.apps.base.service.UnitConversionService)5 AppBaseService (com.axelor.apps.base.service.app.AppBaseService)5