details:   https://code.openbravo.com/erp/devel/main/rev/e97a3e96d950
changeset: 16745:e97a3e96d950
user:      Augusto Mauch <augusto.mauch <at> openbravo.com>
date:      Thu Jun 14 16:08:17 2012 +0200
summary:   Fixes issue 20770: Business partner selector selects first location

Now the callouts affected by the business partner selector change explicitly 
selects the first location in the location combo, to ensure that it is selected 
too in no mandatory combos.

diffstat:

 src/org/openbravo/erpCommon/ad_callouts/SE_Invoice_BPartner.java  |  28 +++-
 src/org/openbravo/erpCommon/ad_callouts/SE_Order_BPartner.java    |  33 +++-
 src/org/openbravo/erpCommon/ad_callouts/SE_Project_BPartner.java  |  65 
++++++++--
 src/org/openbravo/erpCommon/ad_callouts/SE_Proposal_BPartner.java |  32 ++++-
 src/org/openbravo/erpCommon/ad_callouts/SL_InOut_BPartner.java    |  36 ++++-
 5 files changed, 153 insertions(+), 41 deletions(-)

diffs (284 lines):

diff -r d8238ce3ca05 -r e97a3e96d950 
src/org/openbravo/erpCommon/ad_callouts/SE_Invoice_BPartner.java
--- a/src/org/openbravo/erpCommon/ad_callouts/SE_Invoice_BPartner.java  Tue Jun 
12 15:51:15 2012 +0200
+++ b/src/org/openbravo/erpCommon/ad_callouts/SE_Invoice_BPartner.java  Thu Jun 
14 16:08:17 2012 +0200
@@ -149,20 +149,38 @@
       }
 
       resultado.append("new Array(\"inpcBpartnerLocationId\", ");
