use of com.axelor.apps.stock.db.StockLocation in project axelor-open-suite by axelor.
the class ManufOrderServiceImpl method getConsumeAndMissingQtyForAProduct.
@Override
public String getConsumeAndMissingQtyForAProduct(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.fromStockLocation.typeSelect != " + StockLocationRepository.TYPE_VIRTUAL + " AND ( (self.consumedManufOrder IS NOT NULL AND self.consumedManufOrder.statusSelect IN (" + statusListQuery + "))" + " OR (self.consumedOperationOrder IS NOT NULL AND self.consumedOperationOrder.statusSelect IN ( " + statusListQuery + ") ) ) ";
if (companyId != 0L) {
query += " AND self.stockMove.company.id = " + companyId;
if (stockLocationId != 0L) {
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.fromStockLocation.id IN (" + StringTool.getIdListString(stockLocationList) + ") ";
}
}
}
}
return query;
}
use of com.axelor.apps.stock.db.StockLocation in project axelor-open-suite by axelor.
the class ManufOrderServiceImpl method canMerge.
public boolean canMerge(List<Long> ids) {
List<ManufOrder> manufOrderList = manufOrderRepo.all().filter("self.id in (" + Joiner.on(",").join(ids) + ")").fetch();
// I check if all the status of the manuf order in the list are Draft or
// Planned. If not i can return false
boolean allStatusDraftOrPlanned = manufOrderList.stream().allMatch(x -> x.getStatusSelect().equals(ManufOrderRepository.STATUS_DRAFT) || x.getStatusSelect().equals(ManufOrderRepository.STATUS_PLANNED));
if (!allStatusDraftOrPlanned) {
return false;
}
// I check if all the products are the same. If not i return false
Product product = manufOrderList.get(0).getProduct();
boolean allSameProducts = manufOrderList.stream().allMatch(x -> x.getProduct().equals(product));
if (!allSameProducts) {
return false;
}
// Workshop management must be enabled to do the checking
if (appProductionService.getAppProduction().getManageWorkshop()) {
// Check if one of the workShopStockLocation is null
boolean oneWorkShopIsNull = manufOrderList.stream().anyMatch(x -> x.getWorkshopStockLocation() == null);
if (oneWorkShopIsNull) {
return false;
}
// I check if all the stockLocation are the same. If not i return false
StockLocation stockLocation = manufOrderList.get(0).getWorkshopStockLocation();
boolean allSameLocation = manufOrderList.stream().allMatch(x -> x.getWorkshopStockLocation() != null && x.getWorkshopStockLocation().equals(stockLocation));
if (!allSameLocation) {
return false;
}
}
// Check if one of the billOfMaterial is null
boolean oneBillOfMaterialIsNull = manufOrderList.stream().anyMatch(x -> x.getBillOfMaterial() == null);
if (oneBillOfMaterialIsNull) {
return false;
}
// Check if one of the billOfMaterial has his version equal to 1
boolean oneBillOfMaterialWithFirstVersion = manufOrderList.stream().anyMatch(x -> x.getBillOfMaterial().getVersionNumber() == 1);
if (!oneBillOfMaterialWithFirstVersion) {
return false;
}
// I check if all the billOfMaterial are the same. If not i will check
// if all version are compatible, and if not i can return false
BillOfMaterial billOfMaterial = manufOrderList.stream().filter(x -> x.getBillOfMaterial().getVersionNumber() == 1).findFirst().get().getBillOfMaterial();
boolean allSameOrCompatibleBillOfMaterial = manufOrderList.stream().allMatch(x -> x.getBillOfMaterial().equals(billOfMaterial) || billOfMaterial.equals(x.getBillOfMaterial().getOriginalBillOfMaterial()));
if (!allSameOrCompatibleBillOfMaterial) {
return false;
}
return true;
}
use of com.axelor.apps.stock.db.StockLocation in project axelor-open-suite by axelor.
the class ManufOrderStockMoveService method partialFinish.
/**
* Allows to create and realize in or out stock moves for the given manufacturing order.
*
* @param manufOrder
* @param inOrOut can be {@link ManufOrderStockMoveService#PART_FINISH_IN} or {@link
* ManufOrderStockMoveService#PART_FINISH_OUT}
* @throws AxelorException
*/
protected void partialFinish(ManufOrder manufOrder, int inOrOut) throws AxelorException {
if (inOrOut != PART_FINISH_IN && inOrOut != PART_FINISH_OUT) {
throw new IllegalArgumentException(I18n.get(IExceptionMessage.IN_OR_OUT_INVALID_ARG));
}
Company company = manufOrder.getCompany();
StockConfigProductionService stockConfigService = Beans.get(StockConfigProductionService.class);
StockConfig stockConfig = stockConfigService.getStockConfig(company);
StockLocation fromStockLocation;
StockLocation toStockLocation;
List<StockMove> stockMoveList;
if (inOrOut == PART_FINISH_IN) {
stockMoveList = manufOrder.getInStockMoveList();
fromStockLocation = getDefaultStockLocation(manufOrder, company, STOCK_LOCATION_IN);
toStockLocation = stockConfigService.getProductionVirtualStockLocation(stockConfig, manufOrder.getProdProcess().getOutsourcing());
} else {
stockMoveList = manufOrder.getOutStockMoveList();
fromStockLocation = stockConfigService.getProductionVirtualStockLocation(stockConfig, manufOrder.getProdProcess().getOutsourcing());
toStockLocation = getDefaultStockLocation(manufOrder, company, STOCK_LOCATION_OUT);
}
// realize current stock move and update the price
Optional<StockMove> stockMoveToRealize = getPlannedStockMove(stockMoveList);
if (stockMoveToRealize.isPresent()) {
updateRealPrice(manufOrder, stockMoveToRealize.get());
finishStockMove(stockMoveToRealize.get());
}
// generate new stock move
StockMove newStockMove = stockMoveService.createStockMove(null, null, company, fromStockLocation, toStockLocation, null, manufOrder.getPlannedStartDateT().toLocalDate(), null, StockMoveRepository.TYPE_INTERNAL);
newStockMove.setStockMoveLineList(new ArrayList<>());
newStockMove.setOrigin(manufOrder.getManufOrderSeq());
newStockMove.setOriginId(manufOrder.getId());
newStockMove.setOriginTypeSelect(StockMoveRepository.ORIGIN_MANUF_ORDER);
createNewStockMoveLines(manufOrder, newStockMove, inOrOut);
if (!newStockMove.getStockMoveLineList().isEmpty()) {
// plan the stockmove
stockMoveService.plan(newStockMove);
if (inOrOut == PART_FINISH_IN) {
manufOrder.addInStockMoveListItem(newStockMove);
newStockMove.getStockMoveLineList().forEach(manufOrder::addConsumedStockMoveLineListItem);
manufOrder.clearDiffConsumeProdProductList();
} else {
manufOrder.addOutStockMoveListItem(newStockMove);
newStockMove.getStockMoveLineList().forEach(manufOrder::addProducedStockMoveLineListItem);
}
}
}
use of com.axelor.apps.stock.db.StockLocation in project axelor-open-suite by axelor.
the class ManufOrderStockMoveService method getDefaultStockLocation.
/**
* Given a manuf order, its company and whether we want to create a in or out stock move,
* determine the default stock location and return it. First search in prodprocess, then in
* company stock configuration.
*
* @param manufOrder a manufacturing order.
* @param company a company with stock config.
* @param inOrOut can be {@link ManufOrderStockMoveService#STOCK_LOCATION_IN} or {@link
* ManufOrderStockMoveService#STOCK_LOCATION_OUT}.
* @return the found stock location, which can be null.
* @throws AxelorException if the stock config is missing for the company.
*/
public StockLocation getDefaultStockLocation(ManufOrder manufOrder, Company company, int inOrOut) throws AxelorException {
if (inOrOut != STOCK_LOCATION_IN && inOrOut != STOCK_LOCATION_OUT) {
throw new IllegalArgumentException(I18n.get(IExceptionMessage.IN_OR_OUT_INVALID_ARG));
}
StockConfigProductionService stockConfigService = Beans.get(StockConfigProductionService.class);
StockConfig stockConfig = stockConfigService.getStockConfig(company);
StockLocation stockLocation = getDefaultStockLocation(manufOrder.getProdProcess(), inOrOut);
if (stockLocation == null) {
stockLocation = inOrOut == STOCK_LOCATION_IN ? stockConfigService.getComponentDefaultStockLocation(stockConfig) : stockConfigService.getFinishedProductsDefaultStockLocation(stockConfig);
}
return stockLocation;
}
use of com.axelor.apps.stock.db.StockLocation in project axelor-open-suite by axelor.
the class ManufOrderStockMoveService method _createToProduceStockMove.
protected StockMove _createToProduceStockMove(ManufOrder manufOrder, Company company) throws AxelorException {
StockConfigProductionService stockConfigService = Beans.get(StockConfigProductionService.class);
StockConfig stockConfig = stockConfigService.getStockConfig(company);
StockLocation virtualStockLocation = stockConfigService.getProductionVirtualStockLocation(stockConfig, manufOrder.getProdProcess().getOutsourcing());
LocalDateTime plannedEndDateT = manufOrder.getPlannedEndDateT();
LocalDate plannedEndDate = plannedEndDateT != null ? plannedEndDateT.toLocalDate() : null;
StockLocation producedProductStockLocation = manufOrder.getProdProcess().getProducedProductStockLocation();
if (producedProductStockLocation == null) {
producedProductStockLocation = stockConfigService.getFinishedProductsDefaultStockLocation(stockConfig);
}
StockMove stockMove = stockMoveService.createStockMove(null, null, company, virtualStockLocation, producedProductStockLocation, null, plannedEndDate, null, StockMoveRepository.TYPE_INTERNAL);
stockMove.setOriginId(manufOrder.getId());
stockMove.setOriginTypeSelect(StockMoveRepository.ORIGIN_MANUF_ORDER);
stockMove.setOrigin(manufOrder.getManufOrderSeq());
return stockMove;
}
Aggregations