Search in sources :

Example 1 with AccountingReportConfigLine

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;
}
Also used : Account(com.axelor.apps.account.db.Account) AccountingReportConfigLine(com.axelor.apps.account.db.AccountingReportConfigLine) AccountType(com.axelor.apps.account.db.AccountType) HashSet(java.util.HashSet) Transactional(com.google.inject.persist.Transactional)

Aggregations

Account (com.axelor.apps.account.db.Account)1 AccountType (com.axelor.apps.account.db.AccountType)1 AccountingReportConfigLine (com.axelor.apps.account.db.AccountingReportConfigLine)1 Transactional (com.google.inject.persist.Transactional)1 HashSet (java.util.HashSet)1