Search in sources :

Example 6 with ProdProduct

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);
    }
}
Also used : IExceptionMessage(com.axelor.apps.production.exceptions.IExceptionMessage) AppProductionService(com.axelor.apps.production.service.app.AppProductionService) BirtException(org.eclipse.birt.core.exception.BirtException) CostSheetRepository(com.axelor.apps.production.db.repo.CostSheetRepository) ProductRepository(com.axelor.apps.base.db.repo.ProductRepository) ActionView(com.axelor.meta.schema.actions.ActionView) ProdProductRepository(com.axelor.apps.production.db.repo.ProdProductRepository) LoggerFactory(org.slf4j.LoggerFactory) ArrayList(java.util.ArrayList) LinkedHashMap(java.util.LinkedHashMap) BigDecimal(java.math.BigDecimal) AxelorException(com.axelor.exception.AxelorException) ActionResponse(com.axelor.rpc.ActionResponse) I18n(com.axelor.i18n.I18n) ManufOrderService(com.axelor.apps.production.service.manuforder.ManufOrderService) ActionRequest(com.axelor.rpc.ActionRequest) ProdProductProductionRepository(com.axelor.apps.production.service.ProdProductProductionRepository) ProdProduct(com.axelor.apps.production.db.ProdProduct) StringTool(com.axelor.apps.tool.StringTool) ManufOrderPrintService(com.axelor.apps.production.service.manuforder.ManufOrderPrintService) Logger(org.slf4j.Logger) TraceBackRepository(com.axelor.exception.db.repo.TraceBackRepository) MethodHandles(java.lang.invoke.MethodHandles) CostSheet(com.axelor.apps.production.db.CostSheet) TraceBackService(com.axelor.exception.service.TraceBackService) IOException(java.io.IOException) AppBaseService(com.axelor.apps.base.service.app.AppBaseService) Collectors(java.util.stream.Collectors) ManufOrderWorkflowService(com.axelor.apps.production.service.manuforder.ManufOrderWorkflowService) List(java.util.List) IReport(com.axelor.apps.production.report.IReport) CostSheetService(com.axelor.apps.production.service.costsheet.CostSheetService) ReportSettings(com.axelor.apps.report.engine.ReportSettings) Beans(com.axelor.inject.Beans) Product(com.axelor.apps.base.db.Product) ManufOrder(com.axelor.apps.production.db.ManufOrder) ReportFactory(com.axelor.apps.ReportFactory) LocalDate(java.time.LocalDate) ObjectUtils(com.axelor.common.ObjectUtils) ManufOrderRepository(com.axelor.apps.production.db.repo.ManufOrderRepository) Context(com.axelor.rpc.Context) ManufOrderStockMoveService(com.axelor.apps.production.service.manuforder.ManufOrderStockMoveService) Singleton(com.google.inject.Singleton) ManufOrderService(com.axelor.apps.production.service.manuforder.ManufOrderService) AxelorException(com.axelor.exception.AxelorException) ArrayList(java.util.ArrayList) ProdProduct(com.axelor.apps.production.db.ProdProduct) Product(com.axelor.apps.base.db.Product) ProdProduct(com.axelor.apps.production.db.ProdProduct) BirtException(org.eclipse.birt.core.exception.BirtException) AxelorException(com.axelor.exception.AxelorException) IOException(java.io.IOException) LinkedHashMap(java.util.LinkedHashMap) ManufOrderRepository(com.axelor.apps.production.db.repo.ManufOrderRepository) ProdProductRepository(com.axelor.apps.production.db.repo.ProdProductRepository) ManufOrder(com.axelor.apps.production.db.ManufOrder)

