Search in sources :

Example 1 with TempBomTree

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

the class ProductController method openProductTree.

public void openProductTree(ActionRequest request, ActionResponse response) {
    Product product = request.getContext().asType(Product.class);
    product = Beans.get(ProductRepository.class).find(product.getId());
    TempBomTree tempBomTree = Beans.get(BillOfMaterialService.class).generateTree(product.getDefaultBillOfMaterial(), true);
    response.setView(ActionView.define(I18n.get("Bill of materials")).model(TempBomTree.class.getName()).add("tree", "bill-of-material-tree").context("_tempBomTreeId", tempBomTree.getId()).map());
}
Also used : TempBomTree(com.axelor.apps.production.db.TempBomTree) BillOfMaterialService(com.axelor.apps.production.service.BillOfMaterialService) Product(com.axelor.apps.base.db.Product)

Example 2 with TempBomTree

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

the class BillOfMaterialServiceImpl method removeInvalidTree.

@Transactional
public void removeInvalidTree(List<Long> validBomIds, BillOfMaterial bom) {
    List<TempBomTree> invalidBomTrees = tempBomTreeRepo.all().filter("self.bom.id not in (?1) and self.parentBom = ?2", validBomIds, bom).fetch();
    log.debug("Invalid bom trees: {}", invalidBomTrees);
    if (!invalidBomTrees.isEmpty()) {
        List<TempBomTree> childBomTrees = tempBomTreeRepo.all().filter("self.parent in (?1)", invalidBomTrees).fetch();
        for (TempBomTree childBomTree : childBomTrees) {
            childBomTree.setParent(null);
            tempBomTreeRepo.save(childBomTree);
        }
    }
    for (TempBomTree invalidBomTree : invalidBomTrees) {
        tempBomTreeRepo.remove(invalidBomTree);
    }
}
Also used : TempBomTree(com.axelor.apps.production.db.TempBomTree) Transactional(com.google.inject.persist.Transactional)

Example 3 with TempBomTree

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

the class BillOfMaterialController method openBomTree.

public void openBomTree(ActionRequest request, ActionResponse response) {
    BillOfMaterial billOfMaterial = request.getContext().asType(BillOfMaterial.class);
    billOfMaterial = Beans.get(BillOfMaterialRepository.class).find(billOfMaterial.getId());
    TempBomTree tempBomTree = Beans.get(BillOfMaterialService.class).generateTree(billOfMaterial, false);
    response.setView(ActionView.define(I18n.get("Bill of materials")).model(TempBomTree.class.getName()).add("tree", "bill-of-material-tree").context("_tempBomTreeId", tempBomTree.getId()).map());
}
Also used : BillOfMaterial(com.axelor.apps.production.db.BillOfMaterial) TempBomTree(com.axelor.apps.production.db.TempBomTree) BillOfMaterialService(com.axelor.apps.production.service.BillOfMaterialService)

Example 4 with TempBomTree

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

the class BillOfMaterialServiceImpl method getBomTree.

@Transactional
public TempBomTree getBomTree(BillOfMaterial bom, BillOfMaterial parentBom, TempBomTree parent, boolean useProductDefaultBom) {
    TempBomTree bomTree;
    if (parentBom == null) {
        bomTree = tempBomTreeRepo.all().filter("self.bom = ?1 and self.parentBom = null", bom).fetchOne();
    } else {
        bomTree = tempBomTreeRepo.all().filter("self.bom = ?1 and self.parentBom = ?2", bom, parentBom).fetchOne();
    }
    if (bomTree == null) {
        bomTree = new TempBomTree();
    }
    bomTree.setProdProcess(bom.getProdProcess());
    bomTree.setProduct(bom.getProduct());
    bomTree.setQty(bom.getQty());
    bomTree.setUnit(bom.getUnit());
    bomTree.setParentBom(parentBom);
    bomTree.setParent(parent);
    bomTree.setBom(bom);
    bomTree = tempBomTreeRepo.save(bomTree);
    processedBom.add(bom.getId());
    List<Long> validBomIds = processChildBom(bom, bomTree, useProductDefaultBom);
    validBomIds.add(0L);
    removeInvalidTree(validBomIds, bom);
    return bomTree;
}
Also used : TempBomTree(com.axelor.apps.production.db.TempBomTree) Transactional(com.google.inject.persist.Transactional)

Aggregations

TempBomTree (com.axelor.apps.production.db.TempBomTree)4 BillOfMaterialService (com.axelor.apps.production.service.BillOfMaterialService)2 Transactional (com.google.inject.persist.Transactional)2 Product (com.axelor.apps.base.db.Product)1 BillOfMaterial (com.axelor.apps.production.db.BillOfMaterial)1