r3413 - in trunk: lima-business/src/main/java/org/chorem/lima/business/accountingrules lima-business/src/main/java/org/chorem/lima/business/ejb lima-business/src/test/java/org/chorem/lima/business lima-business/src/test/java/org/chorem/lima/entity lima-callao/src/main/java/org/chorem/lima/entity
Author: echatellier Date: 2012-05-14 18:00:59 +0200 (Mon, 14 May 2012) New Revision: 3413 Url: http://chorem.org/repositories/revision/lima/3413 Log: Fix all tests Modified: trunk/lima-business/src/main/java/org/chorem/lima/business/accountingrules/DefaultAccountingRules.java trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/EntryBookServiceImpl.java trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/FinancialPeriodServiceImpl.java trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/FinancialTransactionServiceImpl.java trunk/lima-business/src/test/java/org/chorem/lima/business/ImportServiceImplTest.java trunk/lima-business/src/test/java/org/chorem/lima/entity/FinancialTransactionDAOTest.java trunk/lima-callao/src/main/java/org/chorem/lima/entity/ClosedPeriodicEntryBookDAOImpl.java trunk/lima-callao/src/main/java/org/chorem/lima/entity/FinancialTransactionDAOImpl.java Modified: trunk/lima-business/src/main/java/org/chorem/lima/business/accountingrules/DefaultAccountingRules.java =================================================================== --- trunk/lima-business/src/main/java/org/chorem/lima/business/accountingrules/DefaultAccountingRules.java 2012-05-14 10:38:31 UTC (rev 3412) +++ trunk/lima-business/src/main/java/org/chorem/lima/business/accountingrules/DefaultAccountingRules.java 2012-05-14 16:00:59 UTC (rev 3413) @@ -203,19 +203,23 @@ try { FinancialTransactionDAO financialTransactionDAO = getDaoHelper().getFinancialTransactionDAO(); + ClosedPeriodicEntryBookDAO closedPeriodicEntryBookDAO = getDaoHelper().getClosedPeriodicEntryBookDAO(); + // reload object in current transaction + closedPeriodicEntryBook = closedPeriodicEntryBookDAO.findByTopiaId(closedPeriodicEntryBook.getTopiaId()); // Check if all financial transactions of closedperiodicentrybook are equilibrate // FIMXE echatellier 20120504 unutile de recuperer une liste // entiere juste pour tester l'existence - List<FinancialTransaction> result = financialTransactionDAO.getAllUnbalancedTransaction(closedPeriodicEntryBook.getFinancialPeriod(), - closedPeriodicEntryBook.getEntryBook()); + FinancialPeriod period = closedPeriodicEntryBook.getFinancialPeriod(); + List<FinancialTransaction> result = financialTransactionDAO.getAllUnbalancedTransaction(period.getBeginDate(), + period.getEndDate(), closedPeriodicEntryBook.getEntryBook()); if (result.size() > 0) { throw new LimaBusinessException(_("lima-business.defaultaccountingrules.blockerrorequillibrate")); } // Check if all financial transactions of this closedperiodicentrybook/financialPeriod are well filled in - result = financialTransactionDAO.getAllUnfilledTransaction(closedPeriodicEntryBook.getFinancialPeriod(), - closedPeriodicEntryBook.getEntryBook()); + result = financialTransactionDAO.getAllUnfilledTransaction(period.getBeginDate(), + period.getEndDate(), closedPeriodicEntryBook.getEntryBook()); // FIMXE echatellier 20120504 unutile de recuperer une liste // entiere juste pour tester l'existence if (result.size() > 0) { Modified: trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/EntryBookServiceImpl.java =================================================================== --- trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/EntryBookServiceImpl.java 2012-05-14 10:38:31 UTC (rev 3412) +++ trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/EntryBookServiceImpl.java 2012-05-14 16:00:59 UTC (rev 3413) @@ -142,10 +142,12 @@ AccountingRules accountingRules = LimaConfig.getInstance().getAccountingRules(); + // check rule + accountingRules.removeEntryBookRules(entryBook); + try { - // check rule - accountingRules.removeEntryBookRules(entryBook); + // delete all ClosedPeriodicEntryBook from this EntryBook ClosedPeriodicEntryBookDAO closedPeriodicEntryBookDAO = Modified: trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/FinancialPeriodServiceImpl.java =================================================================== --- trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/FinancialPeriodServiceImpl.java 2012-05-14 10:38:31 UTC (rev 3412) +++ trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/FinancialPeriodServiceImpl.java 2012-05-14 16:00:59 UTC (rev 3413) @@ -182,12 +182,13 @@ ClosedPeriodicEntryBookDAO closedPeriodicEntryBookDAO = getDaoHelper().getClosedPeriodicEntryBookDAO(); - //ClosedPeriodicEntryBook closedPeriodicEntryBook2 = - // closedPeriodicEntryBookDAO.findByTopiaId( - // closedPeriodicEntryBook.getTopiaId()); + // reload object in current transaction + ClosedPeriodicEntryBook closedPeriodicEntryBook2 = + closedPeriodicEntryBookDAO.findByTopiaId( + closedPeriodicEntryBook.getTopiaId()); - closedPeriodicEntryBook.setLocked(true); - closedPeriodicEntryBookDAO.update(closedPeriodicEntryBook); + closedPeriodicEntryBook2.setLocked(true); + closedPeriodicEntryBookDAO.update(closedPeriodicEntryBook2); } catch (TopiaException ex) { throw new LimaException("Can't block period", ex); Modified: trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/FinancialTransactionServiceImpl.java =================================================================== --- trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/FinancialTransactionServiceImpl.java 2012-05-14 10:38:31 UTC (rev 3412) +++ trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/FinancialTransactionServiceImpl.java 2012-05-14 16:00:59 UTC (rev 3413) @@ -162,14 +162,14 @@ public List<FinancialTransaction> getAllInexactFinancialTransactions(FiscalPeriod fiscalPeriod) throws LimaException { List<FinancialTransaction> result = null; - List<FinancialTransaction> checkedResult = new ArrayList<FinancialTransaction>(); + //List<FinancialTransaction> checkedResult = new ArrayList<FinancialTransaction>(); try { FinancialTransactionDAO financialTransactionDAO = getDaoHelper().getFinancialTransactionDAO(); result = financialTransactionDAO.getAllIncorrectTransaction(fiscalPeriod.getBeginDate(), fiscalPeriod.getEndDate(), null); - for (FinancialTransaction fTransaction : result) { + /*for (FinancialTransaction fTransaction : result) { BigDecimal credit = fTransaction.getAmountCredit(); BigDecimal debit = fTransaction.getAmountDebit(); credit = credit.setScale(optionsService.getScale(), @@ -179,7 +179,7 @@ if (credit.equals(debit)) { checkedResult.add(fTransaction); } - } + }*/ } catch (Exception ex) { throw new LimaException("Can't get financial transactions", ex); Modified: trunk/lima-business/src/test/java/org/chorem/lima/business/ImportServiceImplTest.java =================================================================== --- trunk/lima-business/src/test/java/org/chorem/lima/business/ImportServiceImplTest.java 2012-05-14 10:38:31 UTC (rev 3412) +++ trunk/lima-business/src/test/java/org/chorem/lima/business/ImportServiceImplTest.java 2012-05-14 16:00:59 UTC (rev 3413) @@ -148,7 +148,7 @@ String pcg = IOUtils.toString(ImportServiceImplTest.class.getResourceAsStream("/import/pcg_base.csv")); importService.importAsCSV(pcg, ImportExportEntityEnum.ACCOUNT); - Assert.assertEquals(460, accountService.getAccountCount()); + Assert.assertEquals(461, accountService.getAccountCount()); } /** Modified: trunk/lima-business/src/test/java/org/chorem/lima/entity/FinancialTransactionDAOTest.java =================================================================== --- trunk/lima-business/src/test/java/org/chorem/lima/entity/FinancialTransactionDAOTest.java 2012-05-14 10:38:31 UTC (rev 3412) +++ trunk/lima-business/src/test/java/org/chorem/lima/entity/FinancialTransactionDAOTest.java 2012-05-14 16:00:59 UTC (rev 3413) @@ -65,7 +65,8 @@ TopiaContext tx = getTestContext().beginTransaction(); FinancialTransactionDAO ftDAO = LimaCallaoDAOHelper.getFinancialTransactionDAO(tx); - List<FinancialTransaction> fTransactions = ftDAO.getAllUnbalancedTransaction(financialPeriod, journalDesVentes); + List<FinancialTransaction> fTransactions = ftDAO.getAllUnbalancedTransaction(financialPeriod.getBeginDate(), + financialPeriod.getEndDate(), journalDesVentes); Assert.assertNotNull(fTransactions); } } Modified: trunk/lima-callao/src/main/java/org/chorem/lima/entity/ClosedPeriodicEntryBookDAOImpl.java =================================================================== --- trunk/lima-callao/src/main/java/org/chorem/lima/entity/ClosedPeriodicEntryBookDAOImpl.java 2012-05-14 10:38:31 UTC (rev 3412) +++ trunk/lima-callao/src/main/java/org/chorem/lima/entity/ClosedPeriodicEntryBookDAOImpl.java 2012-05-14 16:00:59 UTC (rev 3413) @@ -28,11 +28,26 @@ import java.util.Date; import java.util.List; +import org.hibernate.HibernateException; import org.nuiton.topia.TopiaException; public class ClosedPeriodicEntryBookDAOImpl<E extends ClosedPeriodicEntryBook> extends ClosedPeriodicEntryBookDAOAbstract<ClosedPeriodicEntryBook> { /** + * FIXME echatellier, remove this method when implemented in topia + * just overriden to use merge() instead of saveOrUpdate() + */ + public ClosedPeriodicEntryBook merge(ClosedPeriodicEntryBook e) throws TopiaException { + try { + e = (ClosedPeriodicEntryBook)getContext().getHibernate().merge(e); + getContext().getFiresSupport().warnOnUpdateEntity(e); + return e; + } catch (HibernateException ex) { + throw new TopiaException(ex); + } + } + + /** * Find all ClosedPeriodicEntryBook with common EntryBook. * * @param entryBook entry book property Modified: trunk/lima-callao/src/main/java/org/chorem/lima/entity/FinancialTransactionDAOImpl.java =================================================================== --- trunk/lima-callao/src/main/java/org/chorem/lima/entity/FinancialTransactionDAOImpl.java 2012-05-14 10:38:31 UTC (rev 3412) +++ trunk/lima-callao/src/main/java/org/chorem/lima/entity/FinancialTransactionDAOImpl.java 2012-05-14 16:00:59 UTC (rev 3413) @@ -91,29 +91,6 @@ beginDate, "endDate", endDate, "entryBook", entryBook); return result; } - - /** - * Find all unbalanced transactions. - * - * @param financialPeriod period - * @param entryBook entry book - * @return unbalanced transactions - * @throws TopiaException - */ - @Deprecated - public List<FinancialTransaction> getAllUnbalancedTransaction(FinancialPeriod financialPeriod, - EntryBook entryBook) throws TopiaException { - String query = "FROM " + FinancialTransaction.class.getName() + " T"+ - " WHERE (SELECT sum(amount) FROM " + Entry.class.getName() + - " WHERE debit = true AND financialTransaction = T) != " + - " (SELECT sum(amount) FROM " + Entry.class.getName() + - " WHERE debit = false AND financialTransaction = T)" + - " AND T.financialPeriod = :financialPeriod" + - " AND T.entryBook = :entryBook"; - List<FinancialTransaction> result = context.find(query, "financialPeriod", - financialPeriod, "entryBook", entryBook); - return result; - } /** * Find all unbalanced transactions. @@ -184,12 +161,16 @@ */ public List<FinancialTransaction> getAllIncorrectTransaction(Date beginDate, Date endDate, EntryBook entryBook) throws TopiaException { - String query = "FROM " + FinancialTransaction.class.getName() + " T"+ + String query = "SELECT T FROM " + FinancialTransaction.class.getName() + " T"+ " LEFT JOIN T.entry AS E" + " WHERE ((SELECT sum(amount) FROM " + Entry.class.getName() + " WHERE debit = true AND financialTransaction = T) != " + " (SELECT sum(amount) FROM " + Entry.class.getName() + " WHERE debit = false AND financialTransaction = T)" + + " OR (SELECT sum(amount) FROM " + Entry.class.getName() + + " WHERE debit = true AND financialTransaction = T) IS NULL" + + " OR (SELECT sum(amount) FROM " + Entry.class.getName() + + " WHERE debit = false AND financialTransaction = T) IS NULL" + " OR E.account = null" + " OR E.voucher = null" + " OR E.voucher = ''" + @@ -211,25 +192,26 @@ /** * Find all transaction where some field are not filled in. * - * @param financialPeriod period + * @param beginDate begin date + * @param endDate end date * @param entryBook entry book * @return unfilled transaction * @throws TopiaException */ - @Deprecated - public List<FinancialTransaction> getAllUnfilledTransaction(FinancialPeriod financialPeriod, - EntryBook entryBook) throws TopiaException { - String query = "FROM " + FinancialTransaction.class.getName() + " T"+ + public List<FinancialTransaction> getAllUnfilledTransaction(Date beginDate, + Date endDate, EntryBook entryBook) throws TopiaException { + String query = "SELECT T FROM " + FinancialTransaction.class.getName() + " T"+ " LEFT JOIN T.entry AS E" + " WHERE ((SELECT sum(amount) FROM " + Entry.class.getName() + " WHERE debit = true AND financialTransaction = T) != " + " (SELECT sum(amount) FROM " + Entry.class.getName() + - " WHERE debit = false AND financialTransaction = T) + OR E.account = null" + + " WHERE debit = false AND financialTransaction = T) OR E.account = null" + " OR E.voucher = null OR E.voucher = '' OR E.description = null OR E.description = '')" + " AND T.entryBook = :entryBook" + - " AND T.financialPeriod = :financialPeriod"; - List<FinancialTransaction> result = context.find(query, "financialPeriod", - financialPeriod, "entryBook", entryBook); + " AND :beginDate <= T.transactionDate" + + " AND T.transactionDate <= :endDate"; + List<FinancialTransaction> result = context.find(query, "beginDate", beginDate, + "endDate", endDate, "entryBook", entryBook); return result; } @@ -243,12 +225,12 @@ */ public List<FinancialTransaction> getAllTransactionWithoutEntryBook() throws TopiaException { - String query = "FROM " + FinancialTransaction.class.getName() + " T"+ + String query = "SELECT T FROM " + FinancialTransaction.class.getName() + " T"+ " LEFT JOIN T.entry AS E" + " WHERE ((SELECT sum(amount) FROM " + Entry.class.getName() + " WHERE debit = true AND financialTransaction = T) != " + " (SELECT sum(amount) FROM " + Entry.class.getName() + - " WHERE debit = false AND financialTransaction = T) + OR E.account = null" + + " WHERE debit = false AND financialTransaction = T) OR E.account = null" + " OR E.voucher = null OR E.voucher = '' OR E.description = null OR E.description = '')" + " AND entryBook = null"; // FIXME echatellier 20120504 doesn't concern a period ? all database ?
participants (1)
-
echatellier@users.chorem.org