Search in sources :

Example 31 with ManufOrder

use of com.axelor.apps.production.db.ManufOrder in project axelor-open-suite by axelor.

the class ManufOrderServiceImpl method createManufOrder.

@Override
public ManufOrder createManufOrder(Product product, BigDecimal qty, int priority, boolean isToInvoice, Company company, BillOfMaterial billOfMaterial, LocalDateTime plannedStartDateT, LocalDateTime plannedEndDateT) throws AxelorException {
    logger.debug("Création d'un OF {}", priority);
    ProdProcess prodProcess = billOfMaterial.getProdProcess();
    ManufOrder manufOrder = new ManufOrder(qty, company, null, priority, this.isManagedConsumedProduct(billOfMaterial), billOfMaterial, product, prodProcess, plannedStartDateT, plannedEndDateT, ManufOrderRepository.STATUS_DRAFT, prodProcess.getOutsourcing());
    manufOrder = manufOrderRepo.save(manufOrder);
    if (appProductionService.getAppProduction().getManageWorkshop()) {
        manufOrder.setWorkshopStockLocation(billOfMaterial.getWorkshopStockLocation());
    }
    if (prodProcess != null && prodProcess.getProdProcessLineList() != null) {
        for (ProdProcessLine prodProcessLine : this._sortProdProcessLineByPriority(prodProcess.getProdProcessLineList())) {
            manufOrder.addOperationOrderListItem(operationOrderService.createOperationOrder(manufOrder, prodProcessLine));
        }
    }
    return manufOrder;
}
Also used : ProdProcess(com.axelor.apps.production.db.ProdProcess) ProdProcessLine(com.axelor.apps.production.db.ProdProcessLine) ManufOrder(com.axelor.apps.production.db.ManufOrder)

Example 32 with ManufOrder

use of com.axelor.apps.production.db.ManufOrder in project axelor-open-suite by axelor.

the class ManufOrderServiceImpl method merge.

