use of com.axelor.apps.base.db.Product 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.base.db.Product 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);
}
use of com.axelor.apps.base.db.Product in project axelor-open-suite by axelor.
the class CostSheetLineServiceImpl method createConsumedProductCostSheetLine.
public CostSheetLine createConsumedProductCostSheetLine(Company company, Product product, Unit unit, int bomLevel, CostSheetLine parentCostSheetLine, BigDecimal consumptionQty, int origin, UnitCostCalculation unitCostCalculation) throws AxelorException {
Product parentProduct = parentCostSheetLine.getProduct();
BigDecimal costPrice = null;
switch(origin) {
case CostSheetService.ORIGIN_MANUF_ORDER:
costPrice = this.getComponentCostPrice(product, parentProduct.getManufOrderCompValuMethodSelect(), company);
break;
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;
// from its bill of materials
case CostSheetService.ORIGIN_BILL_OF_MATERIAL:
costPrice = this.getComponentCostPrice(product, parentProduct.getBomCompValuMethodSelect(), company);
break;
default:
costPrice = BigDecimal.ZERO;
}
consumptionQty = consumptionQty.setScale(appBaseService.getNbDecimalDigitForQty(), RoundingMode.HALF_UP);
costPrice = costPrice.multiply(consumptionQty);
costPrice = unitConversionService.convert(unit, product.getUnit(), costPrice, appProductionService.getNbDecimalDigitForUnitPrice(), product);
List<CostSheetLine> costSheetLineList = parentCostSheetLine.getCostSheetLineList() != null ? parentCostSheetLine.getCostSheetLineList() : new ArrayList<CostSheetLine>();
for (CostSheetLine costSheetLine : costSheetLineList) {
if (product.equals(costSheetLine.getProduct()) && unit.equals(costSheetLine.getUnit())) {
BigDecimal qty = costSheetLine.getConsumptionQty().add(consumptionQty);
costSheetLine.setConsumptionQty(qty);
costSheetLine.setCostPrice(costPrice.add(costSheetLine.getCostPrice()).setScale(appProductionService.getNbDecimalDigitForUnitPrice(), BigDecimal.ROUND_HALF_UP));
return costSheetLine;
}
}
return this.createCostSheetLine(product.getName(), product.getCode(), bomLevel, consumptionQty, costPrice, product.getCostSheetGroup(), product, CostSheetLineRepository.TYPE_CONSUMED_PRODUCT, CostSheetLineRepository.TYPE_CONSUMED_PRODUCT, unit, null, parentCostSheetLine);
}
use of com.axelor.apps.base.db.Product in project axelor-open-suite by axelor.
the class ManufOrderController method generateMultiLevelManufOrder.
/**
* Called from multi-level-planing-wizard-form, on clicking "Generate MO" button.
*
* @param request
* @param response
*/
@SuppressWarnings("unchecked")
public void generateMultiLevelManufOrder(ActionRequest request, ActionResponse response) {
try {
Long moId = Long.valueOf(request.getContext().get("id").toString());
ManufOrder mo = Beans.get(ManufOrderRepository.class).find(moId);
ProdProductRepository prodProductRepository = Beans.get(ProdProductRepository.class);
List<ProdProduct> prodProductList = ((List<LinkedHashMap<String, Object>>) request.getContext().get("components")).stream().filter(map -> (boolean) map.get("selected")).map(map -> prodProductRepository.find(Long.valueOf(map.get("id").toString()))).collect(Collectors.toList());
if (prodProductList.isEmpty()) {
throw new AxelorException(TraceBackRepository.CATEGORY_MISSING_FIELD, I18n.get(IExceptionMessage.NO_PRODUCT_SELECTED));
}
List<Product> selectedProductList = new ArrayList<>();
for (ProdProduct prod : prodProductList) {
if (selectedProductList.contains(prod.getProduct())) {
throw new AxelorException(TraceBackRepository.CATEGORY_MISSING_FIELD, I18n.get(IExceptionMessage.DUPLICATE_PRODUCT_SELECTED));
}
selectedProductList.add(prod.getProduct());
}
List<ManufOrder> moList = Beans.get(ManufOrderService.class).generateAllSubManufOrder(selectedProductList, mo);
response.setCanClose(true);
response.setView(ActionView.define(I18n.get("Manufacturing orders")).model(ManufOrder.class.getName()).add("grid", "generated-manuf-order-grid").add("form", "manuf-order-form").param("popup", "true").param("popup-save", "false").param("show-toolbar", "false").param("show-confirm", "false").domain("self.id in (" + StringTool.getIdListString(moList) + ")").map());
} catch (Exception e) {
TraceBackService.trace(response, e);
}
}
use of com.axelor.apps.base.db.Product in project axelor-open-suite by axelor.
the class CostSheetServiceImpl method computeTotalProducedQty.
protected BigDecimal computeTotalProducedQty(Product producedProduct, List<StockMoveLine> producedStockMoveLineList, LocalDate calculationDate, LocalDate previousCostSheetDate, int calculationTypeSelect) throws AxelorException {
BigDecimal totalQty = BigDecimal.ZERO;
Map<List<Object>, BigDecimal> producedStockMoveLinePerProductAndUnit = getTotalQtyPerProductAndUnit(producedStockMoveLineList, calculationDate, previousCostSheetDate, calculationTypeSelect);
for (List<Object> keys : producedStockMoveLinePerProductAndUnit.keySet()) {
Iterator<Object> iterator = keys.iterator();
Product product = (Product) iterator.next();
Unit unit = (Unit) iterator.next();
BigDecimal realQty = producedStockMoveLinePerProductAndUnit.get(keys);
if (product == null || !product.equals(producedProduct)) {
continue;
}
totalQty = totalQty.add(unitConversionService.convert(unit, costSheet.getManufOrder().getUnit(), realQty, realQty.scale(), product));
}
return totalQty;
}
Aggregations