use of com.axelor.apps.base.db.Sequence 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.base.db.Sequence 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