Fixes issue 42057: It is not possible to unpost an Internal Comsumption
authorMark Molina <mark.molina@doceleguas.com>
Mon, 21 Oct 2019 10:15:53 -0300
changeset 36719 ae87c02f3f80
parent 36718 11ad42e1c9ef
child 36720 b67ca267208b
child 36744 6ad2ea738a10
Fixes issue 42057: It is not possible to unpost an Internal Comsumption

If the Internal Consumption documents have not Document Type defined which is mandatory
when unposting a document an exception will be thrown to the user.

Also was included a minor change in the Posted class to set the success message title
after we are sure any exception was thrown to avoid to have an error message with a success
title and cause confusions.
src-db/database/sourcedata/AD_MESSAGE.xml
src/org/openbravo/erpCommon/ad_actionButton/Posted.java
src/org/openbravo/financial/ResetAccounting.java
--- a/src-db/database/sourcedata/AD_MESSAGE.xml	Wed Oct 30 12:02:15 2019 +0100
+++ b/src-db/database/sourcedata/AD_MESSAGE.xml	Mon Oct 21 10:15:53 2019 -0300
@@ -23491,6 +23491,18 @@
 <!--9A6B5D3A2FC544C79ABB21C6029DC24D-->  <ISINCLUDEINI18N><![CDATA[N]]></ISINCLUDEINI18N>
 <!--9A6B5D3A2FC544C79ABB21C6029DC24D--></AD_MESSAGE>
 
+<!--9AAB7BAD16A44A6AA77E45016438545A--><AD_MESSAGE>
+<!--9AAB7BAD16A44A6AA77E45016438545A-->  <AD_MESSAGE_ID><![CDATA[9AAB7BAD16A44A6AA77E45016438545A]]></AD_MESSAGE_ID>
+<!--9AAB7BAD16A44A6AA77E45016438545A-->  <AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID>
+<!--9AAB7BAD16A44A6AA77E45016438545A-->  <AD_ORG_ID><![CDATA[0]]></AD_ORG_ID>
+<!--9AAB7BAD16A44A6AA77E45016438545A-->  <ISACTIVE><![CDATA[Y]]></ISACTIVE>
+<!--9AAB7BAD16A44A6AA77E45016438545A-->  <VALUE><![CDATA[NotDocumentTypeDefinedForTable]]></VALUE>
+<!--9AAB7BAD16A44A6AA77E45016438545A-->  <MSGTEXT><![CDATA[There is not document type defined for table]]></MSGTEXT>
+<!--9AAB7BAD16A44A6AA77E45016438545A-->  <MSGTYPE><![CDATA[E]]></MSGTYPE>
+<!--9AAB7BAD16A44A6AA77E45016438545A-->  <AD_MODULE_ID><![CDATA[0]]></AD_MODULE_ID>
+<!--9AAB7BAD16A44A6AA77E45016438545A-->  <ISINCLUDEINI18N><![CDATA[N]]></ISINCLUDEINI18N>
+<!--9AAB7BAD16A44A6AA77E45016438545A--></AD_MESSAGE>
+
 <!--9ABF66F04E4B4F998D4B5841A9591677--><AD_MESSAGE>
 <!--9ABF66F04E4B4F998D4B5841A9591677-->  <AD_MESSAGE_ID><![CDATA[9ABF66F04E4B4F998D4B5841A9591677]]></AD_MESSAGE_ID>
 <!--9ABF66F04E4B4F998D4B5841A9591677-->  <AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID>
--- a/src/org/openbravo/erpCommon/ad_actionButton/Posted.java	Wed Oct 30 12:02:15 2019 +0100
+++ b/src/org/openbravo/erpCommon/ad_actionButton/Posted.java	Mon Oct 21 10:15:53 2019 -0300
@@ -237,7 +237,6 @@
           long start = System.currentTimeMillis();
           OBError myMessage = new OBError();
           myMessage.setType("Success");
-          myMessage.setTitle(Utility.messageBD(this, "Success", vars.getLanguage()));
           PostedData[] data = PostedData.select(this, strKey, strTableId);
           try {
             HashMap<String, Integer> hm = ResetAccounting.delete(data[0].client, data[0].org,
@@ -245,6 +244,7 @@
             myMessage.setMessage(
                 Utility.parseTranslation(this, vars, vars.getLanguage(), "@UnpostedDocuments@ = "
                     + hm.get("updated") + ", @DeletedEntries@ = " + hm.get("deleted")));
+            myMessage.setTitle(Utility.messageBD(this, "Success", vars.getLanguage()));
           } catch (OBException e) {
             myMessage.setType("Error");
             myMessage.setMessage(
--- a/src/org/openbravo/financial/ResetAccounting.java	Wed Oct 30 12:02:15 2019 +0100
+++ b/src/org/openbravo/financial/ResetAccounting.java	Mon Oct 21 10:15:53 2019 -0300
@@ -99,6 +99,10 @@
       if (CollectionUtils.isNotEmpty(orgIds)) {
         for (String table : tables) {
           List<String> docbasetypes = getDocbasetypes(client, table, localRecordId);
+          if (CollectionUtils.isEmpty(docbasetypes)) {
+            String tableName = OBDal.getInstance().getProxy(Table.class, table).getIdentifier();
+            throw new OBException("@NotDocumentTypeDefinedForTable@: " + tableName);
+          }
           String myQuery = "select distinct e.recordID from FinancialMgmtAccountingFact e where e.organization.id in (:orgIds) and e.client.id = :clientId and e.table.id = :tableId";
           if (localRecordId != null && !"".equals(localRecordId)) {
             myQuery = myQuery + " and e.recordID = :recordId ";