use of com.axelor.apps.base.db.Unit in project axelor-open-suite by axelor.
the class ProductionProductStockLocationServiceImpl method getMissingManufOrderQty.
protected BigDecimal getMissingManufOrderQty(Product product, Company company, StockLocation stockLocation) throws AxelorException {
if (product == null || product.getUnit() == null) {
return BigDecimal.ZERO;
}
Long companyId = 0L;
Long stockLocationId = 0L;
if (company != null) {
companyId = company.getId();
if (stockLocation != null) {
stockLocationId = stockLocation.getId();
}
}
String query = manufOrderService.getConsumeAndMissingQtyForAProduct(product.getId(), companyId, stockLocationId);
List<StockMoveLine> stockMoveLineList = stockMoveLineRepository.all().filter(query).fetch();
BigDecimal sumMissingManufOrderQty = BigDecimal.ZERO;
if (!stockMoveLineList.isEmpty()) {
Unit unitConversion = product.getUnit();
for (StockMoveLine stockMoveLine : stockMoveLineList) {
BigDecimal productMissingManufOrderQty = getMissingQtyOfStockMoveLine(stockMoveLine);
unitConversionService.convert(stockMoveLine.getUnit(), unitConversion, productMissingManufOrderQty, productMissingManufOrderQty.scale(), product);
sumMissingManufOrderQty = sumMissingManufOrderQty.add(productMissingManufOrderQty);
}
}
return sumMissingManufOrderQty;
}
use of com.axelor.apps.base.db.Unit in project axelor-open-suite by axelor.
the class ProductionProductStockLocationServiceImpl method getConsumeManufOrderQty.
protected BigDecimal getConsumeManufOrderQty(Product product, Company company, StockLocation stockLocation) throws AxelorException {
if (product == null || product.getUnit() == null) {
return BigDecimal.ZERO;
}
Long companyId = 0L;
Long stockLocationId = 0L;
if (company != null) {
companyId = company.getId();
if (stockLocation != null) {
stockLocationId = stockLocation.getId();
}
}
String query = manufOrderService.getConsumeAndMissingQtyForAProduct(product.getId(), companyId, stockLocationId);
List<StockMoveLine> stockMoveLineList = stockMoveLineRepository.all().filter(query).fetch();
BigDecimal sumConsumeManufOrderQty = BigDecimal.ZERO;
if (!stockMoveLineList.isEmpty()) {
Unit unitConversion = product.getUnit();
for (StockMoveLine stockMoveLine : stockMoveLineList) {
BigDecimal productConsumeManufOrderQty = stockMoveLine.getRealQty();
unitConversionService.convert(stockMoveLine.getUnit(), unitConversion, productConsumeManufOrderQty, productConsumeManufOrderQty.scale(), product);
sumConsumeManufOrderQty = sumConsumeManufOrderQty.add(productConsumeManufOrderQty);
}
}
return sumConsumeManufOrderQty;
}
use of com.axelor.apps.base.db.Unit in project axelor-open-suite by axelor.
the class StockMoveLineServiceImpl method updateLocations.
@Override
public void updateLocations(StockMoveLine stockMoveLine, StockLocation fromStockLocation, StockLocation toStockLocation, Product product, BigDecimal qty, int fromStatus, int toStatus, LocalDate lastFutureStockMoveDate, TrackingNumber trackingNumber) throws AxelorException {
Unit stockMoveLineUnit = stockMoveLine.getUnit();
switch(fromStatus) {
case StockMoveRepository.STATUS_PLANNED:
stockLocationLineService.updateLocation(fromStockLocation, product, stockMoveLineUnit, qty, false, true, true, null, trackingNumber);
stockLocationLineService.updateLocation(toStockLocation, product, stockMoveLineUnit, qty, false, true, false, null, trackingNumber);
break;
case StockMoveRepository.STATUS_REALIZED:
stockLocationLineService.updateLocation(fromStockLocation, product, stockMoveLineUnit, qty, true, true, true, null, trackingNumber);
stockLocationLineService.updateLocation(toStockLocation, product, stockMoveLineUnit, qty, true, true, false, null, trackingNumber);
break;
default:
break;
}
switch(toStatus) {
case StockMoveRepository.STATUS_PLANNED:
stockLocationLineService.updateLocation(fromStockLocation, product, stockMoveLineUnit, qty, false, true, false, lastFutureStockMoveDate, trackingNumber);
stockLocationLineService.updateLocation(toStockLocation, product, stockMoveLineUnit, qty, false, true, true, lastFutureStockMoveDate, trackingNumber);
break;
case StockMoveRepository.STATUS_REALIZED:
stockLocationLineService.updateLocation(fromStockLocation, product, stockMoveLineUnit, qty, true, true, false, null, trackingNumber);
stockLocationLineService.updateLocation(toStockLocation, product, stockMoveLineUnit, qty, true, true, true, null, trackingNumber);
break;
default:
break;
}
}
use of com.axelor.apps.base.db.Unit in project axelor-open-suite by axelor.
the class StockMoveLineServiceImpl method computeNetMass.
public BigDecimal computeNetMass(StockMove stockMove, StockMoveLine stockMoveLine, Company company) throws AxelorException {
BigDecimal netMass;
Product product = stockMoveLine.getProduct();
Unit startUnit;
Unit endUnit;
if (product == null || !product.getProductTypeSelect().equals(ProductRepository.PRODUCT_TYPE_STORABLE)) {
return null;
}
startUnit = product.getMassUnit();
if (startUnit == null) {
if (stockMove != null && !checkMassesRequired(stockMove, stockMoveLine)) {
return product.getNetMass();
}
throw new AxelorException(TraceBackRepository.CATEGORY_CONFIGURATION_ERROR, I18n.get(IExceptionMessage.MISSING_PRODUCT_MASS_UNIT), product.getName());
}
if (company != null && company.getStockConfig() != null && company.getStockConfig().getCustomsMassUnit() != null) {
endUnit = company.getStockConfig().getCustomsMassUnit();
} else {
endUnit = startUnit;
}
netMass = unitConversionService.convert(startUnit, endUnit, product.getNetMass(), 10, product);
return netMass;
}
use of com.axelor.apps.base.db.Unit in project axelor-open-suite by axelor.
the class StockLocationServiceImpl method getQty.
@Override
public BigDecimal getQty(Long productId, Long locationId, Long companyId, String qtyType) throws AxelorException {
if (productId != null) {
Product product = productRepo.find(productId);
Unit productUnit = product.getUnit();
UnitConversionService unitConversionService = Beans.get(UnitConversionService.class);
int scale = Beans.get(AppBaseService.class).getNbDecimalDigitForQty();
if (locationId == null || locationId == 0L) {
List<StockLocation> stockLocations = getNonVirtualStockLocations(companyId);
if (!stockLocations.isEmpty()) {
BigDecimal qty = BigDecimal.ZERO;
for (StockLocation stockLocation : stockLocations) {
StockLocationLine stockLocationLine = stockLocationLineService.getStockLocationLine(stockLocationRepo.find(stockLocation.getId()), productRepo.find(productId));
if (stockLocationLine != null) {
Unit stockLocationLineUnit = stockLocationLine.getUnit();
qty = qty.add(qtyType.equals("real") ? stockLocationLine.getCurrentQty() : stockLocationLine.getFutureQty());
if (productUnit != null && !productUnit.equals(stockLocationLineUnit)) {
qty = unitConversionService.convert(stockLocationLineUnit, productUnit, qty, qty.scale(), product);
}
}
}
return qty.setScale(scale, RoundingMode.HALF_UP);
}
} else {
StockLocationLine stockLocationLine = stockLocationLineService.getStockLocationLine(stockLocationRepo.find(locationId), productRepo.find(productId));
if (stockLocationLine != null) {
Unit stockLocationLineUnit = stockLocationLine.getUnit();
BigDecimal qty = BigDecimal.ZERO;
qty = qtyType.equals("real") ? stockLocationLine.getCurrentQty() : stockLocationLine.getFutureQty();
if (productUnit != null && !productUnit.equals(stockLocationLineUnit)) {
qty = unitConversionService.convert(stockLocationLineUnit, productUnit, qty, qty.scale(), product);
}
return qty.setScale(scale, RoundingMode.HALF_UP);
}
}
}
return BigDecimal.ZERO;
}
Aggregations