@Transactional(rollbackOn = { Exception.class })
public void merge(List<Long> ids) throws AxelorException {
    if (!canMerge(ids)) {
        throw new AxelorException(ManufOrder.class, TraceBackRepository.CATEGORY_INCONSISTENCY, I18n.get(IExceptionMessage.MANUF_ORDER_NO_GENERATION));
    }
    List<ManufOrder> manufOrderList = manufOrderRepo.all().filter("self.id in (" + Joiner.on(",").join(ids) + ")").fetch();
    /* Init all the necessary values to create the new Manuf Order */
    Product product = manufOrderList.get(0).getProduct();
    StockLocation stockLocation = manufOrderList.get(0).getWorkshopStockLocation();
    Company company = manufOrderList.get(0).getCompany();
    BillOfMaterial billOfMaterial = manufOrderList.stream().filter(x -> x.getBillOfMaterial().getVersionNumber() == 1).findFirst().get().getBillOfMaterial();
    int priority = manufOrderList.stream().mapToInt(ManufOrder::getPrioritySelect).max().orElse(2);
    Unit unit = billOfMaterial.getUnit();
    BigDecimal qty = BigDecimal.ZERO;
    String note = "";
    ManufOrder mergedManufOrder = new ManufOrder();
    for (ManufOrder manufOrder : manufOrderList) {
        manufOrder.setStatusSelect(ManufOrderRepository.STATUS_MERGED);
        manufOrder.setManufOrderMergeResult(mergedManufOrder);
        for (ProductionOrder productionOrder : manufOrder.getProductionOrderSet()) {
            mergedManufOrder.addProductionOrderSetItem(productionOrder);
        }
        for (SaleOrder saleOrder : manufOrder.getSaleOrderSet()) {
            mergedManufOrder.addSaleOrderSetItem(saleOrder);
        }
        /*
       * If unit are the same, then add the qty If not, convert the unit and get the converted qty
       */
        if (manufOrder.getUnit().equals(unit)) {
            qty = qty.add(manufOrder.getQty());
        } else {
            BigDecimal qtyConverted = Beans.get(UnitConversionService.class).convert(manufOrder.getUnit(), unit, manufOrder.getQty(), appBaseService.getNbDecimalDigitForQty(), null);
            qty = qty.add(qtyConverted);
        }
        if (manufOrder.getNote() != null && !manufOrder.getNote().equals("")) {
            note += manufOrder.getManufOrderSeq() + " : " + manufOrder.getNote() + "\n";
        }
    }
    Optional<LocalDateTime> minDate = manufOrderList.stream().filter(mo -> mo.getPlannedStartDateT() != null).map(ManufOrder::getPlannedStartDateT).min(LocalDateTime::compareTo);
    minDate.ifPresent(mergedManufOrder::setPlannedStartDateT);
    /* Update the created manuf order */
    mergedManufOrder.setStatusSelect(ManufOrderRepository.STATUS_DRAFT);
    mergedManufOrder.setProduct(product);
    mergedManufOrder.setUnit(unit);
    mergedManufOrder.setWorkshopStockLocation(stockLocation);
    mergedManufOrder.setQty(qty);
    mergedManufOrder.setBillOfMaterial(billOfMaterial);
    mergedManufOrder.setCompany(company);
    mergedManufOrder.setPrioritySelect(priority);
    mergedManufOrder.setProdProcess(billOfMaterial.getProdProcess());
    mergedManufOrder.setNote(note);
    /*
     * Check the config to see if you directly plan the created manuf order or just prefill the
     * operations
     */
    if (appProductionService.isApp("production") && appProductionService.getAppProduction().getIsManufOrderPlannedAfterMerge()) {
        manufOrderWorkflowService.plan(mergedManufOrder);
    } else {
        preFillOperations(mergedManufOrder);
    }
    manufOrderRepo.save(mergedManufOrder);
}
Also used : StockLocationRepository(com.axelor.apps.stock.db.repo.StockLocationRepository) IExceptionMessage(com.axelor.apps.production.exceptions.IExceptionMessage) ProductionConfig(com.axelor.apps.production.db.ProductionConfig) Inject(com.google.inject.Inject) LoggerFactory(org.slf4j.LoggerFactory) ProductCompanyService(com.axelor.apps.base.service.ProductCompanyService) Transactional(com.google.inject.persist.Transactional) BigDecimal(java.math.BigDecimal) Pair(org.apache.commons.lang3.tuple.Pair) BillOfMaterial(com.axelor.apps.production.db.BillOfMaterial) ProductVariantService(com.axelor.apps.base.service.ProductVariantService) SaleOrder(com.axelor.apps.sale.db.SaleOrder) StockMoveLineService(com.axelor.apps.stock.service.StockMoveLineService) ProductionConfigService(com.axelor.apps.production.service.config.ProductionConfigService) StockLocationService(com.axelor.apps.stock.service.StockLocationService) RoundingMode(java.math.RoundingMode) ProdProcessLine(com.axelor.apps.production.db.ProdProcessLine) 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) Collection(java.util.Collection) Set(java.util.Set) AppBaseService(com.axelor.apps.base.service.app.AppBaseService) StringUtils(com.axelor.common.StringUtils) Collectors(java.util.stream.Collectors) SequenceService(com.axelor.apps.base.service.administration.SequenceService) List(java.util.List) Product(com.axelor.apps.base.db.Product) ManufOrder(com.axelor.apps.production.db.ManufOrder) ProdResidualProduct(com.axelor.apps.production.db.ProdResidualProduct) Optional(java.util.Optional) ManufOrderRepository(com.axelor.apps.production.db.repo.ManufOrderRepository) Joiner(com.google.common.base.Joiner) Company(com.axelor.apps.base.db.Company) AppProductionService(com.axelor.apps.production.service.app.AppProductionService) ProductRepository(com.axelor.apps.base.db.repo.ProductRepository) ProdProductRepository(com.axelor.apps.production.db.repo.ProdProductRepository) LocalDateTime(java.time.LocalDateTime) StockMoveService(com.axelor.apps.stock.service.StockMoveService) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) AxelorException(com.axelor.exception.AxelorException) UnitConversionService(com.axelor.apps.base.service.UnitConversionService) StockLocation(com.axelor.apps.stock.db.StockLocation) I18n(com.axelor.i18n.I18n) ProdProcess(com.axelor.apps.production.db.ProdProcess) ProdProduct(com.axelor.apps.production.db.ProdProduct) ProductionOrder(com.axelor.apps.production.db.ProductionOrder) StringTool(com.axelor.apps.tool.StringTool) Sequence(com.axelor.apps.base.db.Sequence) Logger(org.slf4j.Logger) TraceBackRepository(com.axelor.exception.db.repo.TraceBackRepository) MoreObjects(com.google.common.base.MoreObjects) OperationOrder(com.axelor.apps.production.db.OperationOrder) StockConfigProductionService(com.axelor.apps.production.service.config.StockConfigProductionService) StockMoveLine(com.axelor.apps.stock.db.StockMoveLine) Beans(com.axelor.inject.Beans) Unit(com.axelor.apps.base.db.Unit) OperationOrderService(com.axelor.apps.production.service.operationorder.OperationOrderService) Comparator(java.util.Comparator) OperationOrderStockMoveService(com.axelor.apps.production.service.operationorder.OperationOrderStockMoveService) Collections(java.util.Collections) LocalDateTime(java.time.LocalDateTime) AxelorException(com.axelor.exception.AxelorException) Company(com.axelor.apps.base.db.Company) UnitConversionService(com.axelor.apps.base.service.UnitConversionService) StockLocation(com.axelor.apps.stock.db.StockLocation) Product(com.axelor.apps.base.db.Product) ProdResidualProduct(com.axelor.apps.production.db.ProdResidualProduct) ProdProduct(com.axelor.apps.production.db.ProdProduct) Unit(com.axelor.apps.base.db.Unit) SaleOrder(com.axelor.apps.sale.db.SaleOrder) BigDecimal(java.math.BigDecimal) BillOfMaterial(com.axelor.apps.production.db.BillOfMaterial) ManufOrder(com.axelor.apps.production.db.ManufOrder) ProductionOrder(com.axelor.apps.production.db.ProductionOrder) Transactional(com.google.inject.persist.Transactional)

