use of com.axelor.apps.stock.db.StockMoveLine 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.stock.db.StockMoveLine 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.stock.db.StockMoveLine in project axelor-open-suite by axelor.
the class StockMoveLineServiceImpl method splitStockMoveLineByTrackingNumber.
@Override
@Transactional
public void splitStockMoveLineByTrackingNumber(StockMoveLine stockMoveLine, List<LinkedHashMap<String, Object>> trackingNumbers) {
// boolean draft = true;
// if (stockMoveLine.getStockMove() != null
// && stockMoveLine.getStockMove().getStatusSelect() ==
// StockMoveRepository.STATUS_PLANNED) {
// draft = false;
// }
BigDecimal totalSplitQty = BigDecimal.ZERO;
for (LinkedHashMap<String, Object> trackingNumberItem : trackingNumbers) {
BigDecimal counter = new BigDecimal(trackingNumberItem.get("counter").toString());
if (counter.compareTo(BigDecimal.ZERO) == 0) {
continue;
}
totalSplitQty = totalSplitQty.add(counter);
TrackingNumber trackingNumber = trackingNumberRepo.all().filter("self.product.id = ?1 and self.trackingNumberSeq = ?2", stockMoveLine.getProduct(), trackingNumberItem.get("trackingNumberSeq").toString()).fetchOne();
if (trackingNumber == null) {
trackingNumber = new TrackingNumber();
trackingNumber.setCounter(counter);
trackingNumber.setTrackingNumberSeq(trackingNumberItem.get("trackingNumberSeq").toString());
if (trackingNumberItem.get("warrantyExpirationDate") != null) {
trackingNumber.setWarrantyExpirationDate(LocalDate.parse(trackingNumberItem.get("warrantyExpirationDate").toString()));
}
if (trackingNumberItem.get("perishableExpirationDate") != null) {
trackingNumber.setPerishableExpirationDate(LocalDate.parse(trackingNumberItem.get("perishableExpirationDate").toString()));
}
if (trackingNumberItem.get("origin") != null) {
trackingNumber.setOrigin(trackingNumberItem.get("origin").toString());
}
if (trackingNumberItem.get("note") != null) {
trackingNumber.setNote(trackingNumberItem.get("note").toString());
}
trackingNumber.setProduct(stockMoveLine.getProduct());
}
StockMoveLine newStockMoveLine = stockMoveLineRepository.copy(stockMoveLine, true);
// if (draft) {
newStockMoveLine.setQty(counter);
// } else {
newStockMoveLine.setRealQty(counter);
// }
newStockMoveLine.setTrackingNumber(trackingNumber);
newStockMoveLine.setStockMove(stockMoveLine.getStockMove());
stockMoveLineRepository.save(newStockMoveLine);
}
if (totalSplitQty.compareTo(stockMoveLine.getQty()) < 0) {
BigDecimal remainingQty = stockMoveLine.getQty().subtract(totalSplitQty);
stockMoveLine.setQty(remainingQty);
stockMoveLine.setRealQty(remainingQty);
stockMoveLine.setTrackingNumber(null);
stockMoveLine.setStockMove(stockMoveLine.getStockMove());
} else {
stockMoveLineRepository.remove(stockMoveLine);
}
}
use of com.axelor.apps.stock.db.StockMoveLine 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.stock.db.StockMoveLine in project axelor-open-suite by axelor.
the class StockMoveLineServiceImpl method splitStockMoveLine.
@Override
public StockMoveLine splitStockMoveLine(StockMoveLine stockMoveLine, BigDecimal qty, TrackingNumber trackingNumber) throws AxelorException {
StockMoveLine newStockMoveLine = this.createStockMoveLine(stockMoveLine.getProduct(), stockMoveLine.getProductName(), stockMoveLine.getDescription(), qty, stockMoveLine.getUnitPriceUntaxed(), stockMoveLine.getUnitPriceTaxed(), stockMoveLine.getCompanyUnitPriceUntaxed(), stockMoveLine.getCompanyPurchasePrice(), stockMoveLine.getUnit(), stockMoveLine.getStockMove(), trackingNumber);
stockMoveLine.setQty(stockMoveLine.getQty().subtract(qty));
stockMoveLine.setRealQty(stockMoveLine.getRealQty().subtract(qty));
return newStockMoveLine;
}
Aggregations