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);
}
}
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
}
}
}
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);
}
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;
}
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);
}
Aggregations