Search in sources :

Example 1 with ProdProcess

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

the class ProdProcessController method changeProdProcessListOutsourcing.

public void changeProdProcessListOutsourcing(ActionRequest request, ActionResponse response) throws AxelorException {
    ProdProcess prodProcess = request.getContext().asType(ProdProcess.class);
    if (prodProcess.getProdProcessLineList() != null) {
        Beans.get(ProdProcessService.class).changeProdProcessListOutsourcing(prodProcess);
    }
    response.setValue("prodProcessLineList", prodProcess.getProdProcessLineList());
    response.setHidden("prodProcessLineList.outsourcing", !prodProcess.getOutsourcing());
    if (!prodProcess.getOutsourcing()) {
        response.setValue("generatePurchaseOrderOnMoPlanning", false);
        response.setValue("subcontractors", null);
        response.setValue("outsourcingStockLocation", null);
    }
}
Also used : ProdProcessService(com.axelor.apps.production.service.ProdProcessService) ProdProcess(com.axelor.apps.production.db.ProdProcess)

Example 2 with ProdProcess

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

the class ProdProcessController method generateNewVersion.

public void generateNewVersion(ActionRequest request, ActionResponse response) {
    ProdProcess prodProcess = Beans.get(ProdProcessRepository.class).find(request.getContext().asType(ProdProcess.class).getId());
    ProdProcess copy = Beans.get(ProdProcessService.class).generateNewVersion(prodProcess);
    response.setView(ActionView.define("Production process").model(ProdProcess.class.getName()).add("form", "prod-process-form").add("grid", "prod-process-grid").param("search-filters", "prod-process-filters").context("_showRecord", String.valueOf(copy.getId())).map());
}
Also used : ProdProcessRepository(com.axelor.apps.production.db.repo.ProdProcessRepository) ProdProcessService(com.axelor.apps.production.service.ProdProcessService) ProdProcess(com.axelor.apps.production.db.ProdProcess)

Example 3 with ProdProcess

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

the class ProdProcessService method getLatestProdProcessVersion.

public int getLatestProdProcessVersion(ProdProcess prodProcess, int latestVersion, boolean deep) {
    List<ProdProcess> prodProcessSet = Lists.newArrayList();
    ProdProcess up = prodProcess;
    Long previousId = Long.valueOf(0);
    do {
        prodProcessSet = prodProcessRepo.all().filter("self.originalProdProcess = :origin AND self.id != :id").bind("origin", up).bind("id", previousId).order("-versionNumber").fetch();
        if (!prodProcessSet.isEmpty()) {
            latestVersion = (prodProcessSet.get(0).getVersionNumber() > latestVersion) ? prodProcessSet.get(0).getVersionNumber() : latestVersion;
            for (ProdProcess prodProcessIterator : prodProcessSet) {
                int search = this.getLatestProdProcessVersion(prodProcessIterator, latestVersion, false);
                latestVersion = (search > latestVersion) ? search : latestVersion;
            }
        }
        previousId = up.getId();
        up = up.getOriginalProdProcess();
    } while (up != null && deep);
    return latestVersion;
}
Also used : ProdProcess(com.axelor.apps.production.db.ProdProcess)

Example 4 with ProdProcess

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

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

the class ProdProcessController method checkOriginalProductionProcess.

public void checkOriginalProductionProcess(ActionRequest request, ActionResponse response) {
    ProdProcessRepository prodProcessRepository = Beans.get(ProdProcessRepository.class);
    ProdProcess prodProcess = prodProcessRepository.find(request.getContext().asType(ProdProcess.class).getId());
    List<ProdProcess> prodProcessSet = Lists.newArrayList();
    prodProcessSet = prodProcessRepository.all().filter("self.originalProdProcess = :origin").bind("origin", prodProcess).fetch();
    String message;
    if (!prodProcessSet.isEmpty()) {
        String existingVersions = "";
        for (ProdProcess prodProcessVersion : prodProcessSet) {
            existingVersions += "<li>" + prodProcessVersion.getFullName() + "</li>";
        }
        message = String.format(I18n.get("This production process already has the following versions : <br/><ul> %s </ul>And these versions may also have ones. Do you still wish to create a new one ?"), existingVersions);
    } else {
        message = I18n.get("Do you really wish to create a new version of this production process ?");
    }
    response.setAlert(message);
}
Also used : ProdProcessRepository(com.axelor.apps.production.db.repo.ProdProcessRepository) ProdProcess(com.axelor.apps.production.db.ProdProcess)

Aggregations

ProdProcess (com.axelor.apps.production.db.ProdProcess)12 ProdProcessService (com.axelor.apps.production.service.ProdProcessService)3 Transactional (com.google.inject.persist.Transactional)3 BillOfMaterial (com.axelor.apps.production.db.BillOfMaterial)2 ConfiguratorProdProcess (com.axelor.apps.production.db.ConfiguratorProdProcess)2 ProdProcessLine (com.axelor.apps.production.db.ProdProcessLine)2 ProdProcessRepository (com.axelor.apps.production.db.repo.ProdProcessRepository)2 AxelorException (com.axelor.exception.AxelorException)2 Product (com.axelor.apps.base.db.Product)1 Unit (com.axelor.apps.base.db.Unit)1 ProductRepository (com.axelor.apps.base.db.repo.ProductRepository)1 ConfiguratorBOM (com.axelor.apps.production.db.ConfiguratorBOM)1 ConfiguratorProdProcessLine (com.axelor.apps.production.db.ConfiguratorProdProcessLine)1 ManufOrder (com.axelor.apps.production.db.ManufOrder)1 StockLocation (com.axelor.apps.stock.db.StockLocation)1 BigDecimal (java.math.BigDecimal)1