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;
}
Aggregations