Search in sources :

Example 1 with AccountType

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

the class ImportJournal method importAccountType.

public Object importAccountType(Object bean, Map<String, Object> values) {
    assert bean instanceof Journal;
    Journal journal = (Journal) bean;
    // Only 'Manual misc ops' Journal
    String importId = journal.getImportId();
    if (!"24".equals(importId)) {
        return bean;
    }
    Set<AccountType> accountTypesSet = new HashSet<AccountType>(Beans.get(AccountTypeRepository.class).all().fetch());
    journal.setValidAccountTypeSet(accountTypesSet);
    return journal;
}
Also used : Journal(com.axelor.apps.account.db.Journal) AccountType(com.axelor.apps.account.db.AccountType) AccountTypeRepository(com.axelor.apps.account.db.repo.AccountTypeRepository) HashSet(java.util.HashSet)

Example 2 with AccountType

use of com.axelor.apps.account.db.AccountType 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

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