use of com.axelor.exception.AxelorException in project axelor-open-suite by axelor.
the class OperationOrderWorkflowService method getMachineSetupDuration.
public long getMachineSetupDuration(OperationOrder operationOrder) throws AxelorException {
ProdProcessLine prodProcessLine = operationOrder.getProdProcessLine();
long duration = 0;
WorkCenter workCenter = prodProcessLine.getWorkCenter();
if (workCenter == null) {
return 0;
}
int workCenterTypeSelect = workCenter.getWorkCenterTypeSelect();
if (workCenterTypeSelect == WorkCenterRepository.WORK_CENTER_TYPE_MACHINE || workCenterTypeSelect == WorkCenterRepository.WORK_CENTER_TYPE_BOTH) {
Machine machine = workCenter.getMachine();
if (machine == null) {
throw new AxelorException(workCenter, TraceBackRepository.CATEGORY_MISSING_FIELD, I18n.get(IExceptionMessage.WORKCENTER_NO_MACHINE), workCenter.getName());
}
duration += machine.getStartingDuration();
duration += machine.getEndingDuration();
duration += machine.getSetupDuration();
}
return duration;
}
use of com.axelor.exception.AxelorException in project axelor-open-suite by axelor.
the class ManufOrderServiceImpl method createDiffProdProductList.
@Override
public List<ProdProduct> createDiffProdProductList(List<ProdProduct> prodProductList, List<StockMoveLine> stockMoveLineList) throws AxelorException {
List<ProdProduct> diffConsumeList = new ArrayList<>();
for (ProdProduct prodProduct : prodProductList) {
Product product = prodProduct.getProduct();
Unit newUnit = prodProduct.getUnit();
List<StockMoveLine> stockMoveLineProductList = stockMoveLineList.stream().filter(stockMoveLine1 -> stockMoveLine1.getProduct() != null).filter(stockMoveLine1 -> stockMoveLine1.getProduct().equals(product)).collect(Collectors.toList());
if (stockMoveLineProductList.isEmpty()) {
StockMoveLine stockMoveLine = new StockMoveLine();
stockMoveLineProductList.add(stockMoveLine);
}
BigDecimal diffQty = computeDiffQty(prodProduct, stockMoveLineProductList, product);
BigDecimal plannedQty = prodProduct.getQty();
BigDecimal realQty = diffQty.add(plannedQty);
if (diffQty.compareTo(BigDecimal.ZERO) != 0) {
ProdProduct diffProdProduct = new ProdProduct();
diffProdProduct.setQty(diffQty);
diffProdProduct.setPlannedQty(plannedQty);
diffProdProduct.setRealQty(realQty);
diffProdProduct.setProduct(product);
diffProdProduct.setUnit(newUnit);
diffConsumeList.add(diffProdProduct);
}
}
// There are stock move lines with products that are not available in
// prod product list. It needs to appear in the prod product list
List<StockMoveLine> stockMoveLineMissingProductList = stockMoveLineList.stream().filter(stockMoveLine1 -> stockMoveLine1.getProduct() != null).filter(stockMoveLine1 -> !prodProductList.stream().map(ProdProduct::getProduct).collect(Collectors.toList()).contains(stockMoveLine1.getProduct())).collect(Collectors.toList());
for (StockMoveLine stockMoveLine : stockMoveLineMissingProductList) {
if (stockMoveLine.getQty().compareTo(BigDecimal.ZERO) != 0) {
ProdProduct diffProdProduct = new ProdProduct();
diffProdProduct.setQty(stockMoveLine.getQty());
diffProdProduct.setPlannedQty(BigDecimal.ZERO);
diffProdProduct.setRealQty(stockMoveLine.getQty());
diffProdProduct.setProduct(stockMoveLine.getProduct());
diffProdProduct.setUnit(stockMoveLine.getUnit());
diffConsumeList.add(diffProdProduct);
}
}
return diffConsumeList;
}
use of com.axelor.exception.AxelorException 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.exception.AxelorException in project axelor-open-suite by axelor.
the class CostSheetLineServiceImpl method getComponentCostPrice.
protected BigDecimal getComponentCostPrice(Product product, int componentsValuationMethod, Company company) throws AxelorException {
BigDecimal price = null;
Currency companyCurrency = company.getCurrency();
if (componentsValuationMethod == ProductRepository.COMPONENTS_VALUATION_METHOD_AVERAGE) {
price = weightedAveragePriceService.computeAvgPriceForCompany(product, company);
if (price == null || price.compareTo(BigDecimal.ZERO) == 0) {
price = (BigDecimal) productCompanyService.get(product, "costPrice", company);
}
} else if (componentsValuationMethod == ProductRepository.COMPONENTS_VALUATION_METHOD_COST) {
price = (BigDecimal) productCompanyService.get(product, "costPrice", company);
if (price == null || price.compareTo(BigDecimal.ZERO) == 0) {
price = weightedAveragePriceService.computeAvgPriceForCompany(product, company);
}
}
if (product.getPurchasable() && (price == null || price.compareTo(BigDecimal.ZERO) == 0)) {
price = (BigDecimal) productCompanyService.get(product, "purchasePrice", company);
price = unitConversionService.convert(product.getUnit(), product.getPurchasesUnit() != null ? product.getPurchasesUnit() : product.getUnit(), price, appProductionService.getNbDecimalDigitForUnitPrice(), product);
BigDecimal shippingCoef = shippingCoefService.getShippingCoef(product, (Partner) productCompanyService.get(product, "defaultSupplierPartner", company), company, new BigDecimal(9999999));
price = price.multiply(shippingCoef);
if (productCompanyService.get(product, "purchaseCurrency", company) == null) {
throw new AxelorException(TraceBackRepository.CATEGORY_CONFIGURATION_ERROR, I18n.get(IExceptionMessage.MISSING_PRODUCT_PURCHASE_CURRENCY), product.getFullName());
}
price = currencyService.getAmountCurrencyConvertedAtDate((Currency) productCompanyService.get(product, "purchaseCurrency", company), companyCurrency, price, appProductionService.getTodayDate(company));
if (price == null || price.compareTo(BigDecimal.ZERO) == 0) {
@SuppressWarnings("unchecked") List<SupplierCatalog> supplierCatalogList = (List<SupplierCatalog>) productCompanyService.get(product, "supplierCatalogList", company);
for (SupplierCatalog supplierCatalog : supplierCatalogList) {
if (BigDecimal.ZERO.compareTo(supplierCatalog.getPrice()) < 0) {
price = unitConversionService.convert(product.getUnit(), product.getPurchasesUnit() != null ? product.getPurchasesUnit() : product.getUnit(), supplierCatalog.getPrice(), appProductionService.getNbDecimalDigitForUnitPrice(), product);
Partner supplierPartner = supplierCatalog.getSupplierPartner();
if (supplierPartner != null) {
shippingCoef = shippingCoefService.getShippingCoef(product, supplierPartner, company, new BigDecimal(9999999));
price = price.multiply(shippingCoef);
price = currencyService.getAmountCurrencyConvertedAtDate(supplierPartner.getCurrency(), companyCurrency, price, appProductionService.getTodayDate(company));
}
break;
}
}
}
}
return price;
}
use of com.axelor.exception.AxelorException 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);
}
}
Aggregations