Search in sources :

Example 1 with BillOfMaterial

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

the class UnitCostCalculationServiceImpl method calculationProductProcess.

@Transactional(rollbackOn = { Exception.class })
protected void calculationProductProcess(UnitCostCalculation unitCostCalculation, Product product) throws AxelorException {
    int level = this.productMap.get(product.getId()).intValue();
    log.debug("Unit cost price calculation for product : {}, level : {}", product.getCode(), level);
    int origin = unitCostCalculation.getAllBomLevels() ? CostSheetService.ORIGIN_BULK_UNIT_COST_CALCULATION : CostSheetService.ORIGIN_BILL_OF_MATERIAL;
    BillOfMaterial billOfMaterial = product.getDefaultBillOfMaterial();
    CostSheet costSheet = costSheetService.computeCostPrice(billOfMaterial, origin, unitCostCalculation);
    UnitCostCalcLine unitCostCalcLine = unitCostCalcLineService.createUnitCostCalcLine(product, billOfMaterial.getCompany(), level, costSheet);
    unitCostCalculation.addUnitCostCalcLineListItem(unitCostCalcLine);
    unitCostCalculationRepository.save(unitCostCalculation);
}
Also used : BillOfMaterial(com.axelor.apps.production.db.BillOfMaterial) UnitCostCalcLine(com.axelor.apps.production.db.UnitCostCalcLine) CostSheet(com.axelor.apps.production.db.CostSheet) Transactional(com.google.inject.persist.Transactional)

Example 2 with BillOfMaterial

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

the class ManufOrderServiceImpl method createToProduceProdProductList.

@Override
public void createToProduceProdProductList(ManufOrder manufOrder) {
    BigDecimal manufOrderQty = manufOrder.getQty();
    BillOfMaterial billOfMaterial = manufOrder.getBillOfMaterial();
    BigDecimal bomQty = billOfMaterial.getQty();
    // add the produced product
    manufOrder.addToProduceProdProductListItem(new ProdProduct(manufOrder.getProduct(), manufOrderQty, billOfMaterial.getUnit()));
    // Add the residual products
    if (appProductionService.getAppProduction().getManageResidualProductOnBom() && billOfMaterial.getProdResidualProductList() != null) {
        for (ProdResidualProduct prodResidualProduct : billOfMaterial.getProdResidualProductList()) {
            Product product = productVariantService.getProductVariant(manufOrder.getProduct(), prodResidualProduct.getProduct());
            BigDecimal qty = bomQty.signum() != 0 ? prodResidualProduct.getQty().multiply(manufOrderQty).divide(bomQty, appBaseService.getNbDecimalDigitForQty(), RoundingMode.HALF_UP) : BigDecimal.ZERO;
            manufOrder.addToProduceProdProductListItem(new ProdProduct(product, qty, prodResidualProduct.getUnit()));
        }
    }
}
Also used : BillOfMaterial(com.axelor.apps.production.db.BillOfMaterial) ProdResidualProduct(com.axelor.apps.production.db.ProdResidualProduct) Product(com.axelor.apps.base.db.Product) ProdResidualProduct(com.axelor.apps.production.db.ProdResidualProduct) ProdProduct(com.axelor.apps.production.db.ProdProduct) ProdProduct(com.axelor.apps.production.db.ProdProduct) BigDecimal(java.math.BigDecimal)

Example 3 with BillOfMaterial

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

the class ManufOrderServiceImpl method generateAllSubManufOrder.

/**
 * Called by generateMultiLevelManufOrder controller to generate all manuf order for a given bill
 * of material list from a given manuf order.
 *
 * @param billOfMaterialList
 * @param manufOrder
 * @throws AxelorException
 * @return
 */
public List<ManufOrder> generateAllSubManufOrder(List<Product> productList, ManufOrder manufOrder) throws AxelorException {
    List<ManufOrder> moList = new ArrayList<>();
    Set<Product> productManufactured = new HashSet<>();
    List<Pair<BillOfMaterial, BigDecimal>> childBomList = getToConsumeSubBomList(manufOrder.getBillOfMaterial(), manufOrder, productList);
    // prevent infinite loop
    int depth = 0;
    while (!childBomList.isEmpty()) {
        if (depth >= 25) {
            throw new AxelorException(TraceBackRepository.CATEGORY_CONFIGURATION_ERROR, I18n.get(IExceptionMessage.CHILD_BOM_TOO_MANY_ITERATION));
        }
        List<Pair<BillOfMaterial, BigDecimal>> tempChildBomList = new ArrayList<>();
        for (Pair<BillOfMaterial, BigDecimal> childBomPair : childBomList) {
            BillOfMaterial childBom = childBomPair.getLeft();
            BigDecimal qtyRequested = childBomPair.getRight();
            if (productManufactured.contains(childBom.getProduct())) {
                continue;
            }
            manufOrder = generateManufOrder(childBom.getProduct(), qtyRequested.multiply(childBom.getQty()), childBom.getPriority(), IS_TO_INVOICE, childBom, null, manufOrder.getPlannedStartDateT(), ORIGIN_TYPE_OTHER);
            moList.add(manufOrder);
            productManufactured.add(childBom.getProduct());
            tempChildBomList.addAll(getToConsumeSubBomList(childBom, manufOrder, null));
        }
        childBomList.clear();
        childBomList.addAll(tempChildBomList);
        tempChildBomList.clear();
        depth++;
    }
    return moList;
}
Also used : AxelorException(com.axelor.exception.AxelorException) ArrayList(java.util.ArrayList) Product(com.axelor.apps.base.db.Product) ProdResidualProduct(com.axelor.apps.production.db.ProdResidualProduct) ProdProduct(com.axelor.apps.production.db.ProdProduct) BigDecimal(java.math.BigDecimal) BillOfMaterial(com.axelor.apps.production.db.BillOfMaterial) ManufOrder(com.axelor.apps.production.db.ManufOrder) HashSet(java.util.HashSet) Pair(org.apache.commons.lang3.tuple.Pair)

