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);
}
}
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);
}
}
}
}
}
Aggregations