Search in sources :

Example 1 with Sequence

use of com.axelor.apps.base.db.Sequence in project axelor-open-suite by axelor.

the class AccountingSituationInitServiceImpl method createSupplierAccount.

protected void createSupplierAccount(AccountConfig accountConfig, AccountingSituation situation, int creationMode) throws AxelorException {
    Partner partner = situation.getPartner();
    if (partner.getIsSupplier() == Boolean.FALSE || situation.getSupplierAccount() != null)
        return;
    if (accountConfig.getSupplierAccount() == null) {
        throw new AxelorException(partner, TraceBackRepository.CATEGORY_MISSING_FIELD, I18n.get(IExceptionMessage.ACCOUNT_CUSTOMER_2), I18n.get(com.axelor.apps.base.exceptions.IExceptionMessage.EXCEPTION), situation.getCompany().getName());
    }
    final String accountCode;
    if (creationMode == AccountConfigRepository.AUTOMATIC_ACCOUNT_CREATION_PREFIX) {
        final String prefix = accountConfig.getSupplierAccountPrefix();
        if (StringUtils.isBlank(prefix)) {
            throw new AxelorException(situation, TraceBackRepository.CATEGORY_MISSING_FIELD, I18n.get(IExceptionMessage.ACCOUNTING_SITUATION_4), situation.getCompany().getName());
        }
        accountCode = getPrefixedAccountCode(prefix, partner);
    } else if (creationMode == AccountConfigRepository.AUTOMATIC_ACCOUNT_CREATION_SEQUENCE) {
        final Sequence sequence = accountConfig.getSupplierAccountSequence();
        if (sequence == null) {
            throw new AxelorException(situation, TraceBackRepository.CATEGORY_MISSING_FIELD, I18n.get(IExceptionMessage.ACCOUNTING_SITUATION_5), situation.getCompany().getName());
        }
        accountCode = sequenceService.getSequenceNumber(sequence);
    } else {
        throw new AxelorException(situation, TraceBackRepository.CATEGORY_INCONSISTENCY, I18n.get(IExceptionMessage.ACCOUNTING_SITUATION_3), situation.getCompany().getName());
    }
    Account account = this.createAccount(partner.getFullName(), accountCode, accountConfig.getSupplierAccount(), accountConfig.getSupplierAccount().getAccountType(), true, situation.getCompany(), true);
    situation.setSupplierAccount(account);
}
Also used : AxelorException(com.axelor.exception.AxelorException) Account(com.axelor.apps.account.db.Account) Sequence(com.axelor.apps.base.db.Sequence) Partner(com.axelor.apps.base.db.Partner)

Example 2 with Sequence

use of com.axelor.apps.base.db.Sequence in project axelor-open-suite by axelor.

the class AccountingSituationInitServiceImpl method createCustomerAccount.

protected void createCustomerAccount(AccountConfig accountConfig, AccountingSituation situation, int creationMode) throws AxelorException {
    Partner partner = situation.getPartner();
    if (partner.getIsCustomer() == Boolean.FALSE || situation.getCustomerAccount() != null)
        return;
    if (accountConfig.getCustomerAccount() == null) {
        throw new AxelorException(partner, TraceBackRepository.CATEGORY_MISSING_FIELD, I18n.get(IExceptionMessage.ACCOUNT_CUSTOMER_1), I18n.get(com.axelor.apps.base.exceptions.IExceptionMessage.EXCEPTION), situation.getCompany().getName());
    }
    final String accountCode;
    if (creationMode == AccountConfigRepository.AUTOMATIC_ACCOUNT_CREATION_PREFIX) {
        final String prefix = accountConfig.getCustomerAccountPrefix();
        if (StringUtils.isBlank(prefix)) {
            throw new AxelorException(situation, TraceBackRepository.CATEGORY_MISSING_FIELD, I18n.get(IExceptionMessage.ACCOUNTING_SITUATION_1), situation.getCompany().getName());
        }
        accountCode = getPrefixedAccountCode(prefix, partner);
    } else if (creationMode == AccountConfigRepository.AUTOMATIC_ACCOUNT_CREATION_SEQUENCE) {
        final Sequence sequence = accountConfig.getCustomerAccountSequence();
        if (sequence == null) {
            throw new AxelorException(situation, TraceBackRepository.CATEGORY_MISSING_FIELD, I18n.get(IExceptionMessage.ACCOUNTING_SITUATION_2), situation.getCompany().getName());
        }
        accountCode = sequenceService.getSequenceNumber(sequence);
    } else {
        throw new AxelorException(situation, TraceBackRepository.CATEGORY_INCONSISTENCY, I18n.get(IExceptionMessage.ACCOUNTING_SITUATION_3), situation.getCompany().getName());
    }
    Account account = this.createAccount(partner.getFullName(), accountCode, accountConfig.getCustomerAccount(), accountConfig.getCustomerAccount().getAccountType(), true, situation.getCompany(), true);
    situation.setCustomerAccount(account);
}
Also used : AxelorException(com.axelor.exception.AxelorException) Account(com.axelor.apps.account.db.Account) Sequence(com.axelor.apps.base.db.Sequence) Partner(com.axelor.apps.base.db.Partner)