Example 7 with ProdProduct

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);
}
Also used : StockLocationRepository(com.axelor.apps.stock.db.repo.StockLocationRepository) MrpLineTypeRepository(com.axelor.apps.supplychain.db.repo.MrpLineTypeRepository) IExceptionMessage(com.axelor.apps.production.exceptions.IExceptionMessage) MrpLineOrigin(com.axelor.apps.supplychain.db.MrpLineOrigin) AppPurchaseService(com.axelor.apps.purchase.service.app.AppPurchaseService) Inject(com.google.inject.Inject) LoggerFactory(org.slf4j.LoggerFactory) ProductCompanyService(com.axelor.apps.base.service.ProductCompanyService) PurchaseOrderLineRepository(com.axelor.apps.purchase.db.repo.PurchaseOrderLineRepository) Transactional(com.google.inject.persist.Transactional) SaleOrderLineRepository(com.axelor.apps.sale.db.repo.SaleOrderLineRepository) BigDecimal(java.math.BigDecimal) BillOfMaterial(com.axelor.apps.production.db.BillOfMaterial) StockRulesRepository(com.axelor.apps.stock.db.repo.StockRulesRepository) StockRules(com.axelor.apps.stock.db.StockRules) StockLocationService(com.axelor.apps.stock.service.StockLocationService) RoundingMode(java.math.RoundingMode) StockLocationLineRepository(com.axelor.apps.stock.db.repo.StockLocationLineRepository) StockMoveRepository(com.axelor.apps.stock.db.repo.StockMoveRepository) MrpLine(com.axelor.apps.supplychain.db.MrpLine) MethodHandles(java.lang.invoke.MethodHandles) MrpLineType(com.axelor.apps.supplychain.db.MrpLineType) AppBaseService(com.axelor.apps.base.service.app.AppBaseService) List(java.util.List) Product(com.axelor.apps.base.db.Product) ManufOrder(com.axelor.apps.production.db.ManufOrder) Mrp(com.axelor.apps.supplychain.db.Mrp) LocalDate(java.time.LocalDate) ManufOrderRepository(com.axelor.apps.production.db.repo.ManufOrderRepository) Company(com.axelor.apps.base.db.Company) AppProductionService(com.axelor.apps.production.service.app.AppProductionService) ProductRepository(com.axelor.apps.base.db.repo.ProductRepository) MrpServiceImpl(com.axelor.apps.supplychain.service.MrpServiceImpl) MrpLineRepository(com.axelor.apps.supplychain.db.repo.MrpLineRepository) MrpRepository(com.axelor.apps.supplychain.db.repo.MrpRepository) AxelorException(com.axelor.exception.AxelorException) StockLocation(com.axelor.apps.stock.db.StockLocation) I18n(com.axelor.i18n.I18n) ProdProduct(com.axelor.apps.production.db.ProdProduct) StringTool(com.axelor.apps.tool.StringTool) JPA(com.axelor.db.JPA) Logger(org.slf4j.Logger) TraceBackRepository(com.axelor.exception.db.repo.TraceBackRepository) MrpLineService(com.axelor.apps.supplychain.service.MrpLineService) MrpForecastRepository(com.axelor.apps.supplychain.db.repo.MrpForecastRepository) OperationOrder(com.axelor.apps.production.db.OperationOrder) StockMoveLine(com.axelor.apps.stock.db.StockMoveLine) StockRulesService(com.axelor.apps.stock.service.StockRulesService) Beans(com.axelor.inject.Beans) StockMoveLine(com.axelor.apps.stock.db.StockMoveLine) BigDecimal(java.math.BigDecimal)

Example 8 with ProdProduct

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));
    }
}
Also used : AxelorException(com.axelor.exception.AxelorException) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) ProdProduct(com.axelor.apps.production.db.ProdProduct) Product(com.axelor.apps.base.db.Product) ProdProduct(com.axelor.apps.production.db.ProdProduct) ProdProcessLine(com.axelor.apps.production.db.ProdProcessLine) BigDecimal(java.math.BigDecimal) BillOfMaterial(com.axelor.apps.production.db.BillOfMaterial)

Example 9 with ProdProduct

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;
}
Also used : StockMoveLineService(com.axelor.apps.stock.service.StockMoveLineService) Company(com.axelor.apps.base.db.Company) StockMove(com.axelor.apps.stock.db.StockMove) StockMoveService(com.axelor.apps.stock.service.StockMoveService) OperationOrderStockMoveService(com.axelor.apps.production.service.operationorder.OperationOrderStockMoveService) StockConfig(com.axelor.apps.stock.db.StockConfig) AppBaseService(com.axelor.apps.base.service.app.AppBaseService) StockLocation(com.axelor.apps.stock.db.StockLocation) StockConfigProductionService(com.axelor.apps.production.service.config.StockConfigProductionService) ProdProduct(com.axelor.apps.production.db.ProdProduct) Transactional(com.google.inject.persist.Transactional)

