use of com.axelor.apps.stock.db.TrackingNumber in project axelor-open-suite by axelor.
the class ImportInventoryLine method importInventoryLine.
@Transactional(rollbackOn = { Exception.class })
public Object importInventoryLine(Object bean, Map<String, Object> values) throws AxelorException {
assert bean instanceof InventoryLine;
InventoryLine inventoryLine = (InventoryLine) bean;
TrackingNumberConfiguration trackingNumberConfig = inventoryLine.getProduct().getTrackingNumberConfiguration();
BigDecimal qtyByTracking = BigDecimal.ONE;
BigDecimal realQtyRemaning = inventoryLine.getRealQty();
inventoryLineService.compute(inventoryLine, inventoryLine.getInventory());
TrackingNumber trackingNumber;
if (trackingNumberConfig != null) {
if (trackingNumberConfig.getGenerateProductionAutoTrackingNbr()) {
qtyByTracking = trackingNumberConfig.getProductionQtyByTracking();
} else if (trackingNumberConfig.getGeneratePurchaseAutoTrackingNbr()) {
qtyByTracking = trackingNumberConfig.getPurchaseQtyByTracking();
} else {
qtyByTracking = trackingNumberConfig.getSaleQtyByTracking();
}
InventoryLine inventoryLineNew;
for (int i = 0; i < inventoryLine.getRealQty().intValue(); i += qtyByTracking.intValue()) {
trackingNumber = trackingNumberService.createTrackingNumber(inventoryLine.getProduct(), inventoryLine.getInventory().getStockLocation().getCompany(), appBaseService.getTodayDate(inventoryLine.getInventory().getStockLocation().getCompany()), inventoryLine.getInventory().getInventorySeq());
if (realQtyRemaning.compareTo(qtyByTracking) < 0) {
trackingNumber.setCounter(realQtyRemaning);
} else {
trackingNumber.setCounter(qtyByTracking);
}
inventoryLineNew = inventoryLineService.createInventoryLine(inventoryLine.getInventory(), inventoryLine.getProduct(), inventoryLine.getCurrentQty(), inventoryLine.getRack(), trackingNumber);
inventoryLineNew.setUnit(inventoryLine.getProduct().getUnit());
if (realQtyRemaning.compareTo(qtyByTracking) < 0) {
inventoryLineNew.setRealQty(realQtyRemaning);
} else {
inventoryLineNew.setRealQty(qtyByTracking);
realQtyRemaning = realQtyRemaning.subtract(qtyByTracking);
}
inventoryLineRepo.save(inventoryLineNew);
}
return null;
}
return bean;
}
use of com.axelor.apps.stock.db.TrackingNumber in project axelor-open-suite by axelor.
the class TrackingNumberService method getTrackingNumber.
@Transactional(rollbackOn = { Exception.class })
public TrackingNumber getTrackingNumber(Product product, BigDecimal sizeOfLot, Company company, LocalDate date, String origin) throws AxelorException {
TrackingNumber trackingNumber = trackingNumberRepo.all().filter("self.product = ?1 AND self.counter < ?2", product, sizeOfLot).fetchOne();
if (trackingNumber == null) {
trackingNumber = trackingNumberRepo.save(this.createTrackingNumber(product, company, date, origin));
}
trackingNumber.setCounter(trackingNumber.getCounter().add(sizeOfLot));
return trackingNumber;
}
use of com.axelor.apps.stock.db.TrackingNumber in project axelor-open-suite by axelor.
the class TrackingNumberService method createTrackingNumber.
public TrackingNumber createTrackingNumber(Product product, Company company, LocalDate date, String origin) throws AxelorException {
Preconditions.checkNotNull(product, I18n.get("Product cannot be null."));
Preconditions.checkNotNull(company, I18n.get("Company cannot be null."));
if (date == null) {
throw new AxelorException(product, TraceBackRepository.CATEGORY_CONFIGURATION_ERROR, I18n.get(IExceptionMessage.TRACK_NUMBER_DATE_MISSING), product.getFullName(), origin);
}
TrackingNumber trackingNumber = new TrackingNumber();
if (product.getIsPerishable()) {
trackingNumber.setPerishableExpirationDate(date.plusMonths(product.getPerishableNbrOfMonths()));
}
if (product.getHasWarranty()) {
trackingNumber.setWarrantyExpirationDate(date.plusMonths(product.getWarrantyNbrOfMonths()));
}
trackingNumber.setProduct(product);
trackingNumber.setCounter(BigDecimal.ZERO);
TrackingNumberConfiguration trackingNumberConfiguration = product.getTrackingNumberConfiguration();
if (trackingNumberConfiguration.getSequence() == null) {
throw new AxelorException(product, TraceBackRepository.CATEGORY_CONFIGURATION_ERROR, I18n.get(IExceptionMessage.TRACKING_NUMBER_1), company.getName(), product.getCode());
}
Sequence sequence = trackingNumberConfiguration.getSequence();
String seq;
while (true) {
seq = sequenceService.getSequenceNumber(sequence);
if (trackingNumberRepo.all().filter("self.product = ?1 AND self.trackingNumberSeq = ?2", product, seq).count() == 0) {
break;
}
}
trackingNumber.setTrackingNumberSeq(seq);
return trackingNumber;
}
Aggregations