details: https://code.openbravo.com/erp/devel/pi/rev/bb7b3752a14d changeset: 26164:bb7b3752a14d user: Atul Gaware <atul.gaware <at> openbravo.com> date: Wed Mar 11 11:48:22 2015 +0530 summary: Fixes Issue 29110:It is not possible to change currency in header tab in G/L Journal
As there is trigger mutating error, updation of gl journal line currency and currency rate is moved to a event handler from gl_journal_trg trigger. details: https://code.openbravo.com/erp/devel/pi/rev/ac9670b7bfdd changeset: 26165:ac9670b7bfdd user: Alvaro Ferraz <alvaro.ferraz <at> openbravo.com> date: Wed Mar 11 13:23:31 2015 +0100 summary: Related to issue 29110: Added a clear inside the loop Added a clear inside the loop to avoid performance problems diffstat: src-db/database/model/triggers/GL_JOURNAL_TRG.xml | 8 +- src/org/openbravo/event/GLJournalEventHandler.java | 86 ++++++++++++++++++++++ 2 files changed, 87 insertions(+), 7 deletions(-) diffs (116 lines): diff -r 5a9f94c18c9b -r ac9670b7bfdd src-db/database/model/triggers/GL_JOURNAL_TRG.xml --- a/src-db/database/model/triggers/GL_JOURNAL_TRG.xml Wed Mar 11 15:19:41 2015 +0000 +++ b/src-db/database/model/triggers/GL_JOURNAL_TRG.xml Wed Mar 11 13:23:31 2015 +0100 @@ -17,7 +17,7 @@ * parts created by ComPiere are Copyright (C) ComPiere, Inc.; * All Rights Reserved. * Contributor(s): Openbravo SLU - * Contributions are Copyright (C) 2001-2008 Openbravo, S.L.U. + * Contributions are Copyright (C) 2001-2015 Openbravo, S.L.U. * * Specifically, this derivative work is based upon the following Compiere * file and version. @@ -34,12 +34,6 @@ -- Subtract Old Amount IF(UPDATING) THEN - IF (:old.c_currency_id <> :new.c_currency_id) THEN - UPDATE gl_journalline SET c_currency_id = :new.c_currency_id where gl_journal_id = :old.gl_journal_id; - END IF; - IF (:old.currencyrate <> :new.currencyrate) THEN - UPDATE gl_journalline SET currencyrate = :new.currencyrate where gl_journal_id = :old.gl_journal_id; - END IF; IF(:old.TotalDr <> :NEW.TotalDr OR :OLD.TotalCr <> :NEW.TotalCr) THEN IF(:old.GL_JournalBatch_ID IS NOT NULL AND :old.IsActive='Y') THEN UPDATE GL_JournalBatch diff -r 5a9f94c18c9b -r ac9670b7bfdd src/org/openbravo/event/GLJournalEventHandler.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/org/openbravo/event/GLJournalEventHandler.java Wed Mar 11 13:23:31 2015 +0100 @@ -0,0 +1,86 @@ +/* + ************************************************************************* + * The contents of this file are subject to the Openbravo Public License + * Version 1.0 (the "License"), being the Mozilla Public License + * Version 1.1 with a permitted attribution clause; you may not use this + * file except in compliance with the License. You may obtain a copy of + * the License at http://www.openbravo.com/legal/license.html + * Software distributed under the License is distributed on an "AS IS" + * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the + * License for the specific language governing rights and limitations + * under the License. + * The Original Code is Openbravo ERP. + * The Initial Developer of the Original Code is Openbravo SLU + * All portions are Copyright (C) 2015 Openbravo SLU + * All Rights Reserved. + * Contributor(s): ______________________________________. + ************************************************************************* + */ +package org.openbravo.event; + +import javax.enterprise.event.Observes; + +import org.apache.log4j.Logger; +import org.hibernate.ScrollMode; +import org.hibernate.ScrollableResults; +import org.hibernate.criterion.Restrictions; +import org.openbravo.base.model.Entity; +import org.openbravo.base.model.ModelProvider; +import org.openbravo.base.model.Property; +import org.openbravo.client.kernel.event.EntityPersistenceEventObserver; +import org.openbravo.client.kernel.event.EntityUpdateEvent; +import org.openbravo.dal.service.OBCriteria; +import org.openbravo.dal.service.OBDal; +import org.openbravo.model.financialmgmt.gl.GLJournal; +import org.openbravo.model.financialmgmt.gl.GLJournalLine; + +public class GLJournalEventHandler extends EntityPersistenceEventObserver { + protected Logger logger = Logger.getLogger(this.getClass()); + private static Entity[] entities = { ModelProvider.getInstance().getEntity(GLJournal.ENTITY_NAME) }; + + @Override + protected Entity[] getObservedEntities() { + return entities; + } + + public void onUpdate(@Observes EntityUpdateEvent event) { + if (!isValidEvent(event)) { + return; + } + final GLJournal glj = (GLJournal) event.getTargetInstance(); + // Update GLJournalLine with updated Currency and Currency Rate. + final Entity gljournal = ModelProvider.getInstance().getEntity(GLJournal.ENTITY_NAME); + final Property currencyProperty = gljournal.getProperty(GLJournal.PROPERTY_CURRENCY); + final Property currencyRate = gljournal.getProperty(GLJournal.PROPERTY_RATE); + if (!event.getCurrentState(currencyProperty).equals(event.getPreviousState(currencyProperty)) + || !event.getCurrentState(currencyRate).equals(event.getPreviousState(currencyRate))) { + OBCriteria<GLJournalLine> gljournallineCriteria = OBDal.getInstance().createCriteria( + GLJournalLine.class); + gljournallineCriteria.add(Restrictions.eq(GLJournalLine.PROPERTY_JOURNALENTRY, glj)); + ScrollableResults scrollLines = gljournallineCriteria.scroll(ScrollMode.FORWARD_ONLY); + if (gljournallineCriteria.count() > 0) { + try { + int i = 0; + while (scrollLines.next()) { + final GLJournalLine journalLine = (GLJournalLine) scrollLines.get()[0]; + if (!glj.getCurrency().getId().equals(journalLine.getCurrency().getId())) { + journalLine.setCurrency(glj.getCurrency()); + OBDal.getInstance().save(journalLine); + } + if (!glj.getRate().equals(journalLine.getRate())) { + journalLine.setRate(glj.getRate()); + OBDal.getInstance().save(journalLine); + } + i++; + if (i % 100 == 0) { + OBDal.getInstance().flush(); + OBDal.getInstance().getSession().clear(); + } + } + } finally { + scrollLines.close(); + } + } + } + } +} \ No newline at end of file ------------------------------------------------------------------------------ Dive into the World of Parallel Programming The Go Parallel Website, sponsored by Intel and developed in partnership with Slashdot Media, is your hub for all things parallel software development, from weekly thought leadership blogs to news, videos, case studies, tutorials and more. Take a look and join the conversation now. http://goparallel.sourceforge.net/ _______________________________________________ Openbravo-commits mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/openbravo-commits
