Search in sources :

Example 1 with AccountChart

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

the class AccountChartController method installChart.

public void installChart(ActionRequest request, ActionResponse response) throws AxelorException {
    AccountConfig accountConfig = request.getContext().asType(AccountConfig.class);
    AccountChart act = Beans.get(AccountChartRepository.class).find(accountConfig.getAccountChart().getId());
    Company company = Beans.get(CompanyRepository.class).find(accountConfig.getCompany().getId());
    accountConfig = Beans.get(AccountConfigRepository.class).find(accountConfig.getId());
    List<? extends Account> accountList = Beans.get(AccountRepository.class).all().filter("self.company.id = ?1 AND self.parentAccount != null", company.getId()).fetch();
    if (accountList.isEmpty()) {
        if (Beans.get(AccountChartService.class).installAccountChart(act, company, accountConfig))
            response.setFlash(I18n.get(IExceptionMessage.ACCOUNT_CHART_1));
        else
            response.setFlash(I18n.get(IExceptionMessage.ACCOUNT_CHART_2));
        response.setReload(true);
    } else
        response.setFlash(I18n.get(IExceptionMessage.ACCOUNT_CHART_3));
}
Also used : Company(com.axelor.apps.base.db.Company) CompanyRepository(com.axelor.apps.base.db.repo.CompanyRepository) AccountChart(com.axelor.apps.account.db.AccountChart) AccountRepository(com.axelor.apps.account.db.repo.AccountRepository) AccountChartService(com.axelor.apps.account.service.AccountChartService) AccountChartRepository(com.axelor.apps.account.db.repo.AccountChartRepository) AccountConfig(com.axelor.apps.account.db.AccountConfig)

Example 2 with AccountChart

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

the class ImportAccountChart method importAccountChart.

public Object importAccountChart(Object bean, Map<String, Object> values) throws IOException {
    assert bean instanceof AccountChart;
    AccountChart accountChart = (AccountChart) bean;
    File zipFile = this.getZipFile(accountChart);
    try {
        final MetaFile metaFile = metaFiles.upload(zipFile);
        accountChart.setMetaFile(metaFile);
    } catch (Exception e) {
        e.printStackTrace();
        LOG.warn("Can't load file {} for accountChart {}", zipFile.getName(), accountChart.getName());
    }
    FileUtils.deleteDirectory(zipFile.getParentFile());
    return accountChart;
}
Also used : AccountChart(com.axelor.apps.account.db.AccountChart) MetaFile(com.axelor.meta.db.MetaFile) File(java.io.File) MetaFile(com.axelor.meta.db.MetaFile) IOException(java.io.IOException)

Aggregations

AccountChart (com.axelor.apps.account.db.AccountChart)2 AccountConfig (com.axelor.apps.account.db.AccountConfig)1 AccountChartRepository (com.axelor.apps.account.db.repo.AccountChartRepository)1 AccountRepository (com.axelor.apps.account.db.repo.AccountRepository)1 AccountChartService (com.axelor.apps.account.service.AccountChartService)1 Company (com.axelor.apps.base.db.Company)1 CompanyRepository (com.axelor.apps.base.db.repo.CompanyRepository)1 MetaFile (com.axelor.meta.db.MetaFile)1 File (java.io.File)1 IOException (java.io.IOException)1