Download as pdf or txt
Download as pdf or txt
You are on page 1of 2

AccountAccountRepository.

java 12/26/2021 12:31 PM

1 /*
2 * Axelor Business Solutions
3 *
4 * Copyright (C) 2021 Axelor (<http://axelor.com>).
5 *
6 * This program is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU Affero General Public License, version 3,
8 * as published by the Free Software Foundation.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU Affero General Public License for more details.
14 *
15 * You should have received a copy of the GNU Affero General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18 package com.axelor.apps.account.db.repo;
19
20 import com.axelor.apps.account.db.Account;
21 import com.axelor.db.JPA;
22 import com.axelor.exception.service.TraceBackService;
23 import java.util.Set;
24 import javax.persistence.PersistenceException;
25
26 public class AccountAccountRepository extends AccountRepository {
27
28 @Override
29 public Account save(Account account) {
30 try {
31 if (account.getId() == null) {
32 return super.save(account);
33 }
34
35 if (account.getReconcileOk()) {
36 Set<Account> accountList = account.getCompatibleAccountSet();
37
38 if (accountList != null) {
39 for (Account acc : accountList) {
40 acc.setReconcileOk(true);
41 acc.addCompatibleAccountSetItem(account);
42 JPA.save(acc);
43 }
44 }
45 } else {
46
47 if (account.getCompatibleAccountSet() != null) {
48 for (Account acc : account.getCompatibleAccountSet()) {
49 acc.removeCompatibleAccountSetItem(account);
50 if (acc.getCompatibleAccountSet().size() == 0) {
51 acc.setReconcileOk(false);
52 }
53 JPA.save(acc);
54 }
55 account.getCompatibleAccountSet().clear();
56 }
57 }
58 return super.save(account);
59 } catch (Exception e) {
60 TraceBackService.traceExceptionFromSaveMethod(e);
61 throw new PersistenceException(e);
62 }
63 }
64 }

Page 1 of 2
AccountAccountRepository.java 12/26/2021 12:31 PM

65

Page 2 of 2

You might also like