use of com.axelor.apps.base.db.Product in project axelor-open-suite by axelor.
the class StockMoveServiceImpl method computeMasses.
private void computeMasses(StockMove stockMove) throws AxelorException {
StockConfig stockConfig = stockMove.getCompany().getStockConfig();
Unit endUnit = stockConfig != null ? stockConfig.getCustomsMassUnit() : null;
boolean massesRequiredForStockMove = false;
List<StockMoveLine> stockMoveLineList = stockMove.getStockMoveLineList();
if (stockMoveLineList == null) {
return;
}
UnitConversionService unitConversionService = Beans.get(UnitConversionService.class);
for (StockMoveLine stockMoveLine : stockMoveLineList) {
Product product = stockMoveLine.getProduct();
boolean massesRequiredForStockMoveLine = stockMoveLineService.checkMassesRequired(stockMove, stockMoveLine);
if (product == null || !ProductRepository.PRODUCT_TYPE_STORABLE.equals(product.getProductTypeSelect())) {
continue;
}
BigDecimal netMass = stockMoveLine.getNetMass();
if (netMass.signum() == 0) {
Unit startUnit = product.getMassUnit();
if (startUnit != null && endUnit != null) {
netMass = unitConversionService.convert(startUnit, endUnit, product.getNetMass(), product.getNetMass().scale(), null);
stockMoveLine.setNetMass(netMass);
}
}
if (netMass.signum() != 0) {
BigDecimal totalNetMass = netMass.multiply(stockMoveLine.getRealQty());
stockMoveLine.setTotalNetMass(totalNetMass);
} else if (massesRequiredForStockMoveLine) {
throw new AxelorException(stockMove, TraceBackRepository.CATEGORY_NO_VALUE, I18n.get(IExceptionMessage.STOCK_MOVE_18));
}
if (!massesRequiredForStockMove && massesRequiredForStockMoveLine) {
massesRequiredForStockMove = true;
}
}
if (massesRequiredForStockMove && endUnit == null) {
throw new AxelorException(stockMove, TraceBackRepository.CATEGORY_NO_VALUE, I18n.get(IExceptionMessage.STOCK_MOVE_17));
}
}
use of com.axelor.apps.base.db.Product in project axelor-open-suite by axelor.
the class StockMoveServiceImpl method updateProductNetMass.
@Override
@Transactional
public void updateProductNetMass(StockMove stockMove) throws AxelorException {
if (stockMove.getStockMoveLineList() != null) {
for (StockMoveLine stockMoveLine : stockMove.getStockMoveLineList()) {
if (stockMoveLine.getProduct() != null) {
Product product = productRepository.find(stockMoveLine.getProduct().getId());
stockMoveLine.setNetMass(product.getNetMass());
stockMoveLineRepo.save(stockMoveLine);
}
}
}
}
use of com.axelor.apps.base.db.Product 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.base.db.Product in project axelor-open-suite by axelor.
the class ManufOrderServiceImpl method createDiffProdProductList.
@Override
public List<ProdProduct> createDiffProdProductList(List<ProdProduct> prodProductList, List<StockMoveLine> stockMoveLineList) throws AxelorException {
List<ProdProduct> diffConsumeList = new ArrayList<>();
for (ProdProduct prodProduct : prodProductList) {
Product product = prodProduct.getProduct();
Unit newUnit = prodProduct.getUnit();
List<StockMoveLine> stockMoveLineProductList = stockMoveLineList.stream().filter(stockMoveLine1 -> stockMoveLine1.getProduct() != null).filter(stockMoveLine1 -> stockMoveLine1.getProduct().equals(product)).collect(Collectors.toList());
if (stockMoveLineProductList.isEmpty()) {
StockMoveLine stockMoveLine = new StockMoveLine();
stockMoveLineProductList.add(stockMoveLine);
}
BigDecimal diffQty = computeDiffQty(prodProduct, stockMoveLineProductList, product);
BigDecimal plannedQty = prodProduct.getQty();
BigDecimal realQty = diffQty.add(plannedQty);
if (diffQty.compareTo(BigDecimal.ZERO) != 0) {
ProdProduct diffProdProduct = new ProdProduct();
diffProdProduct.setQty(diffQty);
diffProdProduct.setPlannedQty(plannedQty);
diffProdProduct.setRealQty(realQty);
diffProdProduct.setProduct(product);
diffProdProduct.setUnit(newUnit);
diffConsumeList.add(diffProdProduct);
}
}
// There are stock move lines with products that are not available in
// prod product list. It needs to appear in the prod product list
List<StockMoveLine> stockMoveLineMissingProductList = stockMoveLineList.stream().filter(stockMoveLine1 -> stockMoveLine1.getProduct() != null).filter(stockMoveLine1 -> !prodProductList.stream().map(ProdProduct::getProduct).collect(Collectors.toList()).contains(stockMoveLine1.getProduct())).collect(Collectors.toList());
for (StockMoveLine stockMoveLine : stockMoveLineMissingProductList) {
if (stockMoveLine.getQty().compareTo(BigDecimal.ZERO) != 0) {
ProdProduct diffProdProduct = new ProdProduct();
diffProdProduct.setQty(stockMoveLine.getQty());
diffProdProduct.setPlannedQty(BigDecimal.ZERO);
diffProdProduct.setRealQty(stockMoveLine.getQty());
diffProdProduct.setProduct(stockMoveLine.getProduct());
diffProdProduct.setUnit(stockMoveLine.getUnit());
diffConsumeList.add(diffProdProduct);
}
}
return diffConsumeList;
}
use of com.axelor.apps.base.db.Product 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;
}
Aggregations