use of com.axelor.apps.production.db.ProdProduct in project axelor-open-suite by axelor.
the class ManufOrderController method generateMultiLevelManufOrder.
/**
* Called from multi-level-planing-wizard-form, on clicking "Generate MO" button.
*
* @param request
* @param response
*/
@SuppressWarnings("unchecked")
public void generateMultiLevelManufOrder(ActionRequest request, ActionResponse response) {
try {
Long moId = Long.valueOf(request.getContext().get("id").toString());
ManufOrder mo = Beans.get(ManufOrderRepository.class).find(moId);
ProdProductRepository prodProductRepository = Beans.get(ProdProductRepository.class);
List<ProdProduct> prodProductList = ((List<LinkedHashMap<String, Object>>) request.getContext().get("components")).stream().filter(map -> (boolean) map.get("selected")).map(map -> prodProductRepository.find(Long.valueOf(map.get("id").toString()))).collect(Collectors.toList());
if (prodProductList.isEmpty()) {
throw new AxelorException(TraceBackRepository.CATEGORY_MISSING_FIELD, I18n.get(IExceptionMessage.NO_PRODUCT_SELECTED));
}
List<Product> selectedProductList = new ArrayList<>();
for (ProdProduct prod : prodProductList) {
if (selectedProductList.contains(prod.getProduct())) {
throw new AxelorException(TraceBackRepository.CATEGORY_MISSING_FIELD, I18n.get(IExceptionMessage.DUPLICATE_PRODUCT_SELECTED));
}
selectedProductList.add(prod.getProduct());
}
List<ManufOrder> moList = Beans.get(ManufOrderService.class).generateAllSubManufOrder(selectedProductList, mo);
response.setCanClose(true);
response.setView(ActionView.define(I18n.get("Manufacturing orders")).model(ManufOrder.class.getName()).add("grid", "generated-manuf-order-grid").add("form", "manuf-order-form").param("popup", "true").param("popup-save", "false").param("show-toolbar", "false").param("show-confirm", "false").domain("self.id in (" + StringTool.getIdListString(moList) + ")").map());
} catch (Exception e) {
TraceBackService.trace(response, e);
}
}
use of com.axelor.apps.production.db.ProdProduct in project axelor-open-suite by axelor.
the class MrpServiceProductionImpl method computeQtyLeftToConsume.
protected BigDecimal computeQtyLeftToConsume(List<StockMoveLine> consumedStockMoveLineList, ProdProduct prodProduct) {
BigDecimal qtyToConsume = prodProduct.getQty();
BigDecimal consumedQty = consumedStockMoveLineList.stream().filter(stockMoveLine -> stockMoveLine.getStockMove().getStatusSelect() == StockMoveRepository.STATUS_REALIZED && stockMoveLine.getProduct().equals(prodProduct.getProduct())).map(StockMoveLine::getQty).reduce(BigDecimal::add).orElse(BigDecimal.ZERO);
return qtyToConsume.subtract(consumedQty);
}
use of com.axelor.apps.production.db.ProdProduct in project axelor-open-suite by axelor.
the class ProdProcessService method validateProdProcess.
public void validateProdProcess(ProdProcess prodProcess, BillOfMaterial bom) throws AxelorException {
Map<Product, BigDecimal> bomMap = new HashMap<Product, BigDecimal>();
Set<BillOfMaterial> setBoM = MoreObjects.firstNonNull(bom.getBillOfMaterialSet(), Collections.emptySet());
for (BillOfMaterial bomIt : setBoM) {
bomMap.put(bomIt.getProduct(), bomIt.getQty());
}
List<ProdProcessLine> listPPL = MoreObjects.firstNonNull(prodProcess.getProdProcessLineList(), Collections.emptyList());
for (ProdProcessLine prodProcessLine : listPPL) {
List<ProdProduct> listPP = MoreObjects.firstNonNull(prodProcessLine.getToConsumeProdProductList(), Collections.emptyList());
for (ProdProduct prodProduct : listPP) {
if (!bomMap.containsKey(prodProduct.getProduct())) {
throw new AxelorException(TraceBackRepository.CATEGORY_CONFIGURATION_ERROR, I18n.get(IExceptionMessage.PROD_PROCESS_USELESS_PRODUCT), prodProduct.getProduct().getName());
}
bomMap.put(prodProduct.getProduct(), bomMap.get(prodProduct.getProduct()).subtract(prodProduct.getQty()));
}
}
Set<Product> keyList = bomMap.keySet();
Map<Product, BigDecimal> copyMap = new HashMap<Product, BigDecimal>();
List<String> nameProductList = new ArrayList<String>();
for (Product product : keyList) {
if (bomMap.get(product).compareTo(BigDecimal.ZERO) > 0) {
copyMap.put(product, bomMap.get(product));
nameProductList.add(product.getName());
}
}
if (!copyMap.isEmpty()) {
throw new AxelorException(TraceBackRepository.CATEGORY_CONFIGURATION_ERROR, I18n.get(IExceptionMessage.PROD_PROCESS_MISS_PRODUCT), Joiner.on(",").join(nameProductList));
}
}
use of com.axelor.apps.production.db.ProdProduct 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;
}
use of com.axelor.apps.production.db.ProdProduct 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);
}
Aggregations