Search in sources :

Example 16 with Sequence

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;
}
Also used : Sequence(com.axelor.apps.base.db.Sequence) TrackingNumberConfiguration(com.axelor.apps.stock.db.TrackingNumberConfiguration) Transactional(com.google.inject.persist.Transactional)

Example 17 with Sequence

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;
}
Also used : AxelorException(com.axelor.exception.AxelorException) TrackingNumber(com.axelor.apps.stock.db.TrackingNumber) Sequence(com.axelor.apps.base.db.Sequence) TrackingNumberConfiguration(com.axelor.apps.stock.db.TrackingNumberConfiguration)

Aggregations

Sequence (com.axelor.apps.base.db.Sequence)17 AxelorException (com.axelor.exception.AxelorException)8 Transactional (com.google.inject.persist.Transactional)4 Account (com.axelor.apps.account.db.Account)3 Partner (com.axelor.apps.base.db.Partner)3 SequenceVersion (com.axelor.apps.base.db.SequenceVersion)2 SequenceService (com.axelor.apps.base.service.administration.SequenceService)2 TrackingNumberConfiguration (com.axelor.apps.stock.db.TrackingNumberConfiguration)2 HRConfig (com.axelor.apps.hr.db.HRConfig)1 ProductionConfig (com.axelor.apps.production.db.ProductionConfig)1 AppProductionService (com.axelor.apps.production.service.app.AppProductionService)1 ProductionConfigService (com.axelor.apps.production.service.config.ProductionConfigService)1 TrackingNumber (com.axelor.apps.stock.db.TrackingNumber)1