use of com.axelor.apps.production.db.ManufOrder in project axelor-open-suite by axelor.
the class ManufOrderStockMoveService method createNewConsumedStockMoveLineList.
/**
* Clear the consumed list and create a new one with the right quantity.
*
* @param manufOrder
* @param qtyToUpdate
*/
public void createNewConsumedStockMoveLineList(ManufOrder manufOrder, BigDecimal qtyToUpdate) throws AxelorException {
// find planned stock move
Optional<StockMove> stockMoveOpt = getPlannedStockMove(manufOrder.getInStockMoveList());
if (!stockMoveOpt.isPresent()) {
return;
}
StockMove stockMove = stockMoveOpt.get();
stockMoveService.cancel(stockMove);
// clear all lists from planned lines
manufOrder.getConsumedStockMoveLineList().removeIf(stockMoveLine -> stockMoveLine.getStockMove().getStatusSelect() == StockMoveRepository.STATUS_CANCELED);
stockMove.clearStockMoveLineList();
// create a new list
for (ProdProduct prodProduct : manufOrder.getToConsumeProdProductList()) {
BigDecimal qty = getFractionQty(manufOrder, prodProduct, qtyToUpdate);
_createStockMoveLine(prodProduct, stockMove, StockMoveLineService.TYPE_IN_PRODUCTIONS, qty);
// Update consumed StockMoveLineList with created stock move lines
stockMove.getStockMoveLineList().stream().filter(stockMoveLine1 -> !manufOrder.getConsumedStockMoveLineList().contains(stockMoveLine1)).forEach(manufOrder::addConsumedStockMoveLineListItem);
}
stockMoveService.plan(stockMove);
}
use of com.axelor.apps.production.db.ManufOrder in project axelor-open-suite by axelor.
the class ManufOrderServiceImpl method generateAllSubManufOrder.
/**
* Called by generateMultiLevelManufOrder controller to generate all manuf order for a given bill
* of material list from a given manuf order.
*
* @param billOfMaterialList
* @param manufOrder
* @throws AxelorException
* @return
*/
public List<ManufOrder> generateAllSubManufOrder(List<Product> productList, ManufOrder manufOrder) throws AxelorException {
List<ManufOrder> moList = new ArrayList<>();
Set<Product> productManufactured = new HashSet<>();
List<Pair<BillOfMaterial, BigDecimal>> childBomList = getToConsumeSubBomList(manufOrder.getBillOfMaterial(), manufOrder, productList);
// prevent infinite loop
int depth = 0;
while (!childBomList.isEmpty()) {
if (depth >= 25) {
throw new AxelorException(TraceBackRepository.CATEGORY_CONFIGURATION_ERROR, I18n.get(IExceptionMessage.CHILD_BOM_TOO_MANY_ITERATION));
}
List<Pair<BillOfMaterial, BigDecimal>> tempChildBomList = new ArrayList<>();
for (Pair<BillOfMaterial, BigDecimal> childBomPair : childBomList) {
BillOfMaterial childBom = childBomPair.getLeft();
BigDecimal qtyRequested = childBomPair.getRight();
if (productManufactured.contains(childBom.getProduct())) {
continue;
}
manufOrder = generateManufOrder(childBom.getProduct(), qtyRequested.multiply(childBom.getQty()), childBom.getPriority(), IS_TO_INVOICE, childBom, null, manufOrder.getPlannedStartDateT(), ORIGIN_TYPE_OTHER);
moList.add(manufOrder);
productManufactured.add(childBom.getProduct());
tempChildBomList.addAll(getToConsumeSubBomList(childBom, manufOrder, null));
}
childBomList.clear();
childBomList.addAll(tempChildBomList);
tempChildBomList.clear();
depth++;
}
return moList;
}
use of com.axelor.apps.production.db.ManufOrder in project axelor-open-suite by axelor.
the class ManufOrderController method cancel.
public void cancel(ActionRequest request, ActionResponse response) {
try {
Context context = request.getContext();
ManufOrder manufOrder = context.asType(ManufOrder.class);
Beans.get(ManufOrderWorkflowService.class).cancel(Beans.get(ManufOrderRepository.class).find(manufOrder.getId()), manufOrder.getCancelReason(), manufOrder.getCancelReasonStr());
response.setFlash(I18n.get(IExceptionMessage.MANUF_ORDER_CANCEL));
response.setCanClose(true);
} catch (Exception e) {
TraceBackService.trace(response, e);
}
}
use of com.axelor.apps.production.db.ManufOrder 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.ManufOrder in project axelor-open-suite by axelor.
the class ManufOrderController method computeCostPrice.
/**
* Called from manuf order form, on clicking "compute cost price" button. Call {@link
* CostSheetService#computeCostPrice(ManufOrder, int, LocalDate)}.
*
* @param request
* @param response
*/
public void computeCostPrice(ActionRequest request, ActionResponse response) {
try {
ManufOrder manufOrder = request.getContext().asType(ManufOrder.class);
manufOrder = Beans.get(ManufOrderRepository.class).find(manufOrder.getId());
CostSheet costSheet = Beans.get(CostSheetService.class).computeCostPrice(manufOrder, CostSheetRepository.CALCULATION_WORK_IN_PROGRESS, Beans.get(AppBaseService.class).getTodayDate(manufOrder.getCompany()));
response.setView(ActionView.define(I18n.get("Cost sheet")).model(CostSheet.class.getName()).param("popup", "true").param("show-toolbar", "false").param("show-confirm", "false").param("popup-save", "false").add("grid", "cost-sheet-bill-of-material-grid").add("form", "cost-sheet-bill-of-material-form").context("_showRecord", String.valueOf(costSheet.getId())).map());
response.setReload(true);
} catch (Exception e) {
TraceBackService.trace(response, e);
}
}
Aggregations