Example 33 with ManufOrder

use of com.axelor.apps.production.db.ManufOrder in project axelor-open-suite by axelor.

the class ManufOrderServiceImpl method generateManufOrder.

@Override
@Transactional(rollbackOn = { Exception.class })
public ManufOrder generateManufOrder(Product product, BigDecimal qtyRequested, int priority, boolean isToInvoice, BillOfMaterial billOfMaterial, LocalDateTime plannedStartDateT, LocalDateTime plannedEndDateT, int originType) throws AxelorException {
    if (billOfMaterial == null) {
        billOfMaterial = this.getBillOfMaterial(product);
    }
    Company company = billOfMaterial.getCompany();
    BigDecimal qty = qtyRequested.divide(billOfMaterial.getQty(), appBaseService.getNbDecimalDigitForQty(), RoundingMode.HALF_UP);
    ManufOrder manufOrder = this.createManufOrder(product, qty, priority, IS_TO_INVOICE, company, billOfMaterial, plannedStartDateT, plannedEndDateT);
    if (originType == ORIGIN_TYPE_SALE_ORDER && appProductionService.getAppProduction().getAutoPlanManufOrderFromSO() || originType == ORIGIN_TYPE_MRP || originType == ORIGIN_TYPE_OTHER) {
        manufOrder = manufOrderWorkflowService.plan(manufOrder);
    }
    return manufOrderRepo.save(manufOrder);
}
Also used : Company(com.axelor.apps.base.db.Company) BigDecimal(java.math.BigDecimal) ManufOrder(com.axelor.apps.production.db.ManufOrder) Transactional(com.google.inject.persist.Transactional)

Example 34 with ManufOrder

use of com.axelor.apps.production.db.ManufOrder in project axelor-open-suite by axelor.

the class ManufOrderServiceImpl method canMerge.

