Search in sources :

Example 21 with BillOfMaterial

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

the class ManufOrderServiceImpl method preFillOperations.

@Override
@Transactional(rollbackOn = { Exception.class })
public void preFillOperations(ManufOrder manufOrder) throws AxelorException {
    BillOfMaterial billOfMaterial = manufOrder.getBillOfMaterial();
    if (manufOrder.getProdProcess() == null) {
        manufOrder.setProdProcess(billOfMaterial.getProdProcess());
    }
    ProdProcess prodProcess = manufOrder.getProdProcess();
    if (manufOrder.getPlannedStartDateT() == null) {
        manufOrder.setPlannedStartDateT(appProductionService.getTodayDateTime().toLocalDateTime());
    }
    if (prodProcess != null && prodProcess.getProdProcessLineList() != null) {
        for (ProdProcessLine prodProcessLine : this._sortProdProcessLineByPriority(prodProcess.getProdProcessLineList())) {
            manufOrder.addOperationOrderListItem(operationOrderService.createOperationOrder(manufOrder, prodProcessLine));
        }
    }
    manufOrderRepo.save(manufOrder);
    manufOrder.setPlannedEndDateT(manufOrderWorkflowService.computePlannedEndDateT(manufOrder));
    manufOrderRepo.save(manufOrder);
}
Also used : BillOfMaterial(com.axelor.apps.production.db.BillOfMaterial) ProdProcess(com.axelor.apps.production.db.ProdProcess) ProdProcessLine(com.axelor.apps.production.db.ProdProcessLine) Transactional(com.google.inject.persist.Transactional)

Example 22 with BillOfMaterial

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

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

the class ProductionOrderSaleOrderServiceImpl method generateManufOrders.

/**
 * Loop through bill of materials components to generate manufacturing order for given sale order
 * line and all of its sub manuf order needed to get components for parent manufacturing order.
 *
 * @param productionOrder Initialized production order with no manufacturing order.
 * @param billOfMaterial the bill of material of the parent manufacturing order
 * @param qtyRequested the quantity requested of the parent manufacturing order.
 * @param startDate startDate of creation
 * @param saleOrder a sale order
 * @return the updated production order with all generated manufacturing orders.
 * @throws AxelorException
 */
protected ProductionOrder generateManufOrders(ProductionOrder productionOrder, BillOfMaterial billOfMaterial, BigDecimal qtyRequested, LocalDateTime startDate, SaleOrder saleOrder) throws AxelorException {
    List<BillOfMaterial> childBomList = new ArrayList<>();
    childBomList.add(billOfMaterial);
    // prevent infinite loop
    int depth = 0;
    while (!childBomList.isEmpty()) {
        if (depth >= 100) {
            throw new AxelorException(TraceBackRepository.CATEGORY_CONFIGURATION_ERROR, I18n.get(IExceptionMessage.CHILD_BOM_TOO_MANY_ITERATION));
        }
        List<BillOfMaterial> tempChildBomList = new ArrayList<>();
        for (BillOfMaterial childBom : childBomList) {
            productionOrder = productionOrderService.addManufOrder(productionOrder, childBom.getProduct(), childBom, qtyRequested.multiply(childBom.getQty()), startDate, null, saleOrder, ManufOrderService.ORIGIN_TYPE_SALE_ORDER);
            tempChildBomList.addAll(childBom.getBillOfMaterialSet().stream().filter(BillOfMaterial::getDefineSubBillOfMaterial).collect(Collectors.toList()));
        }
        childBomList.clear();
        childBomList.addAll(tempChildBomList);
        tempChildBomList.clear();
        depth++;
    }
    return productionOrder;
}
Also used : BillOfMaterial(com.axelor.apps.production.db.BillOfMaterial) AxelorException(com.axelor.exception.AxelorException) ArrayList(java.util.ArrayList)

Example 24 with BillOfMaterial

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

the class ProductionOrderSaleOrderServiceImpl method generateManufOrders.