+
       if (tdv != null && tdv.length > 0) {
         resultado.append("new Array(");
-        for (int i = 0; i < tdv.length; i++) {
-          resultado.append("new Array(\"" + tdv[i].getField("id") + "\", \""
-              + FormatUtilities.replaceJS(tdv[i].getField("name")) + "\", \""
-              + (tdv[i].getField("id").equalsIgnoreCase(strLocation) ? "true" 
: "false") + "\")");
-          if (i < tdv.length - 1) {
+        if (strLocation.isEmpty()) {
+          // If no location is provided, the first one is selected
+          resultado.append("new Array(\"" + tdv[0].getField("id") + "\", \""
+              + FormatUtilities.replaceJS(tdv[0].getField("name")) + "\", \"" 
+ "true" + "\")");
+          if (tdv.length > 1) {
             resultado.append(",\n");
           }
+          for (int i = 1; i < tdv.length; i++) {
+            resultado.append("new Array(\"" + tdv[i].getField("id") + "\", \""
+                + FormatUtilities.replaceJS(tdv[i].getField("name")) + "\", 
\"" + "false" + "\")");
+            if (i < tdv.length - 1)
+              resultado.append(",\n");
+          }
+        } else {
+          // If a location is provided, it is selected
+          for (int i = 0; i < tdv.length; i++) {
+            resultado.append("new Array(\"" + tdv[i].getField("id") + "\", \""
+                + FormatUtilities.replaceJS(tdv[i].getField("name")) + "\", \""
+                + (tdv[i].getField("id").equalsIgnoreCase(strLocation) ? 
"true" : "false") + "\")");
+            if (i < tdv.length - 1) {
+              resultado.append(",\n");
+            }
+          }
         }
         resultado.append("\n)");
       } else {
         resultado.append("null");
       }
+
       resultado.append("\n),");
       resultado.append("new Array(\"inpsalesrepId\", ");
       FieldProvider[] tld = null;
diff -r d8238ce3ca05 -r e97a3e96d950 
src/org/openbravo/erpCommon/ad_callouts/SE_Order_BPartner.java
--- a/src/org/openbravo/erpCommon/ad_callouts/SE_Order_BPartner.java    Tue Jun 
12 15:51:15 2012 +0200
+++ b/src/org/openbravo/erpCommon/ad_callouts/SE_Order_BPartner.java    Thu Jun 
14 16:08:17 2012 +0200
@@ -118,17 +118,22 @@
     }
 
     String strLocation = info.vars.getStringParameter("inpcBpartnerId_LOC");
-    if (!strLocation.isEmpty()) {
-      if (tdv != null && tdv.length > 0) {
-        info.addSelect("inpcBpartnerLocationId");
+    if (tdv != null && tdv.length > 0) {
+      info.addSelect("inpcBpartnerLocationId");
+      if (strLocation.isEmpty()) {
+        // If no location is provided, the first one is selected
+        info.addSelectResult(tdv[0].getField("id"), tdv[0].getField("name"), 
true);
+        for (int i = 1; i < tdv.length; i++) {
+          info.addSelectResult(tdv[i].getField("id"), tdv[i].getField("name"), 
false);
+        }
+      } else {
+        // If a location is provided, it is selected
         for (int i = 0; i < tdv.length; i++) {
           info.addSelectResult(tdv[i].getField("id"), tdv[i].getField("name"), 
tdv[i]
               .getField("id").equalsIgnoreCase(strLocation));
         }
-        info.endSelect();
-      } else {
-        info.addResult("inpcBpartnerLocationId", null);
       }
+      info.endSelect();
     }
     // Warehouses
 
@@ -246,11 +251,19 @@
 
     if (tlv != null && tlv.length > 0) {
       info.addSelect("inpbilltoId");
-      for (int i = 0; i < tlv.length; i++) {
-        info.addSelectResult(tlv[i].getField("id"), tlv[i].getField("name"), 
tlv[i].getField("id")
-            .equalsIgnoreCase(strLocation));
+      if (strLocation.isEmpty()) {
+        // If no location is provided, the first one is selected
+        info.addSelectResult(tlv[0].getField("id"), tlv[0].getField("name"), 
true);
+        for (int i = 0; i < tlv.length; i++) {
+          info.addSelectResult(tlv[i].getField("id"), tlv[i].getField("name"), 
false);
+        }
+      } else {
+        // If a location is provided, it is selected
+        for (int i = 0; i < tlv.length; i++) {
+          info.addSelectResult(tlv[i].getField("id"), tlv[i].getField("name"), 
tlv[i]
+              .getField("id").equalsIgnoreCase(strLocation));
+        }
       }
-
       info.endSelect();
     } else {
       info.addResult("inpbilltoId", null);
diff -r d8238ce3ca05 -r e97a3e96d950 
src/org/openbravo/erpCommon/ad_callouts/SE_Project_BPartner.java
--- a/src/org/openbravo/erpCommon/ad_callouts/SE_Project_BPartner.java  Tue Jun 
12 15:51:15 2012 +0200
+++ b/src/org/openbravo/erpCommon/ad_callouts/SE_Project_BPartner.java  Thu Jun 
14 16:08:17 2012 +0200
@@ -113,16 +113,38 @@
     resultado.append("new Array(\"inpcBpartnerLocationId\", ");
     if (tdv != null && tdv.length > 0) {
       resultado.append("new Array(");
-      for (int i = 0; i < tdv.length; i++) {
-        resultado.append("new Array(\"" + tdv[i].getField("id") + "\", \""
-            + FormatUtilities.replaceJS(tdv[i].getField("name")) + "\", \""
-            + (tdv[i].getField("id").equalsIgnoreCase(strLocation) ? "true" : 
"false") + "\")");
-        if (i < tdv.length - 1)
-          resultado.append(",\n");
+      if (strLocation.isEmpty()) {
+        // If no location is provided, the first one is selected
+        if (tdv.length > 0) {
+          resultado.append("new Array(\"" + tdv[0].getField("id") + "\", \""
+              + FormatUtilities.replaceJS(tdv[0].getField("name")) + "\", \"" 
+ "true" + "\")");
+          if (tdv.length > 1) {
+            resultado.append(",\n");
+          }
+        }
+        for (int i = 1; i < tdv.length; i++) {
+          resultado.append("new Array(\"" + tdv[i].getField("id") + "\", \""
+              + FormatUtilities.replaceJS(tdv[i].getField("name")) + "\", \"" 
+ "false" + "\")");
+          if (i < tdv.length - 1) {
+            resultado.append(",\n");
+          }
+        }
+      } else {
+        // If a location is provided, it is selected
+        for (int i = 0; i < tdv.length; i++) {
+          resultado.append("new Array(\"" + tdv[i].getField("id") + "\", \""
+              + FormatUtilities.replaceJS(tdv[i].getField("name")) + "\", \""
+              + (tdv[i].getField("id").equalsIgnoreCase(strLocation) ? "true" 
: "false") + "\")");
+          if (i < tdv.length - 1) {
+            resultado.append(",\n");
+          }
+        }
       }
       resultado.append("\n)");
-    } else
+
+    } else {
       resultado.append("null");
+    }
     resultado.append("\n),");
     try {
       ComboTableData comboTableData = new ComboTableData(vars, this, 
"TABLEDIR", "AD_User_ID", "",
@@ -183,12 +205,29 @@
     resultado.append("new Array(\"inpbilltoId\", ");
     if (tlv != null && tlv.length > 0) {
       resultado.append("new Array(");
-      for (int i = 0; i < tlv.length; i++) {
-        resultado.append("new Array(\"" + tlv[i].getField("id") + "\", \""
-            + FormatUtilities.replaceJS(tlv[i].getField("name")) + "\", \""
-            + (tlv[i].getField("id").equalsIgnoreCase(strLocation) ? "true" : 
"false") + "\")");
-        if (i < tlv.length - 1)
-          resultado.append(",\n");
+
+      if (strLocation.isEmpty()) {
+        if (tlv.length > 0) {
+          resultado.append("new Array(\"" + tlv[0].getField("id") + "\", \""
+              + FormatUtilities.replaceJS(tlv[0].getField("name")) + "\", \"" 
+ "true" + "\")");
+          if (tlv.length > 1) {
+            resultado.append(",\n");
+          }
+        }
+        for (int i = 1; i < tlv.length; i++) {
+          resultado.append("new Array(\"" + tlv[i].getField("id") + "\", \""
+              + FormatUtilities.replaceJS(tlv[i].getField("name")) + "\", \"" 
+ "false" + "\")");
+          if (i < tlv.length - 1)
+            resultado.append(",\n");
+        }
+      } else {
+        for (int i = 0; i < tlv.length; i++) {
+          resultado.append("new Array(\"" + tlv[i].getField("id") + "\", \""
+              + FormatUtilities.replaceJS(tlv[i].getField("name")) + "\", \""
+              + (tlv[i].getField("id").equalsIgnoreCase(strLocation) ? "true" 
: "false") + "\")");
+          if (i < tlv.length - 1)
+            resultado.append(",\n");
+        }
       }
       resultado.append("\n)");
     } else
diff -r d8238ce3ca05 -r e97a3e96d950 
src/org/openbravo/erpCommon/ad_callouts/SE_Proposal_BPartner.java
--- a/src/org/openbravo/erpCommon/ad_callouts/SE_Proposal_BPartner.java Tue Jun 
12 15:51:15 2012 +0200
+++ b/src/org/openbravo/erpCommon/ad_callouts/SE_Proposal_BPartner.java Thu Jun 
14 16:08:17 2012 +0200
@@ -95,16 +95,36 @@
     resultado.append("new Array(\"inpcBpartnerLocationId\", ");
     if (tdv != null && tdv.length > 0) {
       resultado.append("new Array(");
-      for (int i = 0; i < tdv.length; i++) {
-        resultado.append("new Array(\"" + tdv[i].getField("id") + "\", \""
-            + FormatUtilities.replaceJS(tdv[i].getField("name")) + "\", \""
-            + (tdv[i].getField("id").equalsIgnoreCase(strLocation) ? "true" : 
"false") + "\")");
-        if (i < tdv.length - 1)
+
+      if (strLocation.isEmpty()) {
+        // If no location is provided, the first one is selected
+        resultado.append("new Array(\"" + tdv[0].getField("id") + "\", \""
+            + FormatUtilities.replaceJS(tdv[0].getField("name")) + "\", \"" + 
"true" + "\")");
+        if (tdv.length > 1) {
           resultado.append(",\n");
+        }
+        for (int i = 1; i < tdv.length; i++) {
+          resultado.append("new Array(\"" + tdv[i].getField("id") + "\", \""
+              + FormatUtilities.replaceJS(tdv[i].getField("name")) + "\", \"" 
+ "false" + "\")");
+          if (i < tdv.length - 1) {
+            resultado.append(",\n");
+          }
+        }
+      } else {
+        // If a location is provided, it is selected
+        for (int i = 0; i < tdv.length; i++) {
+          resultado.append("new Array(\"" + tdv[i].getField("id") + "\", \""
+              + FormatUtilities.replaceJS(tdv[i].getField("name")) + "\", \""
+              + (tdv[i].getField("id").equalsIgnoreCase(strLocation) ? "true" 
: "false") + "\")");
+          if (i < tdv.length - 1) {
+            resultado.append(",\n");
+          }
+        }
       }
       resultado.append("\n)");
-    } else
+    } else {
       resultado.append("null");
+    }
     resultado.append("\n),");
     try {
       ComboTableData comboTableData = new ComboTableData(vars, this, 
"TABLEDIR", "AD_User_ID", "",
diff -r d8238ce3ca05 -r e97a3e96d950 
src/org/openbravo/erpCommon/ad_callouts/SL_InOut_BPartner.java
--- a/src/org/openbravo/erpCommon/ad_callouts/SL_InOut_BPartner.java    Tue Jun 
12 15:51:15 2012 +0200
+++ b/src/org/openbravo/erpCommon/ad_callouts/SL_InOut_BPartner.java    Thu Jun 
14 16:08:17 2012 +0200
@@ -104,17 +104,39 @@
     resultado.append("new Array(\"inpcBpartnerLocationId\", ");
     if (tdv != null && tdv.length > 0) {
       resultado.append("new Array(");
-      for (int i = 0; i < tdv.length; i++) {
-        resultado.append("new Array(\"" + tdv[i].getField("id") + "\", \""
-            + 
FormatUtilities.replaceJS(Replace.replace(tdv[i].getField("name"), "\"", 
"\\\""))
-            + "\", \"" + (tdv[i].getField("id").equalsIgnoreCase(strLocation) 
? "true" : "false")
-            + "\")");
-        if (i < tdv.length - 1)
+
+      if (strLocation.isEmpty()) {
+        // If no location is provided, the first one is selected
+        resultado.append("new Array(\"" + tdv[0].getField("id") + "\", \""
+            + 
FormatUtilities.replaceJS(Replace.replace(tdv[0].getField("name"), "\"", 
"\\\""))
+            + "\", \"" + "true" + "\")");
+        if (tdv.length > 1) {
           resultado.append(",\n");
+        }
+        for (int i = 1; i < tdv.length; i++) {
+          resultado.append("new Array(\"" + tdv[i].getField("id") + "\", \""
+              + 
FormatUtilities.replaceJS(Replace.replace(tdv[i].getField("name"), "\"", 
"\\\""))
+              + "\", \"" + "false" + "\")");
+          if (i < tdv.length - 1) {
+            resultado.append(",\n");
+          }
+        }
+      } else {
+        // If a location is provided, it is selected
+        for (int i = 0; i < tdv.length; i++) {
+          resultado.append("new Array(\"" + tdv[i].getField("id") + "\", \""
+              + 
FormatUtilities.replaceJS(Replace.replace(tdv[i].getField("name"), "\"", 
"\\\""))
+              + "\", \"" + 
(tdv[i].getField("id").equalsIgnoreCase(strLocation) ? "true" : "false")
+              + "\")");
+          if (i < tdv.length - 1) {
+            resultado.append(",\n");
+          }
+        }
       }
       resultado.append("\n)");
-    } else
+    } else {
       resultado.append("null");
+    }
     resultado.append("\n),");
     resultado.append("new Array(\"inpsalesrepId\", ");
     FieldProvider[] tld = null;

------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and 
threat landscape has changed and how IT managers can respond. Discussions 
will include endpoint security, mobile security and the latest in malware 
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
Openbravo-commits mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/openbravo-commits

Reply via email to