Search in sources :

Example 16 with ProdProduct

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

the class CostSheetServiceImpl method computeConsumedProduct.

protected void computeConsumedProduct(int bomLevel, LocalDate previousCostSheetDate, CostSheetLine parentCostSheetLine, List<StockMoveLine> consumedStockMoveLineList, List<ProdProduct> toConsumeProdProductList, BigDecimal ratio) throws AxelorException {
    CostSheet parentCostSheet = parentCostSheetLine.getCostSheet();
    int calculationTypeSelect = parentCostSheet.getCalculationTypeSelect();
    LocalDate calculationDate = parentCostSheet.getCalculationDate();
    Map<List<Object>, BigDecimal> consumedStockMoveLinePerProductAndUnit = getTotalQtyPerProductAndUnit(consumedStockMoveLineList, calculationDate, previousCostSheetDate, calculationTypeSelect);
    for (List<Object> keys : consumedStockMoveLinePerProductAndUnit.keySet()) {
        Iterator<Object> iterator = keys.iterator();
        Product product = (Product) iterator.next();
        Unit unit = (Unit) iterator.next();
        BigDecimal realQty = consumedStockMoveLinePerProductAndUnit.get(keys);
        if (product == null) {
            continue;
        }
        BigDecimal valuationQty = BigDecimal.ZERO;
        if (calculationTypeSelect == CostSheetRepository.CALCULATION_WORK_IN_PROGRESS) {
            BigDecimal plannedConsumeQty = computeTotalQtyPerUnit(toConsumeProdProductList, product, unit);
            valuationQty = realQty.subtract(plannedConsumeQty.multiply(ratio));
        }
        valuationQty = valuationQty.setScale(appBaseService.getNbDecimalDigitForQty(), RoundingMode.HALF_UP);
        if (valuationQty.compareTo(BigDecimal.ZERO) == 0) {
            continue;
        }
        costSheetLineService.createConsumedProductCostSheetLine(parentCostSheet.getManufOrder().getCompany(), product, unit, bomLevel, parentCostSheetLine, valuationQty, CostSheetService.ORIGIN_MANUF_ORDER, null);
    }
}
Also used : ProdProduct(com.axelor.apps.production.db.ProdProduct) Product(com.axelor.apps.base.db.Product) ProdResidualProduct(com.axelor.apps.production.db.ProdResidualProduct) ArrayList(java.util.ArrayList) List(java.util.List) Unit(com.axelor.apps.base.db.Unit) LocalDate(java.time.LocalDate) CostSheet(com.axelor.apps.production.db.CostSheet) BigDecimal(java.math.BigDecimal)

Example 17 with ProdProduct

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

the class MrpServiceProductionImpl method createManufOrderMrpLines.

