use of com.axelor.apps.stock.db.StockMove in project axelor-open-suite by axelor.
the class ManufOrderStockMoveService method createToProduceStockMove.
public void createToProduceStockMove(ManufOrder manufOrder) throws AxelorException {
Company company = manufOrder.getCompany();
if (manufOrder.getToProduceProdProductList() != null && company != null) {
StockMove stockMove = this._createToProduceStockMove(manufOrder, company);
for (ProdProduct prodProduct : manufOrder.getToProduceProdProductList()) {
BigDecimal productCostPrice = prodProduct.getProduct() != null ? (BigDecimal) productCompanyService.get(prodProduct.getProduct(), "costPrice", manufOrder.getCompany()) : BigDecimal.ZERO;
this._createStockMoveLine(prodProduct, stockMove, StockMoveLineService.TYPE_OUT_PRODUCTIONS, prodProduct.getQty(), productCostPrice);
}
if (stockMove.getStockMoveLineList() != null && !stockMove.getStockMoveLineList().isEmpty()) {
stockMoveService.plan(stockMove);
manufOrder.addOutStockMoveListItem(stockMove);
}
if (stockMove.getStockMoveLineList() != null) {
for (StockMoveLine stockMoveLine : stockMove.getStockMoveLineList()) {
manufOrder.addProducedStockMoveLineListItem(stockMoveLine);
}
}
}
}
use of com.axelor.apps.stock.db.StockMove in project axelor-open-suite by axelor.
the class ManufOrderStockMoveService method createToConsumeStockMove.
public void createToConsumeStockMove(ManufOrder manufOrder) throws AxelorException {
Company company = manufOrder.getCompany();
SupplyChainConfig supplyChainConfig = supplyChainConfigService.getSupplyChainConfig(company);
if (manufOrder.getToConsumeProdProductList() != null && company != null) {
StockMove stockMove = this._createToConsumeStockMove(manufOrder, company);
for (ProdProduct prodProduct : manufOrder.getToConsumeProdProductList()) {
this._createStockMoveLine(prodProduct, stockMove, StockMoveLineService.TYPE_IN_PRODUCTIONS);
}
if (stockMove.getStockMoveLineList() != null && !stockMove.getStockMoveLineList().isEmpty()) {
stockMoveService.plan(stockMove);
if (supplyChainConfig.getAutoRequestReservedQtyOnManufOrder()) {
requestStockReservation(stockMove);
}
manufOrder.addInStockMoveListItem(stockMove);
}
// case where we had to split tracked stock move lines
if (stockMove.getStockMoveLineList() != null) {
for (StockMoveLine stockMoveLine : stockMove.getStockMoveLineList()) {
manufOrder.addConsumedStockMoveLineListItem(stockMoveLine);
}
}
}
}
use of com.axelor.apps.stock.db.StockMove 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.stock.db.StockMove 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);
}
use of com.axelor.apps.stock.db.StockMove in project axelor-open-suite by axelor.
the class CostSheetServiceImpl method getTotalQtyPerProductAndUnit.
protected Map<List<Object>, BigDecimal> getTotalQtyPerProductAndUnit(List<StockMoveLine> stockMoveLineList, LocalDate calculationDate, LocalDate previousCostSheetDate, int calculationType) {
Map<List<Object>, BigDecimal> stockMoveLinePerProductAndUnitMap = new HashMap<>();
if (stockMoveLineList == null) {
return stockMoveLinePerProductAndUnitMap;
}
for (StockMoveLine stockMoveLine : stockMoveLineList) {
StockMove stockMove = stockMoveLine.getStockMove();
if (stockMove == null || StockMoveRepository.STATUS_REALIZED != stockMoveLine.getStockMove().getStatusSelect()) {
continue;
}
if ((calculationType == CostSheetRepository.CALCULATION_PARTIAL_END_OF_PRODUCTION || calculationType == CostSheetRepository.CALCULATION_END_OF_PRODUCTION) && previousCostSheetDate != null && !previousCostSheetDate.isBefore(stockMove.getRealDate())) {
continue;
} else if (calculationType == CostSheetRepository.CALCULATION_WORK_IN_PROGRESS && calculationDate.isBefore(stockMove.getRealDate())) {
continue;
}
Product productKey = stockMoveLine.getProduct();
Unit unitKey = stockMoveLine.getUnit();
List<Object> keys = new ArrayList<Object>();
keys.add(productKey);
keys.add(unitKey);
BigDecimal qty = stockMoveLinePerProductAndUnitMap.get(keys);
if (qty == null) {
qty = BigDecimal.ZERO;
}
stockMoveLinePerProductAndUnitMap.put(keys, qty.add(stockMoveLine.getRealQty()));
}
return stockMoveLinePerProductAndUnitMap;
}
Aggregations