Search in sources :

Example 6 with DebtRecovery

use of com.axelor.apps.account.db.DebtRecovery in project axelor-open-suite by axelor.

the class DebtRecoveryService method getDebtRecovery.

/**
 * Find an existing debtRecovery object for a corresponding partner, company and optionally,
 * trading name.
 *
 * @param partner A partner
 * @param company A company
 * @param tradingName (Optional) A trading name
 * @return The corresponding DebtRecovery object, storing information regarding the current debt
 *     recovery situation of the partner for this company & trading name
 * @throws AxelorException
 */
public DebtRecovery getDebtRecovery(Partner partner, Company company, TradingName tradingName) throws AxelorException {
    AccountingSituationRepository accSituationRepo = Beans.get(AccountingSituationRepository.class);
    AccountingSituation accountingSituation = accSituationRepo.all().filter("self.partner = ?1 and self.company = ?2", partner, company).fetchOne();
    if (accountingSituation == null) {
        throw new AxelorException(accountingSituation, TraceBackRepository.CATEGORY_CONFIGURATION_ERROR, "%s :\n" + I18n.get("Partner") + " %s, " + I18n.get("Company") + " %s : " + I18n.get(IExceptionMessage.DEBT_RECOVERY_1), I18n.get(com.axelor.apps.base.exceptions.IExceptionMessage.EXCEPTION), partner.getName(), company.getName());
    }
    if (tradingName == null) {
        return accountingSituation.getDebtRecovery();
    } else {
        if (accountingSituation.getTradingNameDebtRecoveryList() != null && !accountingSituation.getTradingNameDebtRecoveryList().isEmpty()) {
            for (DebtRecovery debtRecovery : accountingSituation.getTradingNameDebtRecoveryList()) {
                if (tradingName.equals(debtRecovery.getTradingName())) {
                    return debtRecovery;
                }
            }
        }
    }
    // if no debtRecovery has been found for the specified tradingName
    return null;
}
Also used : AxelorException(com.axelor.exception.AxelorException) AccountingSituationRepository(com.axelor.apps.account.db.repo.AccountingSituationRepository) AccountingSituation(com.axelor.apps.account.db.AccountingSituation) DebtRecovery(com.axelor.apps.account.db.DebtRecovery)

Aggregations

DebtRecovery (com.axelor.apps.account.db.DebtRecovery)6 AxelorException (com.axelor.exception.AxelorException)4 AccountingSituation (com.axelor.apps.account.db.AccountingSituation)3 AccountingSituationRepository (com.axelor.apps.account.db.repo.AccountingSituationRepository)2 Transactional (com.google.inject.persist.Transactional)2 DebtRecoveryHistory (com.axelor.apps.account.db.DebtRecoveryHistory)1 DebtRecoveryMethod (com.axelor.apps.account.db.DebtRecoveryMethod)1 MoveLine (com.axelor.apps.account.db.MoveLine)1 DebtRecoveryActionService (com.axelor.apps.account.service.debtrecovery.DebtRecoveryActionService)1 Company (com.axelor.apps.base.db.Company)1 Partner (com.axelor.apps.base.db.Partner)1 TradingName (com.axelor.apps.base.db.TradingName)1 BigDecimal (java.math.BigDecimal)1 LocalDate (java.time.LocalDate)1 ArrayList (java.util.ArrayList)1