Fixes Issue 21459:Invoice for Orders from different Legal Entity is possible
authorPandeeswari Ramakrishnan <pandeeswari.ramakrishnan@openbravo.com>
Tue, 18 Sep 2012 17:41:08 +0200
changeset 17982 9626592579b5
parent 17981 d9a38ada2c86
child 17983 7d048ad0b76f
child 19258 6d0bac2dba0b
Fixes Issue 21459:Invoice for Orders from different Legal Entity is possible
src/org/openbravo/erpCommon/ad_actionButton/CreateFrom.java
src/org/openbravo/erpCommon/utility/Utility.java
--- a/src/org/openbravo/erpCommon/ad_actionButton/CreateFrom.java	Wed Sep 19 16:17:34 2012 +0200
+++ b/src/org/openbravo/erpCommon/ad_actionButton/CreateFrom.java	Tue Sep 18 17:41:08 2012 +0200
@@ -22,6 +22,7 @@
 import java.io.PrintWriter;
 import java.math.BigDecimal;
 import java.sql.Connection;
+import java.util.ArrayList;
 import java.util.StringTokenizer;
 
 import javax.servlet.ServletConfig;
@@ -32,6 +33,7 @@
 import org.openbravo.base.filter.IsIDFilter;
 import org.openbravo.base.secureApp.HttpSecureAppServlet;
 import org.openbravo.base.secureApp.VariablesSecureApp;
+import org.openbravo.dal.core.OBContext;
 import org.openbravo.dal.service.OBDal;
 import org.openbravo.database.SessionInfo;
 import org.openbravo.erpCommon.businessUtility.Tax;
@@ -42,7 +44,9 @@
 import org.openbravo.erpCommon.utility.SequenceIdData;
 import org.openbravo.erpCommon.utility.Utility;
 import org.openbravo.financial.FinancialUtils;
+import org.openbravo.model.common.enterprise.Organization;
 import org.openbravo.model.common.invoice.Invoice;
+import org.openbravo.model.materialmgmt.transaction.ShipmentInOut;
 import org.openbravo.model.pricing.pricelist.PriceList;
 import org.openbravo.utils.Replace;
 import org.openbravo.xmlEngine.XmlDocument;
