use of com.axelor.apps.stock.db.TrackingNumberConfiguration in project axelor-open-suite by axelor.
the class StockMoveLineServiceImpl method createStockMoveLine.
@Override
public StockMoveLine createStockMoveLine(Product product, String productName, String description, BigDecimal quantity, BigDecimal unitPrice, BigDecimal companyUnitPriceUntaxed, Unit unit, StockMove stockMove, int type, boolean taxed, BigDecimal taxRate) throws AxelorException {
if (product != null) {
StockMoveLine stockMoveLine = generateStockMoveLineConvertingUnitPrice(product, productName, description, quantity, unitPrice, companyUnitPriceUntaxed, BigDecimal.ZERO, unit, stockMove, taxed, taxRate);
TrackingNumberConfiguration trackingNumberConfiguration = product.getTrackingNumberConfiguration();
return assignOrGenerateTrackingNumber(stockMoveLine, stockMove, product, trackingNumberConfiguration, type);
} else {
return this.createStockMoveLine(product, productName, description, quantity, BigDecimal.ZERO, BigDecimal.ZERO, companyUnitPriceUntaxed, BigDecimal.ZERO, unit, stockMove, null);
}
}
use of com.axelor.apps.stock.db.TrackingNumberConfiguration in project axelor-open-suite by axelor.
the class StockMoveLineServiceSupplychainImpl method createStockMoveLine.
@Override
public StockMoveLine createStockMoveLine(Product product, String productName, String description, BigDecimal quantity, BigDecimal requestedReservedQty, BigDecimal unitPrice, BigDecimal companyUnitPriceUntaxed, BigDecimal companyPurchasePrice, Unit unit, StockMove stockMove, int type, boolean taxed, BigDecimal taxRate, SaleOrderLine saleOrderLine, PurchaseOrderLine purchaseOrderLine) throws AxelorException {
if (product != null) {
StockMoveLine stockMoveLine = generateStockMoveLineConvertingUnitPrice(product, productName, description, quantity, unitPrice, companyUnitPriceUntaxed, companyPurchasePrice, unit, stockMove, taxed, taxRate);
stockMoveLine.setRequestedReservedQty(requestedReservedQty);
stockMoveLine.setIsQtyRequested(requestedReservedQty != null && requestedReservedQty.signum() > 0);
stockMoveLine.setSaleOrderLine(saleOrderLine);
stockMoveLine.setPurchaseOrderLine(purchaseOrderLine);
TrackingNumberConfiguration trackingNumberConfiguration = product.getTrackingNumberConfiguration();
return assignOrGenerateTrackingNumber(stockMoveLine, stockMove, product, trackingNumberConfiguration, type);
} else {
return this.createStockMoveLine(product, productName, description, quantity, BigDecimal.ZERO, BigDecimal.ZERO, companyUnitPriceUntaxed, BigDecimal.ZERO, unit, stockMove, null);
}
}
use of com.axelor.apps.stock.db.TrackingNumberConfiguration 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.TrackingNumberConfiguration in project axelor-open-suite by axelor.
the class ImportTrackingNumberConfig method computeFullName.
@Transactional(rollbackOn = { Exception.class })
public Object computeFullName(Object bean, Map<String, Object> values) throws AxelorException {
assert bean instanceof TrackingNumberConfiguration;
TrackingNumberConfiguration trackingNumberConfiguration = (TrackingNumberConfiguration) bean;
Sequence sequence = trackingNumberConfiguration.getSequence();
String name = trackingNumberConfiguration.getName();
trackingNumberConfiguration.setFullName(name);
if (sequence != null) {
trackingNumberConfiguration.setFullName(name + " / " + sequence.getFullName());
}
return trackingNumberConfiguration;
}
use of com.axelor.apps.stock.db.TrackingNumberConfiguration 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