Example 4 with BillOfMaterial

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

the class ManufOrderServiceImpl method createToConsumeProdProductList.

@Override
public void createToConsumeProdProductList(ManufOrder manufOrder) {
    BigDecimal manufOrderQty = manufOrder.getQty();
    BillOfMaterial billOfMaterial = manufOrder.getBillOfMaterial();
    BigDecimal bomQty = billOfMaterial.getQty();
    if (billOfMaterial.getBillOfMaterialSet() != null) {
        for (BillOfMaterial billOfMaterialLine : getSortedBillsOfMaterials(billOfMaterial.getBillOfMaterialSet())) {
            if (!billOfMaterialLine.getHasNoManageStock()) {
                Product product = productVariantService.getProductVariant(manufOrder.getProduct(), billOfMaterialLine.getProduct());
                BigDecimal qty = computeToConsumeProdProductLineQuantity(bomQty, manufOrderQty, billOfMaterialLine.getQty());
                ProdProduct prodProduct = new ProdProduct(product, qty, billOfMaterialLine.getUnit());
                manufOrder.addToConsumeProdProductListItem(prodProduct);
                // id by order of creation
                prodProductRepo.persist(prodProduct);
            }
        }
    }
}
Also used : BillOfMaterial(com.axelor.apps.production.db.BillOfMaterial) Product(com.axelor.apps.base.db.Product) ProdResidualProduct(com.axelor.apps.production.db.ProdResidualProduct) ProdProduct(com.axelor.apps.production.db.ProdProduct) ProdProduct(com.axelor.apps.production.db.ProdProduct) BigDecimal(java.math.BigDecimal)

Example 5 with BillOfMaterial

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

the class CostSheetLineServiceImpl method createConsumedProductWasteCostSheetLine.

public CostSheetLine createConsumedProductWasteCostSheetLine(Company company, Product product, Unit unit, int bomLevel, CostSheetLine parentCostSheetLine, BigDecimal consumptionQty, BigDecimal wasteRate, int origin, UnitCostCalculation unitCostCalculation) throws AxelorException {
    Product parentProduct = parentCostSheetLine.getProduct();
    BigDecimal qty = consumptionQty.multiply(wasteRate).divide(new BigDecimal("100"), appBaseService.getNbDecimalDigitForQty(), BigDecimal.ROUND_HALF_UP);
    BigDecimal costPrice = null;
    switch(origin) {
        case CostSheetService.ORIGIN_BULK_UNIT_COST_CALCULATION:
            BillOfMaterial componentDefaultBillOfMaterial = product.getDefaultBillOfMaterial();
            if (componentDefaultBillOfMaterial != null) {
                UnitCostCalcLine unitCostCalcLine = unitCostCalcLineServiceImpl.getUnitCostCalcLine(unitCostCalculation, product);
                if (unitCostCalcLine != null) {
                    costPrice = unitCostCalcLine.getComputedCost();
                    break;
                }
            }
            costPrice = this.getComponentCostPrice(product, parentProduct.getBomCompValuMethodSelect(), company);
            break;
        case CostSheetService.ORIGIN_BILL_OF_MATERIAL:
            costPrice = this.getComponentCostPrice(product, parentProduct.getBomCompValuMethodSelect(), company);
            break;
        default:
            costPrice = BigDecimal.ZERO;
    }
    costPrice = unitConversionService.convert(unit, product.getUnit(), costPrice, appProductionService.getNbDecimalDigitForUnitPrice(), product).multiply(qty);
    return this.createCostSheetLine(product.getName(), product.getCode(), bomLevel, qty, costPrice.setScale(appProductionService.getNbDecimalDigitForUnitPrice(), RoundingMode.HALF_UP), product.getCostSheetGroup(), product, CostSheetLineRepository.TYPE_CONSUMED_PRODUCT_WASTE, CostSheetLineRepository.TYPE_CONSUMED_PRODUCT_WASTE, unit, null, parentCostSheetLine);
}
Also used : BillOfMaterial(com.axelor.apps.production.db.BillOfMaterial) UnitCostCalcLine(com.axelor.apps.production.db.UnitCostCalcLine) Product(com.axelor.apps.base.db.Product) BigDecimal(java.math.BigDecimal)

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