@@ -543,28 +547,27 @@
       xmlDocument.setData("reportShipmentReciept", "liststructure", new CreateFromInvoiceData[0]);
       xmlDocument.setData("reportPurchaseOrder", "liststructure", new CreateFromInvoiceData[0]);
     } else {
+      ArrayList<String> organizationList = new ArrayList<String>(OBContext.getOBContext()
+          .getOrganizationStructureProvider().getNaturalTree(invoice.getOrganization().getId()));
+      String narturalOrgTreeList = Utility.arrayListToString(organizationList, true);
       if (isSOTrx.equals("Y")) {
         xmlDocument.setData("reportShipmentReciept", "liststructure", CreateFromInvoiceData
             .selectFromShipmentSOTrxCombo(this, vars.getLanguage(),
-                Utility.getContext(this, vars, "#User_Client", strWindowId),
-                Utility.getContext(this, vars, "#User_Org", strWindowId), strBPartner,
-                strIsTaxIncluded));
+                Utility.getContext(this, vars, "#User_Client", strWindowId), narturalOrgTreeList, 
+                strBPartner, strIsTaxIncluded));
         xmlDocument.setData("reportPurchaseOrder", "liststructure", CreateFromInvoiceData
             .selectFromPOSOTrxCombo(this, vars.getLanguage(),
-                Utility.getContext(this, vars, "#User_Client", strWindowId),
-                Utility.getContext(this, vars, "#User_Org", strWindowId), strBPartner,
-                strIsTaxIncluded));
+                Utility.getContext(this, vars, "#User_Client", strWindowId), narturalOrgTreeList,
+                strBPartner, strIsTaxIncluded));
       } else {
         xmlDocument.setData("reportShipmentReciept", "liststructure", CreateFromInvoiceData
             .selectFromShipmentCombo(this, vars.getLanguage(),
-                Utility.getContext(this, vars, "#User_Client", strWindowId),
-                Utility.getContext(this, vars, "#User_Org", strWindowId), strBPartner,
-                strIsTaxIncluded));
+                Utility.getContext(this, vars, "#User_Client", strWindowId), narturalOrgTreeList, 
+                strBPartner, strIsTaxIncluded));
         xmlDocument.setData("reportPurchaseOrder", "liststructure", CreateFromInvoiceData
             .selectFromPOCombo(this, vars.getLanguage(),
-                Utility.getContext(this, vars, "#User_Client", strWindowId),
-                Utility.getContext(this, vars, "#User_Org", strWindowId), strBPartner,
-                strIsTaxIncluded));
+                Utility.getContext(this, vars, "#User_Client", strWindowId), narturalOrgTreeList,
+                strBPartner, strIsTaxIncluded));
       }
     }
     {
@@ -593,6 +596,7 @@
     XmlDocument xmlDocument;
     String strPO = vars.getStringParameter("inpPurchaseOrder");
     String strInvoice = vars.getStringParameter("inpInvoice");
+    ShipmentInOut shipment = OBDal.getInstance().get(ShipmentInOut.class, strKey);
     final String strLocator = vars.getStringParameter("inpmLocatorId");
     final String isSOTrx = Utility.getContext(this, vars, "isSOTrx", strWindowId);
     if (vars.commandIn("FIND_PO"))
@@ -685,32 +689,35 @@
       xmlDocument.setData("reportInvoice", "liststructure", new CreateFromShipmentData[0]);
       xmlDocument.setData("reportPurchaseOrder", "liststructure", new CreateFromShipmentData[0]);
     } else {
+      ArrayList<String> organizationList = new ArrayList<String>(OBContext.getOBContext()
+          .getOrganizationStructureProvider().getNaturalTree(shipment.getOrganization().getId()));
+      String narturalOrgTreeList = Utility.arrayListToString(organizationList, true);
       if (isSOTrx.equals("Y")) {
         xmlDocument.setData(
             "reportInvoice",
             "liststructure",
             CreateFromShipmentData.selectFromInvoiceTrxCombo(this, vars.getLanguage(),
                 Utility.getContext(this, vars, "#User_Client", strWindowId),
-                Utility.getContext(this, vars, "#User_Org", strWindowId), strBPartner));
+                narturalOrgTreeList, strBPartner));
         xmlDocument.setData(
             "reportPurchaseOrder",
             "liststructure",
             CreateFromShipmentData.selectFromPOSOTrxCombo(this, vars.getLanguage(),
                 Utility.getContext(this, vars, "#User_Client", strWindowId),
-                Utility.getContext(this, vars, "#User_Org", strWindowId), strBPartner));
+                narturalOrgTreeList, strBPartner));
       } else {
         xmlDocument.setData(
             "reportInvoice",
             "liststructure",
             CreateFromShipmentData.selectFromInvoiceCombo(this, vars.getLanguage(),
                 Utility.getContext(this, vars, "#User_Client", strWindowId),
-                Utility.getContext(this, vars, "#User_Org", strWindowId), strBPartner));
+                narturalOrgTreeList, strBPartner));
         xmlDocument.setData(
             "reportPurchaseOrder",
             "liststructure",
             CreateFromShipmentData.selectFromPOCombo(this, vars.getLanguage(),
                 Utility.getContext(this, vars, "#User_Client", strWindowId),
-                Utility.getContext(this, vars, "#User_Org", strWindowId), strBPartner));
+                narturalOrgTreeList, strBPartner));
       }
     }
 
--- a/src/org/openbravo/erpCommon/utility/Utility.java	Wed Sep 19 16:17:34 2012 +0200
+++ b/src/org/openbravo/erpCommon/utility/Utility.java	Tue Sep 18 17:41:08 2012 +0200
@@ -1608,8 +1608,9 @@
   public static String arrayListToString(ArrayList<String> list, boolean addQuotes) {
     String rt = "";
     for (int i = 0; i < list.size(); i++) {
-      rt += rt.equals("") ? "" : ", " + (addQuotes ? "'" : "") + list.get(i)
+      String aux = (rt.equals("") ? "" : ", ") + (addQuotes ? "'" : "") + list.get(i)
           + (addQuotes ? "'" : "");
+      rt = rt + aux;
     }
     return rt;
   }