use of com.axelor.apps.stock.service.StockMoveLineService in project axelor-open-suite by axelor.
the class ManufOrderServiceImpl method generateWasteStockMove.
@Override
@Transactional(rollbackOn = { Exception.class })
public StockMove generateWasteStockMove(ManufOrder manufOrder) throws AxelorException {
StockMove wasteStockMove = null;
Company company = manufOrder.getCompany();
if (manufOrder.getWasteProdProductList() == null || company == null || manufOrder.getWasteProdProductList().isEmpty()) {
return wasteStockMove;
}
StockConfigProductionService stockConfigService = Beans.get(StockConfigProductionService.class);
StockMoveService stockMoveService = Beans.get(StockMoveService.class);
StockMoveLineService stockMoveLineService = Beans.get(StockMoveLineService.class);
AppBaseService appBaseService = Beans.get(AppBaseService.class);
StockConfig stockConfig = stockConfigService.getStockConfig(company);
StockLocation virtualStockLocation = stockConfigService.getProductionVirtualStockLocation(stockConfig, false);
StockLocation wasteStockLocation = stockConfigService.getWasteStockLocation(stockConfig);
wasteStockMove = stockMoveService.createStockMove(virtualStockLocation.getAddress(), wasteStockLocation.getAddress(), company, virtualStockLocation, wasteStockLocation, null, appBaseService.getTodayDate(company), manufOrder.getWasteProdDescription(), StockMoveRepository.TYPE_INTERNAL);
for (ProdProduct prodProduct : manufOrder.getWasteProdProductList()) {
stockMoveLineService.createStockMoveLine(prodProduct.getProduct(), (String) productCompanyService.get(prodProduct.getProduct(), "name", company), (String) productCompanyService.get(prodProduct.getProduct(), "description", company), prodProduct.getQty(), (BigDecimal) productCompanyService.get(prodProduct.getProduct(), "costPrice", company), (BigDecimal) productCompanyService.get(prodProduct.getProduct(), "costPrice", company), prodProduct.getUnit(), wasteStockMove, StockMoveLineService.TYPE_WASTE_PRODUCTIONS, false, BigDecimal.ZERO);
}
stockMoveService.validate(wasteStockMove);
manufOrder.setWasteStockMove(wasteStockMove);
return wasteStockMove;
}
Aggregations