Search in sources :

Example 1 with ConfiguratorProdProcess

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

the class ConfiguratorProdProcessServiceImpl method createProdProcessHeader.

/**
 * Instantiate a new prod process and set the right attributes.
 */
protected ProdProcess createProdProcessHeader(ConfiguratorProdProcess confProdProcess, String code, StockLocation stockLocation, StockLocation producedProductStockLocation, StockLocation workshopStockLocation, Product product) {
    ProdProcess prodProcess = new ProdProcess();
    prodProcess.setName(confProdProcess.getName());
    prodProcess.setCompany(confProdProcess.getCompany());
    prodProcess.setStatusSelect(confProdProcess.getStatusSelect());
    prodProcess.setCode(code);
    prodProcess.setStockLocation(stockLocation);
    prodProcess.setProducedProductStockLocation(producedProductStockLocation);
    prodProcess.setWorkshopStockLocation(workshopStockLocation);
    prodProcess.setProduct(product);
    return prodProcessRepository.save(prodProcess);
}
Also used : ConfiguratorProdProcess(com.axelor.apps.production.db.ConfiguratorProdProcess) ProdProcess(com.axelor.apps.production.db.ProdProcess)

Example 2 with ConfiguratorProdProcess

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

the class ConfiguratorProdProcessServiceImpl method generateProdProcessService.

@Override
public ProdProcess generateProdProcessService(ConfiguratorProdProcess confProdProcess, JsonContext attributes, Product product) throws AxelorException {
    if (confProdProcess == null) {
        return null;
    }
    String code;
    StockLocation stockLocation;
    StockLocation producedProductStockLocation;
    StockLocation workshopStockLocation;
    if (confProdProcess.getDefCodeAsFormula()) {
        code = String.valueOf(configuratorService.computeFormula(confProdProcess.getCodeFormula(), attributes));
    } else {
        code = confProdProcess.getCode();
    }
    if (confProdProcess.getDefStockLocationAsFormula()) {
        stockLocation = (StockLocation) configuratorService.computeFormula(confProdProcess.getStockLocationFormula(), attributes);
    } else {
        stockLocation = confProdProcess.getStockLocation();
    }
    if (confProdProcess.getDefProducedProductStockLocationAsFormula()) {
        producedProductStockLocation = (StockLocation) configuratorService.computeFormula(confProdProcess.getProducedProductStockLocationFormula(), attributes);
    } else {
        producedProductStockLocation = confProdProcess.getProducedProductStockLocation();
    }
    if (confProdProcess.getDefWorkshopStockLocationAsFormula()) {
        workshopStockLocation = (StockLocation) configuratorService.computeFormula(confProdProcess.getWorkshopStockLocationFormula(), attributes);
    } else {
        workshopStockLocation = confProdProcess.getWorkshopStockLocation();
    }
    ProdProcess prodProcess = createProdProcessHeader(confProdProcess, code, stockLocation, producedProductStockLocation, workshopStockLocation, product);
    List<ConfiguratorProdProcessLine> confLines = confProdProcess.getConfiguratorProdProcessLineList();
    if (confLines != null) {
        for (ConfiguratorProdProcessLine confLine : confLines) {
            prodProcess.addProdProcessLineListItem(confProdProcessLineService.generateProdProcessLine(confLine, attributes));
        }
    }
    return prodProcess;
}
Also used : StockLocation(com.axelor.apps.stock.db.StockLocation) ConfiguratorProdProcess(com.axelor.apps.production.db.ConfiguratorProdProcess) ProdProcess(com.axelor.apps.production.db.ProdProcess) ConfiguratorProdProcessLine(com.axelor.apps.production.db.ConfiguratorProdProcessLine)

Example 3 with ConfiguratorProdProcess

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

the class ConfiguratorCreatorImportServiceProductionImpl method updateAttributeNameInFormulas.

/**
 * Update attribute name in formulas for a configurator bom.
 *
 * @param configuratorBom
 * @param oldName
 * @param newName
 * @param counter used to count the recursive call.
 * @throws AxelorException if we got too many recursive call.
 */
protected void updateAttributeNameInFormulas(ConfiguratorBOM configuratorBom, String oldName, String newName, int counter) throws AxelorException {
    if (counter > MAX_DEPTH) {
        throw new AxelorException(TraceBackRepository.CATEGORY_INCONSISTENCY, I18n.get(IExceptionMessage.CONFIGURATOR_BOM_IMPORT_TOO_MANY_CALLS));
    }
    updateAllFormulaFields(configuratorBom, oldName, newName);
    ConfiguratorProdProcess configuratorProdProcess = configuratorBom.getConfiguratorProdProcess();
    if (configuratorProdProcess != null) {
        updateAttributeNameInFormulas(configuratorBom.getConfiguratorProdProcess(), oldName, newName);
    }
    // recursive call for child BOMs
    List<ConfiguratorBOM> childConfiguratorBomList = Beans.get(ConfiguratorBOMRepository.class).all().filter("self.parentConfiguratorBOM.id = :parentId").bind("parentId", configuratorBom.getId()).fetch();
    if (childConfiguratorBomList != null) {
        for (ConfiguratorBOM childConfiguratorBom : childConfiguratorBomList) {
            updateAttributeNameInFormulas(childConfiguratorBom, oldName, newName, counter + 1);
        }
    }
}
Also used : AxelorException(com.axelor.exception.AxelorException) ConfiguratorBOM(com.axelor.apps.production.db.ConfiguratorBOM) ConfiguratorProdProcess(com.axelor.apps.production.db.ConfiguratorProdProcess)

Aggregations

ConfiguratorProdProcess (com.axelor.apps.production.db.ConfiguratorProdProcess)3 ProdProcess (com.axelor.apps.production.db.ProdProcess)2 ConfiguratorBOM (com.axelor.apps.production.db.ConfiguratorBOM)1 ConfiguratorProdProcessLine (com.axelor.apps.production.db.ConfiguratorProdProcessLine)1 StockLocation (com.axelor.apps.stock.db.StockLocation)1 AxelorException (com.axelor.exception.AxelorException)1