Search in sources :

Example 86 with Product

use of com.axelor.apps.base.db.Product in project axelor-open-suite by axelor.

the class ConfiguratorServiceProductionImpl method generate.

/**
 * In this implementation, we also create a bill of materials.
 *
 * @param configurator
 * @param jsonAttributes
 * @param jsonIndicators
 * @throws AxelorException
 */
@Override
@Transactional(rollbackOn = { Exception.class })
public void generate(Configurator configurator, JsonContext jsonAttributes, JsonContext jsonIndicators) throws AxelorException {
    super.generate(configurator, jsonAttributes, jsonIndicators);
    ConfiguratorBOM configuratorBOM = configurator.getConfiguratorCreator().getConfiguratorBom();
    if (configuratorBOM != null) {
        Product generatedProduct = configurator.getProduct();
        Beans.get(ConfiguratorBomService.class).generateBillOfMaterial(configuratorBOM, jsonAttributes, 0, generatedProduct).ifPresent(generatedProduct::setDefaultBillOfMaterial);
    }
}
Also used : ConfiguratorBOM(com.axelor.apps.production.db.ConfiguratorBOM) Product(com.axelor.apps.base.db.Product) Transactional(com.google.inject.persist.Transactional)

Example 87 with Product

use of com.axelor.apps.base.db.Product in project axelor-open-suite by axelor.

the class ConfiguratorBomServiceImpl method generateBillOfMaterial.

