use of com.axelor.apps.account.db.AccountingReportConfigLine in project axelor-open-suite by axelor.
the class ImportAccountingReportConfigLine method setAccounts.
@Transactional(rollbackOn = { Exception.class })
public Object setAccounts(Object bean, Map<String, Object> values) throws AxelorException {
assert bean instanceof AccountingReportConfigLine;
AccountingReportConfigLine configLine = (AccountingReportConfigLine) bean;
if (configLine.getRuleTypeSelect() == AccountingReportConfigLineRepository.RULE_TYPE_SUM_OF_ACCOUNTS) {
String accountTypeValues = (String) values.get("accountType");
if (accountTypeValues != null && !accountTypeValues.isEmpty()) {
String[] types = accountTypeValues.split("\\|");
Set<AccountType> accountTypes = new HashSet<>();
AccountType typeToAdd;
for (String type : types) {
typeToAdd = accountTypeRepo.all().filter("self.importId = :importId").bind("importId", type).fetchOne();
if (typeToAdd != null) {
accountTypes.add(typeToAdd);
}
}
configLine.setAccountTypeSet(accountTypes);
}
String accountValues = (String) values.get("accountCode");
if (accountValues != null && !accountValues.isEmpty()) {
String[] codes = accountValues.split("\\|");
Set<Account> accounts = new HashSet<>();
Account accountToAdd;
List<Account> fetched;
for (String code : codes) {
accountToAdd = accountRepo.all().filter("self.code = :code").bind("code", code).fetchOne();
if (accountToAdd == null) {
fetched = accountRepo.all().fetch();
for (Account account : fetched) {
if (compareCodes(account.getCode(), code)) {
accountToAdd = account;
break;
}
}
}
if (accountToAdd != null) {
accounts.add(accountToAdd);
}
}
configLine.setAccountSet(accounts);
}
accountingReportConfigLineRepo.save(configLine);
}
return configLine;
}
Aggregations