use of com.axelor.apps.stock.db.StockMove in project axelor-open-suite by axelor.
the class OperationOrderServiceImpl method updateConsumedStockMoveFromOperationOrder.
@Override
@Transactional(rollbackOn = { Exception.class })
public void updateConsumedStockMoveFromOperationOrder(OperationOrder operationOrder) throws AxelorException {
this.updateDiffProdProductList(operationOrder);
List<StockMoveLine> consumedStockMoveLineList = operationOrder.getConsumedStockMoveLineList();
if (consumedStockMoveLineList == null) {
return;
}
Optional<StockMove> stockMoveOpt = operationOrder.getInStockMoveList().stream().filter(stockMove -> stockMove.getStatusSelect() == StockMoveRepository.STATUS_PLANNED).findFirst();
StockMove stockMove;
if (stockMoveOpt.isPresent()) {
stockMove = stockMoveOpt.get();
} else {
stockMove = Beans.get(ManufOrderStockMoveService.class)._createToConsumeStockMove(operationOrder.getManufOrder(), operationOrder.getManufOrder().getCompany());
operationOrder.addInStockMoveListItem(stockMove);
Beans.get(StockMoveService.class).plan(stockMove);
}
Beans.get(ManufOrderService.class).updateStockMoveFromManufOrder(consumedStockMoveLineList, stockMove);
}
use of com.axelor.apps.stock.db.StockMove in project axelor-open-suite by axelor.
the class OperationOrderStockMoveService method createToConsumeStockMove.
public void createToConsumeStockMove(OperationOrder operationOrder) throws AxelorException {
Company company = operationOrder.getManufOrder().getCompany();
if (operationOrder.getToConsumeProdProductList() != null && company != null) {
StockMove stockMove = this._createToConsumeStockMove(operationOrder, company);
stockMove.setOriginId(operationOrder.getId());
stockMove.setOriginTypeSelect(StockMoveRepository.ORIGIN_OPERATION_ORDER);
stockMove.setOrigin(operationOrder.getOperationName());
for (ProdProduct prodProduct : operationOrder.getToConsumeProdProductList()) {
StockMoveLine stockMoveLine = this._createStockMoveLine(prodProduct, stockMove);
}
if (stockMove.getStockMoveLineList() != null && !stockMove.getStockMoveLineList().isEmpty()) {
stockMoveService.plan(stockMove);
operationOrder.addInStockMoveListItem(stockMove);
}
// case where we had to split tracked stock move lines
if (stockMove.getStockMoveLineList() != null) {
for (StockMoveLine stockMoveLine : stockMove.getStockMoveLineList()) {
operationOrder.addConsumedStockMoveLineListItem(stockMoveLine);
}
}
}
}
use of com.axelor.apps.stock.db.StockMove in project axelor-open-suite by axelor.
the class OperationOrderWorkflowService method start.
/**
* Starts the given {@link OperationOrder} and sets its starting time
*
* @param operationOrder An operation order
*/
@Transactional(rollbackOn = { Exception.class })
public void start(OperationOrder operationOrder) throws AxelorException {
if (operationOrder.getStatusSelect() != OperationOrderRepository.STATUS_IN_PROGRESS) {
operationOrder.setStatusSelect(OperationOrderRepository.STATUS_IN_PROGRESS);
operationOrder.setRealStartDateT(appProductionService.getTodayDateTime().toLocalDateTime());
startOperationOrderDuration(operationOrder);
if (operationOrder.getManufOrder() != null) {
int beforeOrAfterConfig = operationOrder.getManufOrder().getProdProcess().getStockMoveRealizeOrderSelect();
if (beforeOrAfterConfig == ProductionConfigRepository.REALIZE_START) {
for (StockMove stockMove : operationOrder.getInStockMoveList()) {
Beans.get(ManufOrderStockMoveService.class).finishStockMove(stockMove);
}
StockMove newStockMove = operationOrderStockMoveService._createToConsumeStockMove(operationOrder, operationOrder.getManufOrder().getCompany());
newStockMove.setStockMoveLineList(new ArrayList<>());
Beans.get(StockMoveService.class).plan(newStockMove);
operationOrder.addInStockMoveListItem(newStockMove);
}
}
operationOrderRepo.save(operationOrder);
}
if (operationOrder.getManufOrder().getStatusSelect() != ManufOrderRepository.STATUS_IN_PROGRESS) {
Beans.get(ManufOrderWorkflowService.class).start(operationOrder.getManufOrder());
}
}
use of com.axelor.apps.stock.db.StockMove in project axelor-open-suite by axelor.
the class ManufOrderServiceImpl method updateConsumedStockMoveFromManufOrder.
@Override
@Transactional(rollbackOn = { Exception.class })
public void updateConsumedStockMoveFromManufOrder(ManufOrder manufOrder) throws AxelorException {
this.updateDiffProdProductList(manufOrder);
List<StockMoveLine> consumedStockMoveLineList = manufOrder.getConsumedStockMoveLineList();
if (consumedStockMoveLineList == null) {
return;
}
ManufOrderStockMoveService manufOrderStockMoveService = Beans.get(ManufOrderStockMoveService.class);
Optional<StockMove> stockMoveOpt = manufOrderStockMoveService.getPlannedStockMove(manufOrder.getInStockMoveList());
StockMove stockMove;
if (stockMoveOpt.isPresent()) {
stockMove = stockMoveOpt.get();
} else {
stockMove = manufOrderStockMoveService._createToConsumeStockMove(manufOrder, manufOrder.getCompany());
manufOrder.addInStockMoveListItem(stockMove);
Beans.get(StockMoveService.class).plan(stockMove);
}
updateStockMoveFromManufOrder(consumedStockMoveLineList, stockMove);
}
use of com.axelor.apps.stock.db.StockMove in project axelor-open-suite by axelor.
the class PurchaseOrderStockServiceImpl method createStockMoveFromPurchaseOrder.
/**
* Méthode permettant de créer un StockMove à partir d'un PurchaseOrder.
*
* @param purchaseOrder une commande
* @throws AxelorException Aucune séquence de StockMove n'a été configurée
*/
public List<Long> createStockMoveFromPurchaseOrder(PurchaseOrder purchaseOrder) throws AxelorException {
List<Long> stockMoveIdList = new ArrayList<>();
if (purchaseOrder.getPurchaseOrderLineList() == null || purchaseOrder.getCompany() == null) {
return stockMoveIdList;
}
if (purchaseOrder.getStockLocation() == null) {
throw new AxelorException(purchaseOrder, TraceBackRepository.CATEGORY_CONFIGURATION_ERROR, I18n.get(IExceptionMessage.PO_MISSING_STOCK_LOCATION), purchaseOrder.getPurchaseOrderSeq());
}
Map<LocalDate, List<PurchaseOrderLine>> purchaseOrderLinePerDateMap = getAllPurchaseOrderLinePerDate(purchaseOrder);
for (LocalDate estimatedDeliveryDate : purchaseOrderLinePerDateMap.keySet().stream().filter(x -> x != null).sorted((x, y) -> x.compareTo(y)).collect(Collectors.toList())) {
List<PurchaseOrderLine> purchaseOrderLineList = purchaseOrderLinePerDateMap.get(estimatedDeliveryDate);
List<Long> stockMoveId = createStockMove(purchaseOrder, estimatedDeliveryDate, purchaseOrderLineList);
if (stockMoveId != null && !stockMoveId.isEmpty()) {
stockMoveIdList.addAll(stockMoveId);
}
}
Optional<List<PurchaseOrderLine>> purchaseOrderLineListDeliveryDateNull = Optional.ofNullable(purchaseOrderLinePerDateMap.get(null));
if (purchaseOrderLineListDeliveryDateNull.isPresent()) {
List<Long> stockMoveId = createStockMove(purchaseOrder, null, purchaseOrderLineListDeliveryDateNull.get());
if (stockMoveId != null && !stockMoveId.isEmpty()) {
stockMoveIdList.addAll(stockMoveId);
}
}
return stockMoveIdList;
}
Aggregations