public boolean canMerge(List<Long> ids) {
    List<ManufOrder> manufOrderList = manufOrderRepo.all().filter("self.id in (" + Joiner.on(",").join(ids) + ")").fetch();
    // I check if all the status of the manuf order in the list are Draft or
    // Planned. If not i can return false
    boolean allStatusDraftOrPlanned = manufOrderList.stream().allMatch(x -> x.getStatusSelect().equals(ManufOrderRepository.STATUS_DRAFT) || x.getStatusSelect().equals(ManufOrderRepository.STATUS_PLANNED));
    if (!allStatusDraftOrPlanned) {
        return false;
    }
    // I check if all the products are the same. If not i return false
    Product product = manufOrderList.get(0).getProduct();
    boolean allSameProducts = manufOrderList.stream().allMatch(x -> x.getProduct().equals(product));
    if (!allSameProducts) {
        return false;
    }
    // Workshop management must be enabled to do the checking
    if (appProductionService.getAppProduction().getManageWorkshop()) {
        // Check if one of the workShopStockLocation is null
        boolean oneWorkShopIsNull = manufOrderList.stream().anyMatch(x -> x.getWorkshopStockLocation() == null);
        if (oneWorkShopIsNull) {
            return false;
        }
        // I check if all the stockLocation are the same. If not i return false
        StockLocation stockLocation = manufOrderList.get(0).getWorkshopStockLocation();
        boolean allSameLocation = manufOrderList.stream().allMatch(x -> x.getWorkshopStockLocation() != null && x.getWorkshopStockLocation().equals(stockLocation));
        if (!allSameLocation) {
            return false;
        }
    }
    // Check if one of the billOfMaterial is null
    boolean oneBillOfMaterialIsNull = manufOrderList.stream().anyMatch(x -> x.getBillOfMaterial() == null);
    if (oneBillOfMaterialIsNull) {
        return false;
    }
    // Check if one of the billOfMaterial has his version equal to 1
    boolean oneBillOfMaterialWithFirstVersion = manufOrderList.stream().anyMatch(x -> x.getBillOfMaterial().getVersionNumber() == 1);
    if (!oneBillOfMaterialWithFirstVersion) {
        return false;
    }
    // I check if all the billOfMaterial are the same. If not i will check
    // if all version are compatible, and if not i can return false
    BillOfMaterial billOfMaterial = manufOrderList.stream().filter(x -> x.getBillOfMaterial().getVersionNumber() == 1).findFirst().get().getBillOfMaterial();
    boolean allSameOrCompatibleBillOfMaterial = manufOrderList.stream().allMatch(x -> x.getBillOfMaterial().equals(billOfMaterial) || billOfMaterial.equals(x.getBillOfMaterial().getOriginalBillOfMaterial()));
    if (!allSameOrCompatibleBillOfMaterial) {
        return false;
    }
    return true;
}
Also used : StockLocationRepository(com.axelor.apps.stock.db.repo.StockLocationRepository) IExceptionMessage(com.axelor.apps.production.exceptions.IExceptionMessage) ProductionConfig(com.axelor.apps.production.db.ProductionConfig) Inject(com.google.inject.Inject) LoggerFactory(org.slf4j.LoggerFactory) ProductCompanyService(com.axelor.apps.base.service.ProductCompanyService) Transactional(com.google.inject.persist.Transactional) BigDecimal(java.math.BigDecimal) Pair(org.apache.commons.lang3.tuple.Pair) BillOfMaterial(com.axelor.apps.production.db.BillOfMaterial) ProductVariantService(com.axelor.apps.base.service.ProductVariantService) SaleOrder(com.axelor.apps.sale.db.SaleOrder) StockMoveLineService(com.axelor.apps.stock.service.StockMoveLineService) ProductionConfigService(com.axelor.apps.production.service.config.ProductionConfigService) StockLocationService(com.axelor.apps.stock.service.StockLocationService) RoundingMode(java.math.RoundingMode) ProdProcessLine(com.axelor.apps.production.db.ProdProcessLine) 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) Collection(java.util.Collection) Set(java.util.Set) AppBaseService(com.axelor.apps.base.service.app.AppBaseService) StringUtils(com.axelor.common.StringUtils) Collectors(java.util.stream.Collectors) SequenceService(com.axelor.apps.base.service.administration.SequenceService) List(java.util.List) Product(com.axelor.apps.base.db.Product) ManufOrder(com.axelor.apps.production.db.ManufOrder) ProdResidualProduct(com.axelor.apps.production.db.ProdResidualProduct) Optional(java.util.Optional) ManufOrderRepository(com.axelor.apps.production.db.repo.ManufOrderRepository) Joiner(com.google.common.base.Joiner) Company(com.axelor.apps.base.db.Company) AppProductionService(com.axelor.apps.production.service.app.AppProductionService) ProductRepository(com.axelor.apps.base.db.repo.ProductRepository) ProdProductRepository(com.axelor.apps.production.db.repo.ProdProductRepository) LocalDateTime(java.time.LocalDateTime) StockMoveService(com.axelor.apps.stock.service.StockMoveService) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) AxelorException(com.axelor.exception.AxelorException) UnitConversionService(com.axelor.apps.base.service.UnitConversionService) StockLocation(com.axelor.apps.stock.db.StockLocation) I18n(com.axelor.i18n.I18n) ProdProcess(com.axelor.apps.production.db.ProdProcess) ProdProduct(com.axelor.apps.production.db.ProdProduct) ProductionOrder(com.axelor.apps.production.db.ProductionOrder) StringTool(com.axelor.apps.tool.StringTool) Sequence(com.axelor.apps.base.db.Sequence) Logger(org.slf4j.Logger) TraceBackRepository(com.axelor.exception.db.repo.TraceBackRepository) MoreObjects(com.google.common.base.MoreObjects) OperationOrder(com.axelor.apps.production.db.OperationOrder) StockConfigProductionService(com.axelor.apps.production.service.config.StockConfigProductionService) StockMoveLine(com.axelor.apps.stock.db.StockMoveLine) Beans(com.axelor.inject.Beans) Unit(com.axelor.apps.base.db.Unit) OperationOrderService(com.axelor.apps.production.service.operationorder.OperationOrderService) Comparator(java.util.Comparator) OperationOrderStockMoveService(com.axelor.apps.production.service.operationorder.OperationOrderStockMoveService) Collections(java.util.Collections) BillOfMaterial(com.axelor.apps.production.db.BillOfMaterial) StockLocation(com.axelor.apps.stock.db.StockLocation) Product(com.axelor.apps.base.db.Product) ProdResidualProduct(com.axelor.apps.production.db.ProdResidualProduct) ProdProduct(com.axelor.apps.production.db.ProdProduct) ManufOrder(com.axelor.apps.production.db.ManufOrder)

