details: https://code.openbravo.com/erp/devel/pi/rev/5170d62ca42f changeset: 34830:5170d62ca42f user: Nono Carballo <nonofce <at> gmail.com> date: Wed Oct 03 10:21:31 2018 +0200 summary: Fixes issue 39335: Wrong combination of General Ledger and accounts
* A new Event Observer was created to check, on save, if Debit and Credit accounts belongs to the selected Accounting Schema. diffstat: src-db/database/sourcedata/AD_MESSAGE.xml | 12 +++ src/org/openbravo/event/GLItemAccountsEventHandler.java | 66 +++++++++++++++++ 2 files changed, 78 insertions(+), 0 deletions(-) diffs (92 lines): diff -r cdc00e66f2c2 -r 5170d62ca42f src-db/database/sourcedata/AD_MESSAGE.xml --- a/src-db/database/sourcedata/AD_MESSAGE.xml Tue Oct 02 17:45:00 2018 +0200 +++ b/src-db/database/sourcedata/AD_MESSAGE.xml Wed Oct 03 10:21:31 2018 +0200 @@ -28438,6 +28438,18 @@ <!--FBDEF1CFE48249D69A50C8D1BB6C803B--> <ISINCLUDEINI18N><![CDATA[N]]></ISINCLUDEINI18N> <!--FBDEF1CFE48249D69A50C8D1BB6C803B--></AD_MESSAGE> +<!--FBE9143338EC442B9461A010B735BBA1--><AD_MESSAGE> +<!--FBE9143338EC442B9461A010B735BBA1--> <AD_MESSAGE_ID><![CDATA[FBE9143338EC442B9461A010B735BBA1]]></AD_MESSAGE_ID> +<!--FBE9143338EC442B9461A010B735BBA1--> <AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID> +<!--FBE9143338EC442B9461A010B735BBA1--> <AD_ORG_ID><![CDATA[0]]></AD_ORG_ID> +<!--FBE9143338EC442B9461A010B735BBA1--> <ISACTIVE><![CDATA[Y]]></ISACTIVE> +<!--FBE9143338EC442B9461A010B735BBA1--> <VALUE><![CDATA[InvalidAccountForGeneralLedger]]></VALUE> +<!--FBE9143338EC442B9461A010B735BBA1--> <MSGTEXT><![CDATA[Credit or Debit account does not belongs to the General Ledger]]></MSGTEXT> +<!--FBE9143338EC442B9461A010B735BBA1--> <MSGTYPE><![CDATA[E]]></MSGTYPE> +<!--FBE9143338EC442B9461A010B735BBA1--> <AD_MODULE_ID><![CDATA[0]]></AD_MODULE_ID> +<!--FBE9143338EC442B9461A010B735BBA1--> <ISINCLUDEINI18N><![CDATA[N]]></ISINCLUDEINI18N> +<!--FBE9143338EC442B9461A010B735BBA1--></AD_MESSAGE> + <!--FC166D49E8CE423BB39BFFE4EAB6B1E0--><AD_MESSAGE> <!--FC166D49E8CE423BB39BFFE4EAB6B1E0--> <AD_MESSAGE_ID><![CDATA[FC166D49E8CE423BB39BFFE4EAB6B1E0]]></AD_MESSAGE_ID> <!--FC166D49E8CE423BB39BFFE4EAB6B1E0--> <AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID> diff -r cdc00e66f2c2 -r 5170d62ca42f src/org/openbravo/event/GLItemAccountsEventHandler.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/org/openbravo/event/GLItemAccountsEventHandler.java Wed Oct 03 10:21:31 2018 +0200 @@ -0,0 +1,66 @@ +/* + ************************************************************************* + * The contents of this file are subject to the Openbravo Public License + * Version 1.1 (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) 2018 Openbravo SLU + * All Rights Reserved. + * Contributor(s): ______________________________________. + ************************************************************************ + */ + +package org.openbravo.event; + +import javax.enterprise.event.Observes; + +import org.apache.commons.lang.StringUtils; +import org.openbravo.base.exception.OBException; +import org.openbravo.base.model.Entity; +import org.openbravo.base.model.ModelProvider; +import org.openbravo.client.kernel.event.EntityNewEvent; +import org.openbravo.client.kernel.event.EntityPersistenceEvent; +import org.openbravo.client.kernel.event.EntityPersistenceEventObserver; +import org.openbravo.erpCommon.utility.OBMessageUtils; +import org.openbravo.model.financialmgmt.gl.GLItemAccounts; + +public class GLItemAccountsEventHandler extends EntityPersistenceEventObserver { + + private static Entity[] entities = { ModelProvider.getInstance().getEntity( + GLItemAccounts.ENTITY_NAME) }; + + @Override + protected Entity[] getObservedEntities() { + return entities; + } + + public void onSave(@Observes final EntityNewEvent event) { + if (!isValidEvent(event)) { + return; + } + checkForValidAccountCombination(event); + } + + private void checkForValidAccountCombination(final EntityPersistenceEvent event) { + GLItemAccounts gLItemAccounts = (GLItemAccounts) event.getTargetInstance(); + + final String gLItemAccountingSchemaId = gLItemAccounts.getAccountingSchema().getId(); + final String gLItemDebitAccountingSchemaId = gLItemAccounts.getGlitemDebitAcct() + .getAccountingSchema().getId(); + final String gLItemCreditAccountingSchemaId = gLItemAccounts.getGlitemCreditAcct() + .getAccountingSchema().getId(); + + if (!StringUtils.equals(gLItemAccountingSchemaId, gLItemDebitAccountingSchemaId) + || !StringUtils.equals(gLItemAccountingSchemaId, gLItemCreditAccountingSchemaId)) { + throw new OBException(OBMessageUtils.messageBD("InvalidAccountForGeneralLedger")); + } + + } +} _______________________________________________ Openbravo-commits mailing list Openbravo-commits@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/openbravo-commits