Example 3 with Sequence

use of com.axelor.apps.base.db.Sequence in project axelor-open-suite by axelor.

the class AccountingSituationInitServiceImpl method createEmployeeAccount.

protected void createEmployeeAccount(AccountConfig accountConfig, AccountingSituation situation, int creationMode) throws AxelorException {
    Partner partner = situation.getPartner();
    if (partner.getIsEmployee() == Boolean.FALSE || situation.getEmployeeAccount() != null)
        return;
    if (accountConfig.getEmployeeAccount() == null) {
        throw new AxelorException(partner, TraceBackRepository.CATEGORY_MISSING_FIELD, I18n.get(IExceptionMessage.ACCOUNT_CONFIG_40), I18n.get(com.axelor.apps.base.exceptions.IExceptionMessage.EXCEPTION), situation.getCompany().getName());
    }
    final String accountCode;
    if (creationMode == AccountConfigRepository.AUTOMATIC_ACCOUNT_CREATION_PREFIX) {
        final String prefix = accountConfig.getEmployeeAccountPrefix();
        if (StringUtils.isBlank(prefix)) {
            throw new AxelorException(situation, TraceBackRepository.CATEGORY_MISSING_FIELD, I18n.get(IExceptionMessage.ACCOUNTING_SITUATION_6), situation.getCompany().getName());
        }
        accountCode = getPrefixedAccountCode(prefix, partner);
    } else if (creationMode == AccountConfigRepository.AUTOMATIC_ACCOUNT_CREATION_SEQUENCE) {
        final Sequence sequence = accountConfig.getEmployeeAccountSequence();
        if (sequence == null) {
            throw new AxelorException(situation, TraceBackRepository.CATEGORY_MISSING_FIELD, I18n.get(IExceptionMessage.ACCOUNTING_SITUATION_7), situation.getCompany().getName());
        }
        accountCode = sequenceService.getSequenceNumber(sequence);
    } else {
        throw new AxelorException(situation, TraceBackRepository.CATEGORY_INCONSISTENCY, I18n.get(IExceptionMessage.ACCOUNTING_SITUATION_3), situation.getCompany().getName());
    }
    Account account = this.createAccount(partner.getFullName(), accountCode, accountConfig.getEmployeeAccount(), accountConfig.getEmployeeAccount().getAccountType(), true, situation.getCompany(), true);
    situation.setEmployeeAccount(account);
}
Also used : AxelorException(com.axelor.exception.AxelorException) Account(com.axelor.apps.account.db.Account) Sequence(com.axelor.apps.base.db.Sequence) Partner(com.axelor.apps.base.db.Partner)

Example 4 with Sequence

use of com.axelor.apps.base.db.Sequence in project axelor-open-suite by axelor.

the class SequenceService method getSequenceNumber.

/**
 * Method returning a sequence number from a given generic sequence and a date
 *
 * @param sequence
 * @param refDate
 * @return
 */
@Transactional
public String getSequenceNumber(Sequence sequence, LocalDate refDate) {
    Sequence seq = JPA.em().createQuery("SELECT self FROM Sequence self WHERE id = :id", Sequence.class).setParameter("id", sequence.getId()).setLockMode(LockModeType.PESSIMISTIC_WRITE).setFlushMode(FlushModeType.COMMIT).getSingleResult();
    SequenceVersion sequenceVersion = getVersion(seq, refDate);
    String nextSeq = computeNextSeq(sequenceVersion, seq, refDate);
    sequenceVersion.setNextNum(sequenceVersion.getNextNum() + seq.getToBeAdded());
    if (sequenceVersion.getId() == null) {
        sequenceVersionRepository.save(sequenceVersion);
    }
    return nextSeq;
}
Also used : SequenceVersion(com.axelor.apps.base.db.SequenceVersion) Sequence(com.axelor.apps.base.db.Sequence) Transactional(com.google.inject.persist.Transactional)

Example 5 with Sequence

use of com.axelor.apps.base.db.Sequence in project axelor-open-suite by axelor.

the class SequenceBaseRepository method copy.

@Override
public Sequence copy(Sequence sequence, boolean deep) {
    Sequence copy = super.copy(sequence, deep);
    copy.clearSequenceVersionList();
    return copy;
}
Also used : Sequence(com.axelor.apps.base.db.Sequence)

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