use of com.axelor.apps.base.db.Product in project axelor-open-suite by axelor.
the class StockCorrectionServiceImpl method generateStockMove.
public StockMove generateStockMove(StockCorrection stockCorrection) throws AxelorException {
StockLocation toStockLocation = stockCorrection.getStockLocation();
Company company = toStockLocation.getCompany();
StockLocation fromStockLocation = stockConfigService.getInventoryVirtualStockLocation(stockConfigService.getStockConfig(company));
StockMoveService stockMoveService = Beans.get(StockMoveService.class);
StockMoveLineService stockMoveLineService = Beans.get(StockMoveLineService.class);
StockLocationLine stockLocationLine = null;
StockLocationLineService stockLocationLineService = Beans.get(StockLocationLineService.class);
if (stockCorrection.getTrackingNumber() == null) {
stockLocationLine = stockLocationLineService.getStockLocationLine(stockCorrection.getStockLocation(), stockCorrection.getProduct());
} else {
stockLocationLine = stockLocationLineService.getDetailLocationLine(stockCorrection.getStockLocation(), stockCorrection.getProduct(), stockCorrection.getTrackingNumber());
}
BigDecimal realQty = stockCorrection.getRealQty();
Product product = stockCorrection.getProduct();
TrackingNumber trackingNumber = stockCorrection.getTrackingNumber();
BigDecimal diff = realQty.subtract(stockLocationLine.getCurrentQty());
StockMove stockMove = null;
if (diff.compareTo(BigDecimal.ZERO) == 0) {
return null;
} else if (diff.compareTo(BigDecimal.ZERO) > 0) {
stockMove = this.createStockMoveHeader(company, fromStockLocation, toStockLocation);
} else {
stockMove = this.createStockMoveHeader(company, toStockLocation, fromStockLocation);
}
stockMove.setOriginTypeSelect(StockMoveRepository.ORIGIN_STOCK_CORRECTION);
stockMove.setOriginId(stockCorrection.getId());
stockMove.setStockCorrectionReason(stockCorrection.getStockCorrectionReason());
BigDecimal productCostPrice = (BigDecimal) productCompanyService.get(product, "costPrice", company);
StockMoveLine stockMoveLine = stockMoveLineService.createStockMoveLine(product, product.getName(), product.getDescription(), diff.abs(), productCostPrice, productCostPrice, product.getUnit(), stockMove, StockMoveLineService.TYPE_NULL, false, BigDecimal.ZERO);
if (stockMoveLine == null) {
throw new AxelorException(stockCorrection, TraceBackRepository.CATEGORY_CONFIGURATION_ERROR, I18n.get(IExceptionMessage.STOCK_CORRECTION_1));
}
if (trackingNumber != null && stockMoveLine.getTrackingNumber() == null) {
stockMoveLine.setTrackingNumber(trackingNumber);
}
stockMoveService.plan(stockMove);
stockMoveService.copyQtyToRealQty(stockMove);
stockMoveService.realize(stockMove, false);
return stockMove;
}
use of com.axelor.apps.base.db.Product in project axelor-open-suite by axelor.
the class StockMoveLineServiceImpl method storeCustomsCodes.
@Override
public void storeCustomsCodes(List<StockMoveLine> stockMoveLineList) {
if (stockMoveLineList == null) {
return;
}
for (StockMoveLine stockMoveLine : stockMoveLineList) {
Product product = stockMoveLine.getProduct();
CustomsCodeNomenclature customsCodeNomenclature = product != null ? product.getCustomsCodeNomenclature() : null;
stockMoveLine.setCustomsCodeNomenclature(customsCodeNomenclature);
stockMoveLine.setCustomsCode(customsCodeNomenclature != null ? customsCodeNomenclature.getCode() : null);
}
}
use of com.axelor.apps.base.db.Product in project axelor-open-suite by axelor.
the class StockMoveLineServiceImpl method checkExpirationDates.
@Override
public void checkExpirationDates(StockMove stockMove) throws AxelorException {
List<String> errorList = new ArrayList<>();
for (StockMoveLine stockMoveLine : stockMove.getStockMoveLineList()) {
TrackingNumber trackingNumber = stockMoveLine.getTrackingNumber();
if (trackingNumber == null) {
continue;
}
Product product = trackingNumber.getProduct();
if (product == null || !product.getCheckExpirationDateAtStockMoveRealization()) {
continue;
}
if (product.getHasWarranty() && trackingNumber.getWarrantyExpirationDate().isBefore(appBaseService.getTodayDate(stockMove.getCompany())) || product.getIsPerishable() && trackingNumber.getPerishableExpirationDate().isBefore(appBaseService.getTodayDate(stockMove.getCompany()))) {
errorList.add(product.getName());
}
}
if (!errorList.isEmpty()) {
String errorStr = errorList.stream().collect(Collectors.joining(", "));
throw new AxelorException(TraceBackRepository.CATEGORY_CONFIGURATION_ERROR, I18n.get(IExceptionMessage.STOCK_MOVE_LINE_EXPIRED_PRODUCTS), errorStr);
}
}
use of com.axelor.apps.base.db.Product in project axelor-open-suite by axelor.
the class InventoryLineService method compute.
public InventoryLine compute(InventoryLine inventoryLine, Inventory inventory) {
StockLocation stockLocation = inventory.getStockLocation();
Product product = inventoryLine.getProduct();
if (product != null) {
inventoryLine.setUnit(product.getUnit());
BigDecimal gap = inventoryLine.getRealQty() != null ? inventoryLine.getCurrentQty().subtract(inventoryLine.getRealQty()).setScale(2, RoundingMode.HALF_UP) : BigDecimal.ZERO;
inventoryLine.setGap(gap);
BigDecimal price;
int value = stockLocation.getCompany().getStockConfig().getInventoryValuationTypeSelect();
switch(value) {
case StockConfigRepository.VALUATION_TYPE_ACCOUNTING_VALUE:
price = product.getCostPrice();
break;
case StockConfigRepository.VALUATION_TYPE_SALE_VALUE:
price = product.getSalePrice();
break;
default:
price = product.getAvgPrice();
break;
}
inventoryLine.setGapValue(gap.multiply(price).setScale(2, RoundingMode.HALF_UP));
inventoryLine.setRealValue(inventoryLine.getRealQty() != null ? inventoryLine.getRealQty().multiply(price).setScale(2, RoundingMode.HALF_UP) : BigDecimal.ZERO);
}
return inventoryLine;
}
use of com.axelor.apps.base.db.Product in project axelor-open-suite by axelor.
the class InventoryLineService method updateInventoryLine.
public InventoryLine updateInventoryLine(InventoryLine inventoryLine, Inventory inventory) {
StockLocation stockLocation = inventory.getStockLocation();
Product product = inventoryLine.getProduct();
if (product != null) {
StockLocationLine stockLocationLine = Beans.get(StockLocationLineService.class).getOrCreateStockLocationLine(stockLocation, product);
if (stockLocationLine != null) {
inventoryLine.setCurrentQty(stockLocationLine.getCurrentQty());
inventoryLine.setRack(stockLocationLine.getRack());
if (inventoryLine.getTrackingNumber() != null) {
inventoryLine.setCurrentQty(Beans.get(StockLocationLineRepository.class).all().filter("self.product = :product and self.detailsStockLocation = :stockLocation and self.trackingNumber = :trackingNumber").bind("product", inventoryLine.getProduct()).bind("stockLocation", stockLocation).bind("trackingNumber", inventoryLine.getTrackingNumber()).fetchStream().map(it -> it.getCurrentQty()).reduce(BigDecimal.ZERO, (a, b) -> a.add(b)));
}
} else {
inventoryLine.setCurrentQty(null);
inventoryLine.setRack(null);
}
}
return inventoryLine;
}
Aggregations