@Transactional(rollbackOn = { Exception.class })
protected void createManufOrderMrpLines(Mrp mrp, ManufOrder manufOrder, MrpLineType manufOrderMrpLineType, MrpLineType manufOrderNeedMrpLineType) throws AxelorException {
    StockLocation stockLocation = manufOrder.getProdProcess().getStockLocation();
    LocalDate maturityDate = null;
    if (manufOrder.getPlannedEndDateT() != null) {
        maturityDate = manufOrder.getPlannedEndDateT().toLocalDate();
    } else {
        maturityDate = manufOrder.getPlannedStartDateT().toLocalDate();
    }
    maturityDate = this.computeMaturityDate(maturityDate, manufOrderMrpLineType);
    for (ProdProduct prodProduct : manufOrder.getToProduceProdProductList()) {
        Product product = prodProduct.getProduct();
        if ((this.isBeforeEndDate(maturityDate) || manufOrderMrpLineType.getIgnoreEndDate()) && this.isMrpProduct(product)) {
            MrpLine mrpLine = this.createMrpLine(mrp, product, manufOrderMrpLineType, prodProduct.getQty(), maturityDate, BigDecimal.ZERO, stockLocation, manufOrder);
            if (mrpLine != null) {
                mrpLineRepository.save(mrpLine);
            }
        }
    }
    if (manufOrderNeedMrpLineType == null) {
        return;
    }
    if (manufOrder.getIsConsProOnOperation()) {
        for (OperationOrder operationOrder : manufOrder.getOperationOrderList()) {
            for (ProdProduct prodProduct : operationOrder.getToConsumeProdProductList()) {
                Product product = prodProduct.getProduct();
                if (this.isMrpProduct(product)) {
                    maturityDate = null;
                    if (operationOrder.getPlannedEndDateT() != null) {
                        maturityDate = operationOrder.getPlannedEndDateT().toLocalDate();
                    } else {
                        maturityDate = operationOrder.getPlannedStartDateT().toLocalDate();
                    }
                    maturityDate = this.computeMaturityDate(maturityDate, manufOrderNeedMrpLineType);
                    MrpLine mrpLine = this.createMrpLine(mrp, prodProduct.getProduct(), manufOrderNeedMrpLineType, computeQtyLeftToConsume(operationOrder, prodProduct), maturityDate, BigDecimal.ZERO, stockLocation, operationOrder);
                    if (mrpLine != null) {
                        mrpLineRepository.save(mrpLine);
                    }
                }
            }
        }
    } else {
        for (ProdProduct prodProduct : manufOrder.getToConsumeProdProductList()) {
            Product product = prodProduct.getProduct();
            if (this.isMrpProduct(product)) {
                // add it with the level of manuf order product + 1.
                if (!this.productMap.containsKey(product.getId())) {
                    this.assignProductAndLevel(product, manufOrder.getProduct());
                    this.createAvailableStockMrpLine(product, manufOrder.getProdProcess().getStockLocation());
                }
                MrpLine mrpLine = this.createMrpLine(mrp, product, manufOrderNeedMrpLineType, computeQtyLeftToConsume(manufOrder, prodProduct), maturityDate, BigDecimal.ZERO, stockLocation, manufOrder);
                if (mrpLine != null) {
                    mrpLineRepository.save(mrpLine);
                }
            }
        }
    }
}
Also used : StockLocation(com.axelor.apps.stock.db.StockLocation) Product(com.axelor.apps.base.db.Product) ProdProduct(com.axelor.apps.production.db.ProdProduct) MrpLine(com.axelor.apps.supplychain.db.MrpLine) ProdProduct(com.axelor.apps.production.db.ProdProduct) LocalDate(java.time.LocalDate) OperationOrder(com.axelor.apps.production.db.OperationOrder) Transactional(com.google.inject.persist.Transactional)

Aggregations

ProdProduct (com.axelor.apps.production.db.ProdProduct)17 BigDecimal (java.math.BigDecimal)13 Company (com.axelor.apps.base.db.Company)9 Product (com.axelor.apps.base.db.Product)9 StockMove (com.axelor.apps.stock.db.StockMove)8 StockMoveLine (com.axelor.apps.stock.db.StockMoveLine)8 AxelorException (com.axelor.exception.AxelorException)8 ArrayList (java.util.ArrayList)8 List (java.util.List)8 AppBaseService (com.axelor.apps.base.service.app.AppBaseService)7 ManufOrder (com.axelor.apps.production.db.ManufOrder)7 StockLocation (com.axelor.apps.stock.db.StockLocation)7 Beans (com.axelor.inject.Beans)7 Transactional (com.google.inject.persist.Transactional)7 LocalDate (java.time.LocalDate)7 ProductRepository (com.axelor.apps.base.db.repo.ProductRepository)6 OperationOrder (com.axelor.apps.production.db.OperationOrder)6 ManufOrderRepository (com.axelor.apps.production.db.repo.ManufOrderRepository)6 IExceptionMessage (com.axelor.apps.production.exceptions.IExceptionMessage)6 I18n (com.axelor.i18n.I18n)6