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