@Override
@Transactional(rollbackOn = { Exception.class })
public Optional<BillOfMaterial> generateBillOfMaterial(ConfiguratorBOM configuratorBOM, JsonContext attributes, int level, Product generatedProduct) throws AxelorException {
    level++;
    if (level > MAX_LEVEL) {
        throw new AxelorException(TraceBackRepository.CATEGORY_CONFIGURATION_ERROR, I18n.get(IExceptionMessage.CONFIGURATOR_BOM_TOO_MANY_CALLS));
    }
    String name;
    Product product;
    BigDecimal qty;
    Unit unit;
    ProdProcess prodProcess;
    if (!checkConditions(configuratorBOM, attributes)) {
        return Optional.empty();
    }
    if (configuratorBOM.getDefNameAsFormula()) {
        name = (String) configuratorService.computeFormula(configuratorBOM.getNameFormula(), attributes);
    } else {
        name = configuratorBOM.getName();
    }
    if (configuratorBOM.getDefProductFromConfigurator()) {
        if (generatedProduct == null) {
            throw new AxelorException(TraceBackRepository.CATEGORY_CONFIGURATION_ERROR, I18n.get(IExceptionMessage.CONFIGURATOR_BOM_IMPORT_GENERATED_PRODUCT_NULL));
        }
        product = generatedProduct;
    } else if (configuratorBOM.getDefProductAsFormula()) {
        product = (Product) configuratorService.computeFormula(configuratorBOM.getProductFormula(), attributes);
        if (product == null) {
            throw new AxelorException(TraceBackRepository.CATEGORY_CONFIGURATION_ERROR, I18n.get(IExceptionMessage.CONFIGURATOR_BOM_IMPORT_FORMULA_PRODUCT_NULL));
        }
        product = Beans.get(ProductRepository.class).find(product.getId());
    } else {
        if (configuratorBOM.getProduct() == null) {
            throw new AxelorException(TraceBackRepository.CATEGORY_CONFIGURATION_ERROR, I18n.get(IExceptionMessage.CONFIGURATOR_BOM_IMPORT_FILLED_PRODUCT_NULL));
        }
        product = configuratorBOM.getProduct();
    }
    if (configuratorBOM.getDefQtyAsFormula()) {
        qty = new BigDecimal(configuratorService.computeFormula(configuratorBOM.getQtyFormula(), attributes).toString());
    } else {
        qty = configuratorBOM.getQty();
    }
    if (configuratorBOM.getDefUnitAsFormula()) {
        unit = (Unit) configuratorService.computeFormula(configuratorBOM.getUnitFormula(), attributes);
        if (unit != null) {
            unit = Beans.get(UnitRepository.class).find(unit.getId());
        }
    } else {
        unit = configuratorBOM.getUnit();
    }
    if (configuratorBOM.getDefProdProcessAsFormula()) {
        prodProcess = (ProdProcess) configuratorService.computeFormula(configuratorBOM.getProdProcessFormula(), attributes);
        if (prodProcess != null) {
            prodProcess = Beans.get(ProdProcessRepository.class).find(prodProcess.getId());
        }
    } else if (configuratorBOM.getDefProdProcessAsConfigurator()) {
        prodProcess = confProdProcessService.generateProdProcessService(configuratorBOM.getConfiguratorProdProcess(), attributes, product);
    } else {
        prodProcess = configuratorBOM.getProdProcess();
    }
    BillOfMaterial billOfMaterial = new BillOfMaterial();
    billOfMaterial.setCompany(configuratorBOM.getCompany());
    billOfMaterial.setName(name);
    billOfMaterial.setProduct(product);
    billOfMaterial.setQty(qty);
    billOfMaterial.setUnit(unit);
    billOfMaterial.setProdProcess(prodProcess);
    billOfMaterial.setStatusSelect(configuratorBOM.getStatusSelect());
    billOfMaterial.setDefineSubBillOfMaterial(configuratorBOM.getDefineSubBillOfMaterial());
    if (configuratorBOM.getConfiguratorBomList() != null) {
        for (ConfiguratorBOM confBomChild : configuratorBOM.getConfiguratorBomList()) {
            generateBillOfMaterial(confBomChild, attributes, level, generatedProduct).ifPresent(billOfMaterial::addBillOfMaterialSetItem);
        }
    }
    billOfMaterial = billOfMaterialRepository.save(billOfMaterial);
    configuratorBOM.setBillOfMaterialId(billOfMaterial.getId());
    configuratorBOMRepo.save(configuratorBOM);
    return Optional.of(billOfMaterial);
}
Also used : AxelorException(com.axelor.exception.AxelorException) BillOfMaterial(com.axelor.apps.production.db.BillOfMaterial) ProductRepository(com.axelor.apps.base.db.repo.ProductRepository) Product(com.axelor.apps.base.db.Product) ConfiguratorBOM(com.axelor.apps.production.db.ConfiguratorBOM) ProdProcess(com.axelor.apps.production.db.ProdProcess) Unit(com.axelor.apps.base.db.Unit) BigDecimal(java.math.BigDecimal) Transactional(com.google.inject.persist.Transactional)

Example 88 with Product

use of com.axelor.apps.base.db.Product in project axelor-open-suite by axelor.

the class MrpForecastProductionServiceImpl method generateMrpForecast.

@Override
public void generateMrpForecast(Period period, List<LinkedHashMap<String, Object>> mrpForecastList, StockLocation stockLocation, int technicalOrigin) {
    LocalDate forecastDate = period.getToDate();
    for (LinkedHashMap<String, Object> mrpForecastItem : mrpForecastList) {
        Long id = mrpForecastItem.get("id") != null ? Long.parseLong(mrpForecastItem.get("id").toString()) : null;
        BigDecimal qty = new BigDecimal(mrpForecastItem.get("qty").toString());
        @SuppressWarnings("unchecked") LinkedHashMap<String, Object> productMap = (LinkedHashMap<String, Object>) mrpForecastItem.get("product");
        Product product = productRepo.find(Long.parseLong(productMap.get("id").toString()));
        if (id != null && qty.compareTo(BigDecimal.ZERO) == 0) {
            this.RemoveMrpForecast(id);
        } else if (qty.compareTo(BigDecimal.ZERO) != 0) {
            this.createMrpForecast(id, forecastDate, product, stockLocation, qty, technicalOrigin);
        }
    }
}
Also used : Product(com.axelor.apps.base.db.Product) LocalDate(java.time.LocalDate) BigDecimal(java.math.BigDecimal) LinkedHashMap(java.util.LinkedHashMap)