Example 35 with ManufOrder

use of com.axelor.apps.production.db.ManufOrder 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

ManufOrder (com.axelor.apps.production.db.ManufOrder)44 AxelorException (com.axelor.exception.AxelorException)30 IOException (java.io.IOException)22 BirtException (org.eclipse.birt.core.exception.BirtException)22 ManufOrderRepository (com.axelor.apps.production.db.repo.ManufOrderRepository)17 ManufOrderService (com.axelor.apps.production.service.manuforder.ManufOrderService)12 BigDecimal (java.math.BigDecimal)12 ArrayList (java.util.ArrayList)12 AppProductionService (com.axelor.apps.production.service.app.AppProductionService)11 List (java.util.List)11 ProdProduct (com.axelor.apps.production.db.ProdProduct)10 ManufOrderWorkflowService (com.axelor.apps.production.service.manuforder.ManufOrderWorkflowService)10 Transactional (com.google.inject.persist.Transactional)10 Beans (com.axelor.inject.Beans)9 Company (com.axelor.apps.base.db.Company)8 Product (com.axelor.apps.base.db.Product)8 ProductRepository (com.axelor.apps.base.db.repo.ProductRepository)8 AppBaseService (com.axelor.apps.base.service.app.AppBaseService)8 IExceptionMessage (com.axelor.apps.production.exceptions.IExceptionMessage)8 I18n (com.axelor.i18n.I18n)8