Example 10 with ProdProduct

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);
}
Also used : Company(com.axelor.apps.base.db.Company) IExceptionMessage(com.axelor.apps.production.exceptions.IExceptionMessage) ProductRepository(com.axelor.apps.base.db.repo.ProductRepository) ReservedQtyService(com.axelor.apps.supplychain.service.ReservedQtyService) Inject(com.google.inject.Inject) LocalDateTime(java.time.LocalDateTime) LoggerFactory(org.slf4j.LoggerFactory) StockMoveService(com.axelor.apps.stock.service.StockMoveService) ProductCompanyService(com.axelor.apps.base.service.ProductCompanyService) Transactional(com.google.inject.persist.Transactional) ArrayList(java.util.ArrayList) BigDecimal(java.math.BigDecimal) AxelorException(com.axelor.exception.AxelorException) StockLocation(com.axelor.apps.stock.db.StockLocation) CollectionUtils(org.apache.commons.collections.CollectionUtils) I18n(com.axelor.i18n.I18n) StockMoveLineService(com.axelor.apps.stock.service.StockMoveLineService) ProdProcess(com.axelor.apps.production.db.ProdProcess) ProdProduct(com.axelor.apps.production.db.ProdProduct) RoundingMode(java.math.RoundingMode) Logger(org.slf4j.Logger) StockConfig(com.axelor.apps.stock.db.StockConfig) StockMove(com.axelor.apps.stock.db.StockMove) StockMoveRepository(com.axelor.apps.stock.db.repo.StockMoveRepository) MethodHandles(java.lang.invoke.MethodHandles) AppBaseService(com.axelor.apps.base.service.app.AppBaseService) OperationOrder(com.axelor.apps.production.db.OperationOrder) OperationOrderRepository(com.axelor.apps.production.db.repo.OperationOrderRepository) StockConfigProductionService(com.axelor.apps.production.service.config.StockConfigProductionService) SupplyChainConfig(com.axelor.apps.supplychain.db.SupplyChainConfig) StockMoveLine(com.axelor.apps.stock.db.StockMoveLine) List(java.util.List) Beans(com.axelor.inject.Beans) ManufOrder(com.axelor.apps.production.db.ManufOrder) LocalDate(java.time.LocalDate) Optional(java.util.Optional) ManufOrderRepository(com.axelor.apps.production.db.repo.ManufOrderRepository) OperationOrderStockMoveService(com.axelor.apps.production.service.operationorder.OperationOrderStockMoveService) SupplyChainConfigService(com.axelor.apps.supplychain.service.config.SupplyChainConfigService) StockMove(com.axelor.apps.stock.db.StockMove) ProdProduct(com.axelor.apps.production.db.ProdProduct) BigDecimal(java.math.BigDecimal)

Aggregations

ProdProduct (com.axelor.apps.production.db.ProdProduct)17 BigDecimal (java.math.BigDecimal)13 Company (com.axelor.apps.base.db.Company)9 Product (com.axelor.apps.base.db.Product)9 StockMove (com.axelor.apps.stock.db.StockMove)8 StockMoveLine (com.axelor.apps.stock.db.StockMoveLine)8 AxelorException (com.axelor.exception.AxelorException)8 ArrayList (java.util.ArrayList)8 List (java.util.List)8 AppBaseService (com.axelor.apps.base.service.app.AppBaseService)7 ManufOrder (com.axelor.apps.production.db.ManufOrder)7 StockLocation (com.axelor.apps.stock.db.StockLocation)7 Beans (com.axelor.inject.Beans)7 Transactional (com.google.inject.persist.Transactional)7 LocalDate (java.time.LocalDate)7 ProductRepository (com.axelor.apps.base.db.repo.ProductRepository)6 OperationOrder (com.axelor.apps.production.db.OperationOrder)6 ManufOrderRepository (com.axelor.apps.production.db.repo.ManufOrderRepository)6 IExceptionMessage (com.axelor.apps.production.exceptions.IExceptionMessage)6 I18n (com.axelor.i18n.I18n)6