use of com.axelor.apps.stock.db.StockMove in project axelor-open-suite by axelor.
the class ManufOrderServiceImpl method updateStockMoveFromManufOrder.
@Override
public void updateStockMoveFromManufOrder(List<StockMoveLine> stockMoveLineList, StockMove stockMove) throws AxelorException {
if (stockMoveLineList == null) {
return;
}
// add missing lines in stock move
stockMoveLineList.stream().filter(stockMoveLine -> stockMoveLine.getStockMove() == null).forEach(stockMove::addStockMoveLineListItem);
// remove lines in stock move removed in manuf order
if (stockMove.getStockMoveLineList() != null) {
stockMove.getStockMoveLineList().removeIf(stockMoveLine -> !stockMoveLineList.contains(stockMoveLine));
}
StockMoveService stockMoveService = Beans.get(StockMoveService.class);
// update stock location by cancelling then planning stock move.
stockMoveService.cancel(stockMove);
stockMoveService.plan(stockMove);
}
use of com.axelor.apps.stock.db.StockMove 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.StockMove 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;
}
use of com.axelor.apps.stock.db.StockMove in project axelor-open-suite by axelor.
the class ManufOrderStockMoveService method createNewProducedStockMoveLineList.
/**
* Clear the produced list and create a new one with the right quantity.
*
* @param manufOrder
* @param qtyToUpdate
*/
public void createNewProducedStockMoveLineList(ManufOrder manufOrder, BigDecimal qtyToUpdate) throws AxelorException {
Optional<StockMove> stockMoveOpt = getPlannedStockMove(manufOrder.getOutStockMoveList());
if (!stockMoveOpt.isPresent()) {
return;
}
StockMove stockMove = stockMoveOpt.get();
stockMoveService.cancel(stockMove);
// clear all lists
manufOrder.getProducedStockMoveLineList().removeIf(stockMoveLine -> stockMoveLine.getStockMove().getStatusSelect() == StockMoveRepository.STATUS_CANCELED);
stockMove.clearStockMoveLineList();
// create a new list
for (ProdProduct prodProduct : manufOrder.getToProduceProdProductList()) {
BigDecimal qty = getFractionQty(manufOrder, prodProduct, qtyToUpdate);
BigDecimal productCostPrice = prodProduct.getProduct() != null ? (BigDecimal) productCompanyService.get(prodProduct.getProduct(), "costPrice", manufOrder.getCompany()) : BigDecimal.ZERO;
_createStockMoveLine(prodProduct, stockMove, StockMoveLineService.TYPE_OUT_PRODUCTIONS, qty, productCostPrice);
// Update produced StockMoveLineList with created stock move lines
stockMove.getStockMoveLineList().stream().filter(stockMoveLine1 -> !manufOrder.getProducedStockMoveLineList().contains(stockMoveLine1)).forEach(manufOrder::addProducedStockMoveLineListItem);
}
stockMoveService.plan(stockMove);
}
use of com.axelor.apps.stock.db.StockMove in project axelor-open-suite by axelor.
the class ManufOrderStockMoveService method _createToConsumeStockMove.
public StockMove _createToConsumeStockMove(ManufOrder manufOrder, Company company) throws AxelorException {
StockConfigProductionService stockConfigService = Beans.get(StockConfigProductionService.class);
StockConfig stockConfig = stockConfigService.getStockConfig(company);
StockLocation virtualStockLocation = manufOrder.getOutsourcing() ? manufOrder.getProdProcess().getProducedProductStockLocation() : stockConfigService.getProductionVirtualStockLocation(stockConfig, manufOrder.getProdProcess().getOutsourcing());
StockLocation fromStockLocation = manufOrder.getOutsourcing() ? company.getStockConfig().getOutsourcingReceiptStockLocation() : getDefaultStockLocation(manufOrder, company, STOCK_LOCATION_IN);
StockMove stockMove = stockMoveService.createStockMove(null, null, company, fromStockLocation, virtualStockLocation, null, manufOrder.getPlannedStartDateT().toLocalDate(), null, StockMoveRepository.TYPE_INTERNAL);
stockMove.setOriginId(manufOrder.getId());
stockMove.setOriginTypeSelect(StockMoveRepository.ORIGIN_MANUF_ORDER);
stockMove.setOrigin(manufOrder.getManufOrderSeq());
return stockMove;
}
Aggregations