@Override
public ProductionOrder generateManufOrders(ProductionOrder productionOrder, SaleOrderLine saleOrderLine) throws AxelorException {
    Product product = saleOrderLine.getProduct();
    if (saleOrderLine.getSaleSupplySelect() == ProductRepository.SALE_SUPPLY_PRODUCE && product != null && product.getProductTypeSelect().equals(ProductRepository.PRODUCT_TYPE_STORABLE)) {
        BillOfMaterial billOfMaterial = saleOrderLine.getBillOfMaterial();
        if (billOfMaterial == null) {
            billOfMaterial = product.getDefaultBillOfMaterial();
        }
        if (billOfMaterial == null && product.getParentProduct() != null) {
            billOfMaterial = product.getParentProduct().getDefaultBillOfMaterial();
        }
        if (billOfMaterial == null) {
            throw new AxelorException(saleOrderLine, TraceBackRepository.CATEGORY_CONFIGURATION_ERROR, I18n.get(IExceptionMessage.PRODUCTION_ORDER_SALES_ORDER_NO_BOM), product.getName(), product.getCode());
        }
        if (billOfMaterial.getProdProcess() == null) {
            return null;
        }
        Unit unit = saleOrderLine.getProduct().getUnit();
        BigDecimal qty = saleOrderLine.getQty();
        if (unit != null && !unit.equals(saleOrderLine.getUnit())) {
            qty = unitConversionService.convert(saleOrderLine.getUnit(), unit, qty, qty.scale(), saleOrderLine.getProduct());
        }
        return generateManufOrders(productionOrder, billOfMaterial, qty, LocalDateTime.now(), saleOrderLine.getSaleOrder());
    }
    return null;
}
Also used : BillOfMaterial(com.axelor.apps.production.db.BillOfMaterial) AxelorException(com.axelor.exception.AxelorException) Product(com.axelor.apps.base.db.Product) Unit(com.axelor.apps.base.db.Unit) BigDecimal(java.math.BigDecimal)

Example 25 with BillOfMaterial

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

the class ProductionOrderWizardServiceImpl method validate.

@Override
@SuppressWarnings("unchecked")
public Long validate(Context context) throws AxelorException {
    Map<String, Object> bomContext = (Map<String, Object>) context.get("billOfMaterial");
    BillOfMaterial billOfMaterial = billOfMaterialRepo.find(((Integer) bomContext.get("id")).longValue());
    BigDecimal qty = new BigDecimal((String) context.get("qty"));
    Product product = null;
    if (context.get("product") != null) {
        Map<String, Object> productContext = (Map<String, Object>) context.get("product");
        product = productRepo.find(((Integer) productContext.get("id")).longValue());
    } else {
        product = billOfMaterial.getProduct();
    }
    ZonedDateTime startDateT;
    if (context.containsKey("_startDate") && context.get("_startDate") != null) {
        startDateT = ZonedDateTime.parse((CharSequence) context.get("_startDate"), DateTimeFormatter.ISO_INSTANT.withZone(ZoneId.systemDefault()));
    } else {
        startDateT = appProductionService.getTodayDateTime();
    }
    ProductionOrder productionOrder = productionOrderService.generateProductionOrder(product, billOfMaterial, qty, startDateT.toLocalDateTime());
    if (productionOrder != null) {
        return productionOrder.getId();
    } else {
        throw new AxelorException(TraceBackRepository.CATEGORY_CONFIGURATION_ERROR, I18n.get(IExceptionMessage.PRODUCTION_ORDER_2));
    }
}
Also used : BillOfMaterial(com.axelor.apps.production.db.BillOfMaterial) AxelorException(com.axelor.exception.AxelorException) ZonedDateTime(java.time.ZonedDateTime) Product(com.axelor.apps.base.db.Product) Map(java.util.Map) BigDecimal(java.math.BigDecimal) ProductionOrder(com.axelor.apps.production.db.ProductionOrder)

Aggregations

BillOfMaterial (com.axelor.apps.production.db.BillOfMaterial)36 Product (com.axelor.apps.base.db.Product)19 BigDecimal (java.math.BigDecimal)16 AxelorException (com.axelor.exception.AxelorException)15 Transactional (com.google.inject.persist.Transactional)11 ProdProduct (com.axelor.apps.production.db.ProdProduct)10 ArrayList (java.util.ArrayList)8 ProdResidualProduct (com.axelor.apps.production.db.ProdResidualProduct)7 BillOfMaterialService (com.axelor.apps.production.service.BillOfMaterialService)7 Unit (com.axelor.apps.base.db.Unit)4 ProductRepository (com.axelor.apps.base.db.repo.ProductRepository)4 ProdProcess (com.axelor.apps.production.db.ProdProcess)4 ProdProcessLine (com.axelor.apps.production.db.ProdProcessLine)4 ProductionOrder (com.axelor.apps.production.db.ProductionOrder)4 AppProductionService (com.axelor.apps.production.service.app.AppProductionService)4 ProductCompanyService (com.axelor.apps.base.service.ProductCompanyService)3 AppBaseService (com.axelor.apps.base.service.app.AppBaseService)3 ManufOrder (com.axelor.apps.production.db.ManufOrder)3 UnitCostCalcLine (com.axelor.apps.production.db.UnitCostCalcLine)3 BillOfMaterialRepository (com.axelor.apps.production.db.repo.BillOfMaterialRepository)3