Example 89 with Product

use of com.axelor.apps.base.db.Product in project axelor-open-suite by axelor.

the class MrpLineServiceProductionImpl method generateManufacturingProposal.

@Transactional(rollbackOn = { Exception.class })
protected void generateManufacturingProposal(MrpLine mrpLine) throws AxelorException {
    Product product = mrpLine.getProduct();
    ManufOrder manufOrder = manufOrderService.generateManufOrder(product, mrpLine.getQty(), ManufOrderService.DEFAULT_PRIORITY, ManufOrderService.IS_TO_INVOICE, null, mrpLine.getMaturityDate().atStartOfDay(), null, ManufOrderServiceImpl.ORIGIN_TYPE_MRP);
    // correct day
    linkToOrder(mrpLine, manufOrder);
}
Also used : Product(com.axelor.apps.base.db.Product) ManufOrder(com.axelor.apps.production.db.ManufOrder) Transactional(com.google.inject.persist.Transactional)

Example 90 with Product

use of com.axelor.apps.base.db.Product in project axelor-open-suite by axelor.

the class ProductionProductStockLocationServiceImpl method computeIndicators.

@Override
public Map<String, Object> computeIndicators(Long productId, Long companyId, Long stockLocationId) throws AxelorException {
    Map<String, Object> map = super.computeIndicators(productId, companyId, stockLocationId);
    Product product = productRepository.find(productId);
    Company company = companyRepository.find(companyId);
    StockLocation stockLocation = stockLocationRepository.find(stockLocationId);
    int scale = appBaseService.getNbDecimalDigitForQty();
    BigDecimal consumeManufOrderQty = this.getConsumeManufOrderQty(product, company, stockLocation).setScale(scale, RoundingMode.HALF_UP);
    BigDecimal availableQty = (BigDecimal) map.getOrDefault("$availableQty", BigDecimal.ZERO.setScale(scale, RoundingMode.HALF_UP));
    map.put("$buildingQty", this.getBuildingQty(product, company, stockLocation).setScale(scale, RoundingMode.HALF_UP));
    map.put("$consumeManufOrderQty", consumeManufOrderQty);
    map.put("$missingManufOrderQty", BigDecimal.ZERO.max(consumeManufOrderQty.subtract(availableQty)).setScale(scale, RoundingMode.HALF_UP));
    return map;
}
Also used : Company(com.axelor.apps.base.db.Company) StockLocation(com.axelor.apps.stock.db.StockLocation) Product(com.axelor.apps.base.db.Product) BigDecimal(java.math.BigDecimal)

Aggregations

Product (com.axelor.apps.base.db.Product)189 BigDecimal (java.math.BigDecimal)91 AxelorException (com.axelor.exception.AxelorException)70 Transactional (com.google.inject.persist.Transactional)45 ArrayList (java.util.ArrayList)38 StockMoveLine (com.axelor.apps.stock.db.StockMoveLine)33 Company (com.axelor.apps.base.db.Company)24 SaleOrderLine (com.axelor.apps.sale.db.SaleOrderLine)24 Unit (com.axelor.apps.base.db.Unit)23 ProductRepository (com.axelor.apps.base.db.repo.ProductRepository)23 HashMap (java.util.HashMap)20 BillOfMaterial (com.axelor.apps.production.db.BillOfMaterial)19 StockLocation (com.axelor.apps.stock.db.StockLocation)19 List (java.util.List)19 ProdProduct (com.axelor.apps.production.db.ProdProduct)18 StockLocationLine (com.axelor.apps.stock.db.StockLocationLine)18 LocalDate (java.time.LocalDate)18 PurchaseOrderLine (com.axelor.apps.purchase.db.PurchaseOrderLine)16 StockMove (com.axelor.apps.stock.db.StockMove)16 Map (java.util.Map)16