use of com.axelor.apps.production.service.manuforder.ManufOrderStockMoveService in project axelor-open-suite by axelor.
the class StockMoveLineController method compute.
public void compute(ActionRequest request, ActionResponse response) throws AxelorException {
StockMoveLine stockMoveLine = request.getContext().asType(StockMoveLine.class);
Optional<StockMove> stockMove = Optional.ofNullable(stockMoveLine.getStockMove());
if (!stockMove.isPresent()) {
Context parentContext = request.getContext().getParent();
if (parentContext.getContextClass().equals(StockMove.class)) {
stockMove = Optional.ofNullable(parentContext.asType(StockMove.class));
} else if (parentContext.getContextClass().equals(ManufOrder.class)) {
ManufOrder manufOrder = parentContext.asType(ManufOrder.class);
ManufOrderStockMoveService manufOrderStockMoveService = Beans.get(ManufOrderStockMoveService.class);
stockMove = manufOrderStockMoveService.getPlannedStockMove(manufOrder.getInStockMoveList());
}
if (!stockMove.isPresent()) {
return;
}
}
stockMoveLine = Beans.get(StockMoveLineService.class).compute(stockMoveLine, stockMove.get());
response.setValue("companyPurchasePrice", stockMoveLine.getCompanyPurchasePrice());
response.setValue("unitPriceUntaxed", stockMoveLine.getUnitPriceUntaxed());
response.setValue("unitPriceTaxed", stockMoveLine.getUnitPriceTaxed());
}
use of com.axelor.apps.production.service.manuforder.ManufOrderStockMoveService in project axelor-open-suite by axelor.
the class ManufOrderController method consumeStockMove.
/**
* Called from manuf order form on clicking realize button. Call {@link
* ManufOrderStockMoveService#consumeInStockMoves(ManufOrder)} to consume material used in manuf
* order.
*
* @param request
* @param response
*/
public void consumeStockMove(ActionRequest request, ActionResponse response) {
try {
ManufOrder manufOrder = request.getContext().asType(ManufOrder.class);
manufOrder = Beans.get(ManufOrderRepository.class).find(manufOrder.getId());
Beans.get(ManufOrderStockMoveService.class).consumeInStockMoves(manufOrder);
response.setReload(true);
} catch (Exception e) {
TraceBackService.trace(response, e);
}
}
use of com.axelor.apps.production.service.manuforder.ManufOrderStockMoveService in project axelor-open-suite by axelor.
the class OperationOrderStockMoveService method partialFinish.
/**
* Allows to create and realize in stock moves for the given operation order. This method is used
* during a partial finish.
*
* @param operationOrder
* @throws AxelorException
*/
@Transactional(rollbackOn = { Exception.class })
public void partialFinish(OperationOrder operationOrder) throws AxelorException {
ManufOrderStockMoveService manufOrderStockMoveService = Beans.get(ManufOrderStockMoveService.class);
ManufOrder manufOrder = operationOrder.getManufOrder();
Company company = manufOrder.getCompany();
StockConfigProductionService stockConfigService = Beans.get(StockConfigProductionService.class);
StockConfig stockConfig = stockConfigService.getStockConfig(company);
StockLocation fromStockLocation;
StockLocation toStockLocation;
List<StockMove> stockMoveList;
stockMoveList = operationOrder.getInStockMoveList();
fromStockLocation = manufOrderStockMoveService.getDefaultStockLocation(manufOrder, company, ManufOrderStockMoveService.STOCK_LOCATION_IN);
toStockLocation = stockConfigService.getProductionVirtualStockLocation(stockConfig, operationOrder.getManufOrder().getProdProcess().getOutsourcing());
// realize current stock move
Optional<StockMove> stockMoveToRealize = stockMoveList.stream().filter(stockMove -> stockMove.getStatusSelect() == StockMoveRepository.STATUS_PLANNED && !CollectionUtils.isEmpty(stockMove.getStockMoveLineList())).findFirst();
if (stockMoveToRealize.isPresent()) {
manufOrderStockMoveService.finishStockMove(stockMoveToRealize.get());
}
// generate new stock move
StockMove newStockMove = stockMoveService.createStockMove(null, null, company, fromStockLocation, toStockLocation, null, operationOrder.getPlannedStartDateT().toLocalDate(), null, StockMoveRepository.TYPE_INTERNAL);
newStockMove.setOrigin(operationOrder.getOperationName());
newStockMove.setOriginId(operationOrder.getId());
newStockMove.setOriginTypeSelect(StockMoveRepository.ORIGIN_OPERATION_ORDER);
newStockMove.setStockMoveLineList(new ArrayList<>());
createNewStockMoveLines(operationOrder, newStockMove);
if (!newStockMove.getStockMoveLineList().isEmpty()) {
// plan the stockmove
stockMoveService.plan(newStockMove);
operationOrder.addInStockMoveListItem(newStockMove);
newStockMove.getStockMoveLineList().forEach(operationOrder::addConsumedStockMoveLineListItem);
operationOrder.clearDiffConsumeProdProductList();
}
}
use of com.axelor.apps.production.service.manuforder.ManufOrderStockMoveService in project axelor-open-suite by axelor.
the class OperationOrderStockMoveService method createNewConsumedStockMoveLineList.
/**
* Clear the consumed list and create a new one with the right quantity.
*
* @param operationOrder
* @param qtyToUpdate
*/
public void createNewConsumedStockMoveLineList(OperationOrder operationOrder, BigDecimal qtyToUpdate) throws AxelorException {
ManufOrderStockMoveService manufOrderStockMoveService = Beans.get(ManufOrderStockMoveService.class);
// find planned stock move
Optional<StockMove> stockMoveOpt = manufOrderStockMoveService.getPlannedStockMove(operationOrder.getInStockMoveList());
if (!stockMoveOpt.isPresent()) {
return;
}
StockMove stockMove = stockMoveOpt.get();
stockMoveService.cancel(stockMove);
// clear all lists from planned lines
operationOrder.getConsumedStockMoveLineList().removeIf(stockMoveLine -> stockMoveLine.getStockMove().getStatusSelect() == StockMoveRepository.STATUS_CANCELED);
stockMove.clearStockMoveLineList();
// create a new list
for (ProdProduct prodProduct : operationOrder.getToConsumeProdProductList()) {
BigDecimal qty = manufOrderStockMoveService.getFractionQty(operationOrder.getManufOrder(), prodProduct, qtyToUpdate);
manufOrderStockMoveService._createStockMoveLine(prodProduct, stockMove, StockMoveLineService.TYPE_IN_PRODUCTIONS, qty);
// Update consumed StockMoveLineList with created stock move lines
stockMove.getStockMoveLineList().stream().filter(stockMoveLine1 -> !operationOrder.getConsumedStockMoveLineList().contains(stockMoveLine1)).forEach(operationOrder::addConsumedStockMoveLineListItem);
}
stockMoveService.plan(stockMove);
}
Aggregations