Search in sources :

Example 31 with BillOfMaterial

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

the class BillOfMaterialController method checkOriginalBillOfMaterial.

public void checkOriginalBillOfMaterial(ActionRequest request, ActionResponse response) {
    BillOfMaterialRepository billOfMaterialRepository = Beans.get(BillOfMaterialRepository.class);
    BillOfMaterial billOfMaterial = billOfMaterialRepository.find(request.getContext().asType(BillOfMaterial.class).getId());
    List<BillOfMaterial> BillOfMaterialSet = Lists.newArrayList();
    BillOfMaterialSet = billOfMaterialRepository.all().filter("self.originalBillOfMaterial = :origin").bind("origin", billOfMaterial).fetch();
    String message;
    if (!BillOfMaterialSet.isEmpty()) {
        String existingVersions = "";
        for (BillOfMaterial billOfMaterialVersion : BillOfMaterialSet) {
            existingVersions += "<li>" + billOfMaterialVersion.getFullName() + "</li>";
        }
        message = String.format(I18n.get("This bill of materials 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 bill of materials ?");
    }
    response.setAlert(message);
}
Also used : BillOfMaterial(com.axelor.apps.production.db.BillOfMaterial) BillOfMaterialRepository(com.axelor.apps.production.db.repo.BillOfMaterialRepository)

Example 32 with BillOfMaterial

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

the class BillOfMaterialController method addRawMaterials.

public void addRawMaterials(ActionRequest request, ActionResponse response) {
    try {
        BillOfMaterial billOfMaterial = request.getContext().asType(BillOfMaterial.class);
        @SuppressWarnings("unchecked") ArrayList<LinkedHashMap<String, Object>> rawMaterials = (ArrayList<LinkedHashMap<String, Object>>) request.getContext().get("rawMaterials");
        if (rawMaterials != null && !rawMaterials.isEmpty()) {
            Beans.get(BillOfMaterialService.class).addRawMaterials(billOfMaterial.getId(), rawMaterials);
            response.setReload(true);
        }
    } catch (Exception e) {
        TraceBackService.trace(response, e);
    }
}
Also used : BillOfMaterial(com.axelor.apps.production.db.BillOfMaterial) BillOfMaterialService(com.axelor.apps.production.service.BillOfMaterialService) ArrayList(java.util.ArrayList) AxelorException(com.axelor.exception.AxelorException) LinkedHashMap(java.util.LinkedHashMap)

Example 33 with BillOfMaterial

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

the class UnitCostCalculationServiceImpl method assignProductLevel.

/**
 * Update the level of Bill of materials. The highest for each product (0: product with parent, 1:
 * product with a parent, 2: product with a parent that have a parent, ...)
 *
 * @param billOfMaterial
 * @param level
 */
protected void assignProductLevel(BillOfMaterial billOfMaterial, int level) {
    if (billOfMaterial.getBillOfMaterialSet() == null || billOfMaterial.getBillOfMaterialSet().isEmpty() || level > 100) {
        Product subProduct = billOfMaterial.getProduct();
        log.debug("Add of the sub product : {} for the level : {} ", subProduct.getFullName(), level);
        this.productMap.put(subProduct.getId(), this.getMaxLevel(subProduct, level));
    } else {
        level = level + 1;
        for (BillOfMaterial subBillOfMaterial : billOfMaterial.getBillOfMaterialSet()) {
            Product subProduct = subBillOfMaterial.getProduct();
            if (this.productMap.containsKey(subProduct.getId())) {
                this.assignProductLevel(subBillOfMaterial, level);
                if (hasValidBillOfMaterial(subProduct)) {
                    this.assignProductLevel(subProduct.getDefaultBillOfMaterial(), level);
                }
            }
        }
    }
}
Also used : BillOfMaterial(com.axelor.apps.production.db.BillOfMaterial) Product(com.axelor.apps.base.db.Product)

Example 34 with BillOfMaterial

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

the class MrpServiceProductionImpl method createProposalMrpLine.

@Override
@Transactional(rollbackOn = { Exception.class })
protected void createProposalMrpLine(Mrp mrp, Product product, MrpLineType mrpLineType, BigDecimal reorderQty, StockLocation stockLocation, LocalDate maturityDate, List<MrpLineOrigin> mrpLineOriginList, String relatedToSelectName) throws AxelorException {
    super.createProposalMrpLine(mrp, product, mrpLineType, reorderQty, stockLocation, maturityDate, mrpLineOriginList, relatedToSelectName);
    if (!Beans.get(AppProductionService.class).isApp("production")) {
        return;
    }
    BillOfMaterial defaultBillOfMaterial = product.getDefaultBillOfMaterial();
    if (mrpLineType.getElementSelect() == MrpLineTypeRepository.ELEMENT_MANUFACTURING_PROPOSAL && defaultBillOfMaterial != null) {
        MrpLineType manufProposalNeedMrpLineType = this.getMrpLineType(MrpLineTypeRepository.ELEMENT_MANUFACTURING_PROPOSAL_NEED);
        if (manufProposalNeedMrpLineType == null) {
            return;
        }
        for (BillOfMaterial billOfMaterial : defaultBillOfMaterial.getBillOfMaterialSet()) {
            Product subProduct = billOfMaterial.getProduct();
            if (this.isMrpProduct(subProduct)) {
                // TODO take the time to do the Manuf order (use machine planning)
                super.createProposalMrpLine(mrp, subProduct, manufProposalNeedMrpLineType, reorderQty.multiply(billOfMaterial.getQty()).setScale(appBaseService.getNbDecimalDigitForQty(), RoundingMode.HALF_UP), stockLocation, maturityDate, mrpLineOriginList, relatedToSelectName);
            }
        }
    }
}
Also used : BillOfMaterial(com.axelor.apps.production.db.BillOfMaterial) Product(com.axelor.apps.base.db.Product) ProdProduct(com.axelor.apps.production.db.ProdProduct) MrpLineType(com.axelor.apps.supplychain.db.MrpLineType) Transactional(com.google.inject.persist.Transactional)

Example 35 with BillOfMaterial

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

the class BillOfMaterialServiceImpl method createBomFromRawMaterial.

@Transactional
protected BillOfMaterial createBomFromRawMaterial(long productId, int priority) throws AxelorException {
    BillOfMaterial newBom = new BillOfMaterial();
    Product rawMaterial = productRepo.find(productId);
    newBom.setDefineSubBillOfMaterial(false);
    newBom.setPriority(priority);
    newBom.setProduct(rawMaterial);
    newBom.setQty(new BigDecimal(1));
    if (rawMaterial.getUnit() == null) {
        throw new AxelorException(TraceBackRepository.CATEGORY_CONFIGURATION_ERROR, I18n.get(IExceptionMessage.BOM_MISSING_UNIT_ON_PRODUCT), rawMaterial.getFullName());
    }
    newBom.setUnit(rawMaterial.getUnit());
    newBom.setWasteRate(BigDecimal.ZERO);
    newBom.setHasNoManageStock(false);
    billOfMaterialRepo.save(newBom);
    // need to save first cuz computeName uses the id.
    String name = this.computeName(newBom);
    newBom.setName(name);
    newBom.setFullName(name);
    return newBom;
}
Also used : BillOfMaterial(com.axelor.apps.production.db.BillOfMaterial) AxelorException(com.axelor.exception.AxelorException) Product(com.axelor.apps.base.db.Product) BigDecimal(java.math.BigDecimal) Transactional(com.google.inject.persist.Transactional)

Aggregations

BillOfMaterial (com.axelor.apps.production.db.BillOfMaterial)36 Product (com.axelor.apps.base.db.Product)19 BigDecimal (java.math.BigDecimal)16 AxelorException (com.axelor.exception.AxelorException)15 Transactional (com.google.inject.persist.Transactional)11 ProdProduct (com.axelor.apps.production.db.ProdProduct)10 ArrayList (java.util.ArrayList)8 ProdResidualProduct (com.axelor.apps.production.db.ProdResidualProduct)7 BillOfMaterialService (com.axelor.apps.production.service.BillOfMaterialService)7 Unit (com.axelor.apps.base.db.Unit)4 ProductRepository (com.axelor.apps.base.db.repo.ProductRepository)4 ProdProcess (com.axelor.apps.production.db.ProdProcess)4 ProdProcessLine (com.axelor.apps.production.db.ProdProcessLine)4 ProductionOrder (com.axelor.apps.production.db.ProductionOrder)4 AppProductionService (com.axelor.apps.production.service.app.AppProductionService)4 ProductCompanyService (com.axelor.apps.base.service.ProductCompanyService)3 AppBaseService (com.axelor.apps.base.service.app.AppBaseService)3 ManufOrder (com.axelor.apps.production.db.ManufOrder)3 UnitCostCalcLine (com.axelor.apps.production.db.UnitCostCalcLine)3 BillOfMaterialRepository (com.axelor.apps.production.db.repo.BillOfMaterialRepository)3