Search in sources :

Example 6 with ProductionOrder

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

the class ProductionOrderServiceBusinessImpl method generateProductionOrder.

@Transactional(rollbackOn = { Exception.class })
public ProductionOrder generateProductionOrder(Product product, BillOfMaterial billOfMaterial, BigDecimal qtyRequested, Project project, LocalDateTime startDate, LocalDateTime endDate, SaleOrder saleOrder) throws AxelorException {
    ProductionOrder productionOrder = this.createProductionOrder(saleOrder);
    productionOrder.setProject(project);
    this.addManufOrder(productionOrder, product, billOfMaterial, qtyRequested, startDate, endDate, saleOrder, ManufOrderService.ORIGIN_TYPE_OTHER);
    return productionOrderRepo.save(productionOrder);
}
Also used : ProductionOrder(com.axelor.apps.production.db.ProductionOrder) Transactional(com.google.inject.persist.Transactional)

Example 7 with ProductionOrder

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

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

the class ProductionOrderServiceImpl method generateProductionOrder.

/**
 * Generate a Production Order
 *
 * @param product Product must be passed in param because product can be different of bill of
 *     material product (Product variant)
 * @param billOfMaterial
 * @param qtyRequested
 * @param businessProject
 * @return
 * @throws AxelorException
 */
@Transactional(rollbackOn = { Exception.class })
public ProductionOrder generateProductionOrder(Product product, BillOfMaterial billOfMaterial, BigDecimal qtyRequested, LocalDateTime startDate) throws AxelorException {
    ProductionOrder productionOrder = this.createProductionOrder(null);
    this.addManufOrder(productionOrder, product, billOfMaterial, qtyRequested, startDate, null, null, ManufOrderService.ORIGIN_TYPE_OTHER);
    return productionOrderRepo.save(productionOrder);
}
Also used : ProductionOrder(com.axelor.apps.production.db.ProductionOrder) Transactional(com.google.inject.persist.Transactional)

Example 9 with ProductionOrder

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

ProductionOrder (com.axelor.apps.production.db.ProductionOrder)9 Transactional (com.google.inject.persist.Transactional)4 Product (com.axelor.apps.base.db.Product)3 BillOfMaterial (com.axelor.apps.production.db.BillOfMaterial)3 AppProductionService (com.axelor.apps.production.service.app.AppProductionService)3 AxelorException (com.axelor.exception.AxelorException)3 BigDecimal (java.math.BigDecimal)3 Company (com.axelor.apps.base.db.Company)1 Sequence (com.axelor.apps.base.db.Sequence)1 Unit (com.axelor.apps.base.db.Unit)1 ProductRepository (com.axelor.apps.base.db.repo.ProductRepository)1 ProductCompanyService (com.axelor.apps.base.service.ProductCompanyService)1 ProductVariantService (com.axelor.apps.base.service.ProductVariantService)1 UnitConversionService (com.axelor.apps.base.service.UnitConversionService)1 SequenceService (com.axelor.apps.base.service.administration.SequenceService)1 AppBaseService (com.axelor.apps.base.service.app.AppBaseService)1 ProductionOrderSaleOrderServiceBusinessImpl (com.axelor.apps.businessproduction.service.ProductionOrderSaleOrderServiceBusinessImpl)1 ManufOrder (com.axelor.apps.production.db.ManufOrder)1 OperationOrder (com.axelor.apps.production.db.OperationOrder)1 ProdProcess (com.axelor.apps.production.db.ProdProcess)1