Merge Production Development with MP4
authorrafaeldemiguel <rdm@openbravo.com>
Thu, 20 Oct 2011 13:09:18 +0200
changeset 15002 282b10cf7bdc
parent 15001 a7a8ccfb1923 (current diff)
parent 13967 4e9fa8e7edbc (diff)
child 15003 e32394357910
Merge Production Development with MP4
src-db/database/model/functions/AD_DELETE_CLIENT.xml
src-db/database/model/functions/AD_DELETE_CLIENT0.xml
src-db/database/model/triggers/FIN_FINACC_TRANSACTION_TRG.xml
src-db/database/model/triggers/FIN_PAYMENT_TRG.xml
src-db/database/sourcedata/AD_COLUMN.xml
src-db/database/sourcedata/AD_ELEMENT.xml
src-db/database/sourcedata/AD_FIELD.xml
src-db/database/sourcedata/AD_MENU.xml
src-db/database/sourcedata/AD_MESSAGE.xml
src-db/database/sourcedata/AD_MODEL_OBJECT.xml
src-db/database/sourcedata/AD_MODEL_OBJECT_MAPPING.xml
src-db/database/sourcedata/AD_TREENODE.xml
src-db/database/sourcedata/AD_VAL_RULE.xml
src/org/openbravo/erpCommon/ad_process/DeleteClient_data.xsql
src/org/openbravo/erpCommon/utility/Register.java
--- a/.hgignore	Thu Oct 13 18:24:25 2011 +0200
+++ b/.hgignore	Thu Oct 20 13:09:18 2011 +0200
@@ -38,6 +38,7 @@
 
 *.bak
 *.swp
+
 Thumbs.db
 
 sources
--- a/.hgsigs	Thu Oct 13 18:24:25 2011 +0200
+++ b/.hgsigs	Thu Oct 20 13:09:18 2011 +0200
@@ -40,3 +40,4 @@
 73cf94540eee261735546af235c022b6629c60b4 0 iEYEABECAAYFAk5km6QACgkQCX/oGf+2qkMg+QCfSxJaCXo3RB98Em77DE2wTgMdIrsAn3lvr6yVFui+ZIn81ELLNg6+hjTY
 de6ba33247c6a6fe40c8091880ca88371e62f9e5 0 iEYEABECAAYFAk5uEmIACgkQCX/oGf+2qkMqYwCeOiBUc3Bbsscvh17YA3xEium84OsAoNuBTpQKw5uNm0oE7YgIYfxislr9
 1337fbe9577f700323ed7dca2830832d4c767c24 0 iEYEABECAAYFAk58b5AACgkQCX/oGf+2qkOhuwCfcZb9pTthMp2BXE6xcKVquD27R7MAnidzwSvbx4rJK2XvWht0B35hELV4
+36fbd0e92534c9261754d500e9ef0d1a45744b59 0 iEYEABECAAYFAk6B2kgACgkQCX/oGf+2qkPXrwCghp9G3HStth7Hc4vevflmiJsaL/sAoLKnTFUyu4ZX8mlLusps5zAiWNjT
--- a/.hgtags	Thu Oct 13 18:24:25 2011 +0200
+++ b/.hgtags	Thu Oct 20 13:09:18 2011 +0200
@@ -51,3 +51,4 @@
 7ab6e81dcecb181d85885103d32f2f6ccac8b0a1 3.0MP2.1
 d08117cade69fcc9ac91619661a6b5071db6af16 3.0MP2.2
 74d95de540d0f428ab9c53303fa45ac6c192885c 3.0MP2.3
+c7a189353e46e28e320809a2e8aaaaac8c6f67e2 3.0MP3
--- a/modules/org.openbravo.advpaymentmngt/src-db/database/model/functions/APRM_GEN_PAYMENTSCHEDULE_INV.xml	Thu Oct 13 18:24:25 2011 +0200
+++ b/modules/org.openbravo.advpaymentmngt/src-db/database/model/functions/APRM_GEN_PAYMENTSCHEDULE_INV.xml	Thu Oct 20 13:09:18 2011 +0200
@@ -56,6 +56,7 @@
 v_reversalinvoice_id VARCHAR2(32);
 v_delete_paymentplan BOOLEAN := FALSE;
 v_Financial_Account_ID FIN_FINANCIAL_ACCOUNT.FIN_FINANCIAL_ACCOUNT_ID%TYPE;
+v_Financial_Account_Org VARCHAR2(32);
 v_CreatePayment CHAR(1):='N';
 v_CreateFinTransaction CHAR(1):='N';
 v_PaymentDocType_ID FIN_PAYMENT.C_DOCTYPE_ID%TYPE;
@@ -532,11 +533,16 @@
       WHERE C_BPARTNER_ID = v_BPartner_ID;
 
       -- Automatic creation of payment and financial transaction
-      SELECT CASE WHEN v_IsSOTrx='Y' THEN FIN_FINANCIAL_ACCOUNT_ID ELSE PO_FINANCIAL_ACCOUNT_ID END
-        INTO v_Financial_Account_ID
-      FROM C_BPARTNER
-      WHERE C_BPARTNER_ID = v_BPartner_ID;
-      IF(v_Financial_Account_ID IS NOT NULL) THEN
+      SELECT CASE WHEN v_IsSOTrx='Y' THEN c_bpartner.FIN_FINANCIAL_ACCOUNT_ID ELSE C_BPARTNER.PO_FINANCIAL_ACCOUNT_ID END,
+             CASE WHEN v_IsSOTrx='Y' THEN facustomer.ad_org_id ELSE favendor.ad_org_id END
+        INTO v_Financial_Account_ID, v_Financial_Account_Org
+      FROM c_bpartner LEFT JOIN FIN_FINANCIAL_ACCOUNT facustomer ON (c_bpartner.fin_financial_account_id = facustomer.fin_financial_account_id)
+                      LEFT JOIN FIN_FINANCIAL_ACCOUNT favendor ON (c_bpartner.po_financial_account_id = favendor.fin_financial_account_id)
+      WHERE c_bpartner.c_bpartner_id = v_BPartner_ID;
+      
+      -- Organization of the financial account must be in the natural organization tree of the invoice org.
+      IF (v_Financial_Account_ID IS NOT NULL AND
+          (AD_ISORGINCLUDED(v_Financial_Account_Org, v_Org_ID, v_Client_ID) <> -1 OR AD_ISORGINCLUDED(v_Org_ID, v_Financial_Account_Org, v_Client_ID) <> -1)) THEN
         SELECT MIN(em_aprm_payment_desc) INTO v_payment_desc
         FROM ad_orginfo
         WHERE ad_org_id = v_Org_ID
--- a/modules/org.openbravo.advpaymentmngt/src-db/database/sourcedata/AD_FIELD.xml	Thu Oct 13 18:24:25 2011 +0200
+++ b/modules/org.openbravo.advpaymentmngt/src-db/database/sourcedata/AD_FIELD.xml	Thu Oct 20 13:09:18 2011 +0200
@@ -5061,7 +5061,7 @@
 <!--830694907A3F8D5BE040007F01000893-->  <ISCENTRALLYMAINTAINED><![CDATA[Y]]></ISCENTRALLYMAINTAINED>
 <!--830694907A3F8D5BE040007F01000893-->  <AD_TAB_ID><![CDATA[170]]></AD_TAB_ID>
 <!--830694907A3F8D5BE040007F01000893-->  <AD_COLUMN_ID><![CDATA[828EE0AE803F5FA1E040007F010067C7]]></AD_COLUMN_ID>
-<!--830694907A3F8D5BE040007F01000893-->  <ISDISPLAYED><![CDATA[Y]]></ISDISPLAYED>
+<!--830694907A3F8D5BE040007F01000893-->  <ISDISPLAYED><![CDATA[N]]></ISDISPLAYED>
 <!--830694907A3F8D5BE040007F01000893-->  <DISPLAYLENGTH><![CDATA[12]]></DISPLAYLENGTH>
 <!--830694907A3F8D5BE040007F01000893-->  <ISREADONLY><![CDATA[N]]></ISREADONLY>
 <!--830694907A3F8D5BE040007F01000893-->  <SEQNO><![CDATA[80]]></SEQNO>
--- a/modules/org.openbravo.advpaymentmngt/src-db/database/sourcedata/AD_MESSAGE.xml	Thu Oct 13 18:24:25 2011 +0200
+++ b/modules/org.openbravo.advpaymentmngt/src-db/database/sourcedata/AD_MESSAGE.xml	Thu Oct 20 13:09:18 2011 +0200
@@ -705,6 +705,17 @@
 <!--FCDC2F10EAAD46A5A24BCEC2BF017A05-->  <AD_MODULE_ID><![CDATA[A918E3331C404B889D69AA9BFAFB23AC]]></AD_MODULE_ID>
 <!--FCDC2F10EAAD46A5A24BCEC2BF017A05--></AD_MESSAGE>
 
+<!--FEDF027AC00540119E81B4E573C4CD97--><AD_MESSAGE>
+<!--FEDF027AC00540119E81B4E573C4CD97-->  <AD_MESSAGE_ID><![CDATA[FEDF027AC00540119E81B4E573C4CD97]]></AD_MESSAGE_ID>
+<!--FEDF027AC00540119E81B4E573C4CD97-->  <AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID>
+<!--FEDF027AC00540119E81B4E573C4CD97-->  <AD_ORG_ID><![CDATA[0]]></AD_ORG_ID>
+<!--FEDF027AC00540119E81B4E573C4CD97-->  <ISACTIVE><![CDATA[Y]]></ISACTIVE>
+<!--FEDF027AC00540119E81B4E573C4CD97-->  <VALUE><![CDATA[APRM_bpmandatory_creditrefund]]></VALUE>
+<!--FEDF027AC00540119E81B4E573C4CD97-->  <MSGTEXT><![CDATA[Business Partner cannot be empty when performing refund or credit actions.]]></MSGTEXT>
+<!--FEDF027AC00540119E81B4E573C4CD97-->  <MSGTYPE><![CDATA[E]]></MSGTYPE>
+<!--FEDF027AC00540119E81B4E573C4CD97-->  <AD_MODULE_ID><![CDATA[A918E3331C404B889D69AA9BFAFB23AC]]></AD_MODULE_ID>
+<!--FEDF027AC00540119E81B4E573C4CD97--></AD_MESSAGE>
+
 <!--FF8080812E44C5F1012E44D2099A001A--><AD_MESSAGE>
 <!--FF8080812E44C5F1012E44D2099A001A-->  <AD_MESSAGE_ID><![CDATA[FF8080812E44C5F1012E44D2099A001A]]></AD_MESSAGE_ID>
 <!--FF8080812E44C5F1012E44D2099A001A-->  <AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID>
--- a/modules/org.openbravo.advpaymentmngt/src-db/database/sourcedata/AD_MODULE.xml	Thu Oct 13 18:24:25 2011 +0200
+++ b/modules/org.openbravo.advpaymentmngt/src-db/database/sourcedata/AD_MODULE.xml	Thu Oct 20 13:09:18 2011 +0200
@@ -6,7 +6,7 @@
 <!--A918E3331C404B889D69AA9BFAFB23AC-->  <AD_ORG_ID><![CDATA[0]]></AD_ORG_ID>
 <!--A918E3331C404B889D69AA9BFAFB23AC-->  <ISACTIVE><![CDATA[Y]]></ISACTIVE>
 <!--A918E3331C404B889D69AA9BFAFB23AC-->  <NAME><![CDATA[Advanced Payables and Receivables Mngmt]]></NAME>
-<!--A918E3331C404B889D69AA9BFAFB23AC-->  <VERSION><![CDATA[3.0.13698]]></VERSION>
+<!--A918E3331C404B889D69AA9BFAFB23AC-->  <VERSION><![CDATA[3.0.13966]]></VERSION>
 <!--A918E3331C404B889D69AA9BFAFB23AC-->  <DESCRIPTION><![CDATA[Managing your finances with an ERP does not have to be difficult. Enjoy a radically improved user experience that combines the power of an enterprise grade financial application with the simplicity and ease of a web 2.0 personal accounting service.]]></DESCRIPTION>
 <!--A918E3331C404B889D69AA9BFAFB23AC-->  <HELP><![CDATA[Advanced Payables and Receivables Management simplifies and automates the business processes around the management of financial accounts, from the receipt and issue of payment, to the reconciliation of those events with bank statements.
 If you would like to help shape this module you are welcome to take part in the forum discussions or register feature requests or issues in the corresponding (Forum and Bug Tracking) sections in the Advanced Payables and Receivable project in the OB Forge.]]></HELP>
@@ -25,7 +25,7 @@
 <!--A918E3331C404B889D69AA9BFAFB23AC-->  <UPDATEINFO><![CDATA[Fixed issue with document sequence numbers reset in case of applying dataset second time.
 Fixed issue 15305.]]></UPDATEINFO>
 <!--A918E3331C404B889D69AA9BFAFB23AC-->  <REFERENCEDATAINFO><![CDATA[Document types and default algorithm for bank statement auto matching]]></REFERENCEDATAINFO>
-<!--A918E3331C404B889D69AA9BFAFB23AC-->  <VERSION_LABEL><![CDATA[MP3]]></VERSION_LABEL>
+<!--A918E3331C404B889D69AA9BFAFB23AC-->  <VERSION_LABEL><![CDATA[MP4]]></VERSION_LABEL>
 <!--A918E3331C404B889D69AA9BFAFB23AC-->  <ISCOMMERCIAL><![CDATA[N]]></ISCOMMERCIAL>
 <!--A918E3331C404B889D69AA9BFAFB23AC--></AD_MODULE>
 
--- a/modules/org.openbravo.advpaymentmngt/src-db/database/sourcedata/AD_MODULE_DEPENDENCY.xml	Thu Oct 13 18:24:25 2011 +0200
+++ b/modules/org.openbravo.advpaymentmngt/src-db/database/sourcedata/AD_MODULE_DEPENDENCY.xml	Thu Oct 20 13:09:18 2011 +0200
@@ -7,7 +7,7 @@
 <!--89326AE95DAD449D85DFAB2C5B1C6683-->  <ISACTIVE><![CDATA[Y]]></ISACTIVE>
 <!--89326AE95DAD449D85DFAB2C5B1C6683-->  <AD_MODULE_ID><![CDATA[A918E3331C404B889D69AA9BFAFB23AC]]></AD_MODULE_ID>
 <!--89326AE95DAD449D85DFAB2C5B1C6683-->  <AD_DEPENDENT_MODULE_ID><![CDATA[5EB4F15C80684ACA904756BDC12ADBE5]]></AD_DEPENDENT_MODULE_ID>
-<!--89326AE95DAD449D85DFAB2C5B1C6683-->  <STARTVERSION><![CDATA[2.1.13698]]></STARTVERSION>
+<!--89326AE95DAD449D85DFAB2C5B1C6683-->  <STARTVERSION><![CDATA[2.1.13966]]></STARTVERSION>
 <!--89326AE95DAD449D85DFAB2C5B1C6683-->  <ISINCLUDED><![CDATA[N]]></ISINCLUDED>
 <!--89326AE95DAD449D85DFAB2C5B1C6683-->  <DEPENDANT_MODULE_NAME><![CDATA[User Interface Selector]]></DEPENDANT_MODULE_NAME>
 <!--89326AE95DAD449D85DFAB2C5B1C6683-->  <DEPENDENCY_ENFORCEMENT><![CDATA[MAJOR]]></DEPENDENCY_ENFORCEMENT>
@@ -21,7 +21,7 @@
 <!--B97FC854C6DD41E692161585645A900F-->  <ISACTIVE><![CDATA[Y]]></ISACTIVE>
 <!--B97FC854C6DD41E692161585645A900F-->  <AD_MODULE_ID><![CDATA[A918E3331C404B889D69AA9BFAFB23AC]]></AD_MODULE_ID>
 <!--B97FC854C6DD41E692161585645A900F-->  <AD_DEPENDENT_MODULE_ID><![CDATA[0]]></AD_DEPENDENT_MODULE_ID>
-<!--B97FC854C6DD41E692161585645A900F-->  <STARTVERSION><![CDATA[3.0.13698]]></STARTVERSION>
+<!--B97FC854C6DD41E692161585645A900F-->  <STARTVERSION><![CDATA[3.0.13966]]></STARTVERSION>
 <!--B97FC854C6DD41E692161585645A900F-->  <ISINCLUDED><![CDATA[N]]></ISINCLUDED>
 <!--B97FC854C6DD41E692161585645A900F-->  <DEPENDANT_MODULE_NAME><![CDATA[core]]></DEPENDANT_MODULE_NAME>
 <!--B97FC854C6DD41E692161585645A900F-->  <DEPENDENCY_ENFORCEMENT><![CDATA[MAJOR]]></DEPENDENCY_ENFORCEMENT>
--- a/modules/org.openbravo.advpaymentmngt/src-db/database/sourcedata/AD_TEXTINTERFACES.xml	Thu Oct 13 18:24:25 2011 +0200
+++ b/modules/org.openbravo.advpaymentmngt/src-db/database/sourcedata/AD_TEXTINTERFACES.xml	Thu Oct 20 13:09:18 2011 +0200
@@ -2409,6 +2409,28 @@
 <!--AC02A8EF9F4F4FF6A8011C70A0F8553C-->  <AD_MODULE_ID><![CDATA[A918E3331C404B889D69AA9BFAFB23AC]]></AD_MODULE_ID>
 <!--AC02A8EF9F4F4FF6A8011C70A0F8553C--></AD_TEXTINTERFACES>
 
+<!--AD4B47A653568779E040007F010055A7--><AD_TEXTINTERFACES>
+<!--AD4B47A653568779E040007F010055A7-->  <AD_TEXTINTERFACES_ID><![CDATA[AD4B47A653568779E040007F010055A7]]></AD_TEXTINTERFACES_ID>
+<!--AD4B47A653568779E040007F010055A7-->  <AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID>
+<!--AD4B47A653568779E040007F010055A7-->  <AD_ORG_ID><![CDATA[0]]></AD_ORG_ID>
+<!--AD4B47A653568779E040007F010055A7-->  <ISACTIVE><![CDATA[Y]]></ISACTIVE>
+<!--AD4B47A653568779E040007F010055A7-->  <TEXT><![CDATA[Accounting Dimensions]]></TEXT>
+<!--AD4B47A653568779E040007F010055A7-->  <FILENAME><![CDATA[/org/openbravo/advpaymentmngt/ad_actionbutton/AddPaymentFromTransaction.html]]></FILENAME>
+<!--AD4B47A653568779E040007F010055A7-->  <ISUSED><![CDATA[Y]]></ISUSED>
+<!--AD4B47A653568779E040007F010055A7-->  <AD_MODULE_ID><![CDATA[A918E3331C404B889D69AA9BFAFB23AC]]></AD_MODULE_ID>
+<!--AD4B47A653568779E040007F010055A7--></AD_TEXTINTERFACES>
+
+<!--AD4B47A653588779E040007F010055A7--><AD_TEXTINTERFACES>
+<!--AD4B47A653588779E040007F010055A7-->  <AD_TEXTINTERFACES_ID><![CDATA[AD4B47A653588779E040007F010055A7]]></AD_TEXTINTERFACES_ID>
+<!--AD4B47A653588779E040007F010055A7-->  <AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID>
+<!--AD4B47A653588779E040007F010055A7-->  <AD_ORG_ID><![CDATA[0]]></AD_ORG_ID>
+<!--AD4B47A653588779E040007F010055A7-->  <ISACTIVE><![CDATA[Y]]></ISACTIVE>
+<!--AD4B47A653588779E040007F010055A7-->  <TEXT><![CDATA[Accounting Dimensions]]></TEXT>
+<!--AD4B47A653588779E040007F010055A7-->  <FILENAME><![CDATA[/org/openbravo/advpaymentmngt/ad_actionbutton/AddOrderOrInvoice.html]]></FILENAME>
+<!--AD4B47A653588779E040007F010055A7-->  <ISUSED><![CDATA[Y]]></ISUSED>
+<!--AD4B47A653588779E040007F010055A7-->  <AD_MODULE_ID><![CDATA[A918E3331C404B889D69AA9BFAFB23AC]]></AD_MODULE_ID>
+<!--AD4B47A653588779E040007F010055A7--></AD_TEXTINTERFACES>
+
 <!--AF139B1C12C0477AB902B9DF23D53779--><AD_TEXTINTERFACES>
 <!--AF139B1C12C0477AB902B9DF23D53779-->  <AD_TEXTINTERFACES_ID><![CDATA[AF139B1C12C0477AB902B9DF23D53779]]></AD_TEXTINTERFACES_ID>
 <!--AF139B1C12C0477AB902B9DF23D53779-->  <AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID>
--- a/modules/org.openbravo.advpaymentmngt/src/org/openbravo/advpaymentmngt/ad_actionbutton/AddOrderOrInvoice.html	Thu Oct 13 18:24:25 2011 +0200
+++ b/modules/org.openbravo.advpaymentmngt/src/org/openbravo/advpaymentmngt/ad_actionbutton/AddOrderOrInvoice.html	Thu Oct 20 13:09:18 2011 +0200
@@ -109,14 +109,14 @@
       OB.APRM.AOOI_ddt !== document.getElementById('paramDueDateTo').value ||
       OB.APRM.AOOI_cu !== document.getElementById('paramCurrencyId').value)
   {
-	OB.APRM.AOOI_bp = document.getElementById('C_BPartner_ID').value;
+    OB.APRM.AOOI_bp = document.getElementById('C_BPartner_ID').value;
     OB.APRM.AOOI_dt = document.getElementById('paramDocumentType').value;
     OB.APRM.AOOI_pm = document.getElementById('paramAlternativePaymentMethod').checked;
     OB.APRM.AOOI_ddf = document.getElementById('paramDueDateFrom').value;
     OB.APRM.AOOI_ddt = document.getElementById('paramDueDateTo').value;
     OB.APRM.AOOI_cu = document.getElementById('paramCurrencyId').value;
 
-	try {
+    try {
       var url = '../org.openbravo.advpaymentmngt.ad_actionbutton/AddOrderOrInvoice.html';
       var paramXMLReq = null;
       return submitXmlHttpRequest(callBackGrid, document.frmMain, 'GRIDLIST', url, false, null, paramXMLReq);
@@ -131,42 +131,71 @@
   var table = document.getElementById('sectionGLItemGrid'),
       glitemCount = OB.APRM.APFT_GLItems.length,
       glitemAmount = 0,
-      rowCount, row, cellGLItemDesc, cellGLITemReceivedInAmt, cellGLITemPaidOutAmt, cellRemoveButton, i, textNode;
+      glitemDescLength = 20, glitemDescCont = "...",
+      cellCount, row, cellGLItemDesc, cellGLITemReceivedInAmt, cellGLITemPaidOutAmt, cellRemoveButton, i, textNode, glAcctDimsDesc, acctDim, cellGLItemDim;
 
   table.innerHTML = '';
   if (glitemCount === 0) {
     OB.APRM.HasGLItems = false;
+    frm.inpGLSumAmount.value = '0';
+    updateTotal();
     return;
   }
   OB.APRM.HasGLItems = true;
   for (i = 0; i < glitemCount; i++) {
-    rowCount = table.rows.length;
-    row = table.insertRow(rowCount);
+    row = table.insertRow(table.rows.length);
     row.className = 'DataGrid_Body_Row DataGrid_Body_Row_'+i%2;
+    cellCount = 0;
     
-    cellGLItemDesc = row.insertCell(0);
+    cellGLItemDesc = row.insertCell(cellCount);
     textNode = document.createTextNode(OB.APRM.APFT_GLItems[i].glitemDesc);
     cellGLItemDesc.appendChild(textNode);
     cellGLItemDesc.className = 'DataGrid_Body_Cell';
+    cellCount++;
     
-    cellGLITemReceivedInAmt = row.insertCell(1);
+    // Accounting Dimensions
+    glAcctDimsDesc = ["cBpartnerDimDesc", "cActivityDimDesc", "mProductDimDesc", "cCampaignDimDesc", "cProjectDimDesc", "cSalesregionDimDesc"];
+    for (acctDim = 0; acctDim < glAcctDimsDesc.length; acctDim++) {
+      if (OB.APRM.APFT_GLItems[i][glAcctDimsDesc[acctDim]]) {
+        cellGLItemDim = row.insertCell(cellCount);
+        if (OB.APRM.APFT_GLItems[i][glAcctDimsDesc[acctDim]].length > glitemDescLength + glitemDescCont.length) {
+          textNode = document.createTextNode(OB.APRM.APFT_GLItems[i][glAcctDimsDesc[acctDim]].slice(0, glitemDescLength) + glitemDescCont);
+        } else {
+          textNode = document.createTextNode(OB.APRM.APFT_GLItems[i][glAcctDimsDesc[acctDim]]);
+        }
+        cellGLItemDim.appendChild(textNode);
+        cellGLItemDim.className = 'DataGrid_Body_Cell';
+        cellCount++;
+      } else if (OB.APRM.APFT_GLItems[i][glAcctDimsDesc[acctDim].replace("Desc", "Displayed")]) {
+        // The Acct. Dimen is displayed and the user has left it empty
+        cellGLItemDim = row.insertCell(cellCount);
+        textNode = document.createTextNode("");
+        cellGLItemDim.appendChild(textNode);
+        cellGLItemDim.className = 'DataGrid_Body_Cell';
+        cellCount++;
+      }
+    }
+    
+    cellGLITemReceivedInAmt = row.insertCell(cellCount);
     textNode = document.createTextNode(applyFormatJSToOBMasked(OB.APRM.APFT_GLItems[i].glitemReceivedInAmt));
     cellGLITemReceivedInAmt.appendChild(textNode);
     cellGLITemReceivedInAmt.className = 'DataGrid_Body_Cell_Amount';
+    cellCount++;
     
-    cellGLITemPaidOutAmt = row.insertCell(2);
+    cellGLITemPaidOutAmt = row.insertCell(cellCount);
     textNode = document.createTextNode(applyFormatJSToOBMasked(OB.APRM.APFT_GLItems[i].glitemPaidOutAmt));
     cellGLITemPaidOutAmt.appendChild(textNode);
     cellGLITemPaidOutAmt.className = 'DataGrid_Body_Cell_Amount';
+    cellCount++;
     
     if (isTrue('isReceipt')) {
       glitemAmount = subtract(applyFormatJSToOBMasked(OB.APRM.APFT_GLItems[i].glitemReceivedInAmt), applyFormatJSToOBMasked(OB.APRM.APFT_GLItems[i].glitemPaidOutAmt));
     } else {
       glitemAmount = subtract(applyFormatJSToOBMasked(OB.APRM.APFT_GLItems[i].glitemPaidOutAmt), applyFormatJSToOBMasked(OB.APRM.APFT_GLItems[i].glitemReceivedInAmt));
     }
-    cellRemoveButton = row.insertCell(3);
+    cellRemoveButton = row.insertCell(cellCount);
     cellRemoveButton.innerHTML = '<div><button type="button" id="buttonRemoveGLItem"'
-        + ' class="ButtonLink_focus" onclick="removeGLItem(' + i + ', ' + glitemAmount + ');return false;"'
+        + ' class="ButtonLink_focus" onclick="removeGLItem(' + i + ', ' + applyFormatOBMaskedToJS(glitemAmount) + ');return false;"'
         + ' onfocus="buttonEvent(\'onfocus\', this); window.status=\'OK\'; return true;"'
         + ' onblur="buttonEvent(\'onblur\', this);"'
         + '  onkeyup="buttonEvent(\'onkeyup\', this);"'
@@ -224,6 +253,24 @@
     id: OB.APRM.APFT_GLItemsId,
     glitemId: frm.inpcGlitemId.value,
     glitemDesc: sc_C_Glitem_ID.selectorField.getDisplayValue(),
+    cBpartnerDim: frm.inpCBPartnerId_dim && frm.inpCBPartnerId_dim.value,
+    cBpartnerDimDesc: sc_C_BPartner_ID_dim.selectorField.getDisplayValue(),
+    cBpartnerDimDisplayed: frm.strElement_BP.value,
+    cActivityDim: frm.inpCActivityId && frm.inpCActivityId.value,
+    cActivityDimDesc: sc_C_Activity_ID.selectorField.getDisplayValue(),
+    cActivityDimDisplayed: frm.strElement_AY.value,
+    mProductDim: frm.inpMProductId && frm.inpMProductId.value,
+    mProductDimDesc:  sc_M_Product_ID.selectorField.getDisplayValue(),
+    mProductDimDisplayed: frm.strElement_PR.value,
+    cCampaignDim: frm.inpCampaignId && frm.inpCampaignId.value,
+    cCampaignDimDesc: sc_C_Campaign_ID.selectorField.getDisplayValue(),
+    cCampaignDimDisplayed: frm.strElement_MC.value,
+    cProjectDim: frm.inpCProjectId && frm.inpCProjectId.value,
+    cProjectDimDesc: sc_C_Project_ID.selectorField.getDisplayValue(),
+    cProjectDimDisplayed: frm.strElement_PJ.value,
+    cSalesregionDim: frm.inpCSalesRegionId && frm.inpCSalesRegionId.value,
+    cSalesregionDimDesc: sc_C_SalesRegion_ID.selectorField.getDisplayValue(),
+    cSalesregionDimDisplayed: frm.strElement_SR.value,
     glitemReceivedInAmt: OB.Utilities.Number.OBMaskedToJS(frm.inpGLItemReceivedInAmount.value,
                                                           getGlobalDecSeparator(),
                                                           getGlobalGroupSeparator()),
@@ -234,6 +281,7 @@
   loadGLItemList();
 }
 function removeGLItem(key, removedAmount) {
+  var removedAmount = applyFormatJSToOBMasked(removedAmount);
   if (!isTrue('isReceipt')){
     if ( compare(document.frmMain.inpActualPayment.value, '>', removedAmount) ) {
       document.frmMain.inpActualPayment.value = subtract(document.frmMain.inpActualPayment.value, removedAmount);
@@ -253,8 +301,8 @@
   updateConvertedAmounts();
 }
 function displayMulticurrencyControls() {
-  var invCurrency = document.getElementById('paramCurrencyId').value
-  var accountCurrency = document.getElementById('paramFinancialAccountCurrencyId').value
+  var invCurrency = document.getElementById('paramCurrencyId').value;
+  var accountCurrency = document.getElementById('paramFinancialAccountCurrencyId').value;
 
   var display = ( invCurrency && accountCurrency && invCurrency != accountCurrency );
 
@@ -360,6 +408,7 @@
   } else {
     displayLogicElement('bpartnerfilterRow', !hasBPartner);
   }
+  autoDisplayLogicDimensions(toGLItem);
 
   resizeAreaCreateFrom();
   if (toGLItem) {
@@ -367,6 +416,59 @@
   }
   return true;
 }
+function autoDisplayLogicDimensions(isDisplayed) {
+  var displayLogicDimension = function (dimension, isDisplayed) {
+    displayLogicElement(dimension + '_dim_label', isDisplayed);
+    displayLogicElement(dimension + '_dim_inp', isDisplayed);
+    displayLogicElement(dimension + '_th', isDisplayed)
+  }
+  var displayTitle = false;
+  if (document.frmMain.strElement_BP.value === 'Y' && isDisplayed) {
+    displayLogicDimension('c_bpartner_id', true);
+    displayTitle = true;
+  } else {
+    displayLogicDimension('c_bpartner_id', false);
+  }  
+  if (document.frmMain.strElement_AY.value === 'Y' && isDisplayed) {
+    displayLogicDimension('c_activity_id', true);
+    displayTitle = true;
+  } else {
+    displayLogicDimension('c_activity_id', false);
+  }
+  
+  if (document.frmMain.strElement_PR.value === 'Y' && isDisplayed) {
+    displayLogicDimension('m_product_id', true);
+    displayTitle = true;
+  } else {
+    displayLogicDimension('m_product_id', false);
+  }
+  if (document.frmMain.strElement_MC.value === 'Y' && isDisplayed) {
+    displayLogicDimension('c_campaign_id', true);
+    displayTitle = true;
+  } else {
+    displayLogicDimension('c_campaign_id', false);
+  }
+  
+  if (document.frmMain.strElement_PJ.value === 'Y' && isDisplayed) {
+    displayLogicDimension('c_project_id', true);
+    displayTitle = true;
+  } else {
+    displayLogicDimension('c_project_id', false);
+  }
+  if (document.frmMain.strElement_SR.value === 'Y' && isDisplayed) {
+    displayLogicDimension('c_salesregion_id', true);
+    displayTitle = true;
+  } else {
+    displayLogicDimension('c_salesregion_id', false);
+  }
+  
+  if (displayTitle) {
+    displayLogicElement('acctDimensionsTitle', true);
+  } else {
+    displayLogicElement('acctDimensionsTitle', false);
+  }
+}
+
 function documentTypeOnChange(value){
   if ('G' === value) {
     //if we are not already on GL Item mode.
@@ -504,6 +606,12 @@
   <input type="hidden" name="inpGLItems" value=""/>
   <input type="hidden" name="inpDeleteGLItem" value=""/>
   <input type="hidden" id="paramGeneratedCredit" name="inpGeneratedCredit" value="0"/>
+  <input type="hidden" name="strElement_BP" id="paramStrElement_BP" value=""/>
+  <input type="hidden" name="strElement_PR" id="paramStrElement_PR" value=""/>
+  <input type="hidden" name="strElement_PJ" id="paramStrElement_PJ" value=""/>
+  <input type="hidden" name="strElement_AY" id="paramStrElement_AY" value=""/>
+  <input type="hidden" name="strElement_SR" id="paramStrElement_SR" value=""/>
+  <input type="hidden" name="strElement_MC" id="paramStrElement_MC" value=""/>
   <div class="Popup_ContentPane_CircleLogo">
     <div class="Popup_WindowLogo">
       <img class="Popup_WindowLogo_Icon Popup_WindowLogo_Icon_process" src="../../../../../web/images/blank.gif" border=0/></img>
@@ -1034,6 +1142,110 @@
               </td>
               <td class="TitleCell"></td>
             </tr>
+            
+            <tr id="acctDimensionsTitle">
+              <td colspan="6">
+                <table class="FieldGroup" cellspacing="0" cellpadding="0" border="0">
+                <tbody>
+                  <tr class="FieldGroup_TopMargin"/>
+                  <tr>
+                    <td class="FieldGroupTitle_Left"><img class="FieldGroupTitle_Left_bg" border="0" src="../../../../../web/images/blank.gif"/></td>
+                    <td class="FieldGroupTitle">Accounting Dimensions</td>
+                    <td class="FieldGroupTitle_Right"><img class="FieldGroupTitle_Right_bg" border="0" src="../../../../../web/images/blank.gif"/></td>
+                    <td class="FieldGroupContent"/>
+                  </tr>
+                  <tr class="FieldGroup_BottomMargin"/>
+                </tbody>
+                </table>
+              </td>
+            </tr>
+            <tr id="GLItemSection1_Dim">
+              <!-- Business Partner Dimension -->
+              <td id="c_bpartner_id_dim_label" class="TitleCell"><span class="LabelText">Business Partner</span></td>
+              <td id="c_bpartner_id_dim_inp" class="TextBox_ContentCell" colspan="2">
+                <table style="border:0px;border-collapse:collapse;">
+                  <tr>
+                    <td style="padding-top: 0px;">
+                      <script>var sc_C_BPartner_ID_dim = null;</script>
+                      <input type="hidden" name="inpCBPartnerId_dim" id="C_BPartner_ID_dim" value="" onreset="sc_C_BPartner_ID_dim.resetSelector();" onchange="openbravo.Utilities.updateSmartClientComponentValue(this, sc_C_BPartner_ID_dim.selectorField);"></input>
+                      <script id="selectorLink" src="../org.openbravo.client.kernel/OBUISEL_Selector/A98899B1C75A4F4EBD3414F1B654EFAB?columnName=C_BPartner_ID_dim&disabled=false&CssSize=TwoCells&DisplayLength=45.0&required=false"></script>
+                    </td>
+                  </tr>
+                </table>
+              </td>
+              <!-- Activity Dimension -->
+              <td id="c_activity_id_dim_label" class="TitleCell"><span class="LabelText">Activity</span></td>
+              <td id="c_activity_id_dim_inp" class="TextBox_ContentCell" colspan="1">
+                <table style="border:0px;border-collapse:collapse;">
+                  <tr>
+                    <td style="padding-top: 0px;">
+                      <script>var sc_C_Activity_ID = null;</script>
+                      <input type="hidden" name="inpCActivityId" id="C_Activity_ID" value="" onreset="sc_C_Activity_ID.resetSelector();" onchange="openbravo.Utilities.updateSmartClientComponentValue(this, sc_C_Activity_ID.selectorField);"></input>
+                      <script id="selectorLink" src="../org.openbravo.client.kernel/OBUISEL_Selector/FF808181312D569C01312D8C1EC40036?columnName=C_Activity_ID&disabled=false&CssSize=TwoCells&DisplayLength=45.0&required=false"></script>
+                    </td>
+                  </tr>
+                </table>
+              </td>             
+              <td class="TitleCell"></td>
+            </tr>
+            <tr id="GLItemSection2_Dim">
+              <!-- Product Dimension -->
+              <td id="m_product_id_dim_label" class="TitleCell"><span class="LabelText">Product</span></td>
+              <td id="m_product_id_dim_inp" class="TextBox_ContentCell" colspan="2">
+                <table style="border:0px;border-collapse:collapse;">
+                  <tr>
+                    <td style="padding-top: 0px;">
+                      <script>var sc_M_Product_ID = null;</script>
+                      <input type="hidden" name="inpMProductId" id="M_Product_ID" value="" onreset="sc_M_Product_ID.resetSelector();" onchange="openbravo.Utilities.updateSmartClientComponentValue(this, sc_M_Product_ID.selectorField);"></input>
+                      <script id="selectorLink" src="../org.openbravo.client.kernel/OBUISEL_Selector/FF808181312DA8D801312DDE869B000C?columnName=M_Product_ID&disabled=false&CssSize=TwoCells&DisplayLength=45.0&required=false"></script>
+                    </td>
+                  </tr>
+                </table>
+              </td>
+              <!-- Campaign Dimension -->
+              <td id="c_campaign_id_dim_label" class="TitleCell"><span class="LabelText">Campaign</span></td>
+              <td id="c_campaign_id_dim_inp" class="TextBox_ContentCell" colspan="1">
+                <table style="border:0px;border-collapse:collapse;">
+                  <tr>
+                    <td style="padding-top: 0px;">
+                      <script>var sc_C_Campaign_ID = null;</script>
+                      <input type="hidden" name="inpCampaignId" id="C_Campaign_ID" value="" onreset="sc_C_Campaign_ID.resetSelector();" onchange="openbravo.Utilities.updateSmartClientComponentValue(this, sc_C_Campaign_ID.selectorField);"></input>
+                      <script id="selectorLink" src="../org.openbravo.client.kernel/OBUISEL_Selector/FF808181312D569C01312D8DCCD50045?columnName=C_Campaign_ID&disabled=false&CssSize=TwoCells&DisplayLength=45.0&required=false"></script>
+                    </td>
+                  </tr>
+                </table>
+              </td>
+              <td class="TitleCell"></td>
+            </tr>
+            <tr id="GLItemSection3_Dim">
+              <!-- Project Dimension -->
+              <td id="c_project_id_dim_label" class="TitleCell"><span class="LabelText">Project</span></td>
+              <td id="c_project_id_dim_inp" class="TextBox_ContentCell" colspan="2">
+                <table style="border:0px;border-collapse:collapse;">
+                  <tr>
+                    <td style="padding-top: 0px;">
+                      <script>var sc_C_Project_ID = null;</script>
+                      <input type="hidden" name="inpCProjectId" id="C_Project_ID" value="" onreset="sc_C_Project_ID.resetSelector();" onchange="openbravo.Utilities.updateSmartClientComponentValue(this, sc_C_Project_ID.selectorField);"></input>
+                      <script id="selectorLink" src="../org.openbravo.client.kernel/OBUISEL_Selector/FF808181312D569C01312D90408D005D?columnName=C_Project_ID&disabled=false&CssSize=TwoCells&DisplayLength=45.0&required=false"></script>
+                    </td>
+                  </tr>
+                </table>
+              </td>
+              <!-- Sales Region Dimension -->
+              <td id="c_salesregion_id_dim_label" class="TitleCell"><span class="LabelText">Sales Region</span></td>
+              <td id="c_salesregion_id_dim_inp" class="TextBox_ContentCell" colspan="1">
+                <table style="border:0px;border-collapse:collapse;">
+                  <tr>
+                    <td style="padding-top: 0px;">
+                      <script>var sc_C_SalesRegion_ID = null;</script>
+                      <input type="hidden" name="inpCSalesRegionId" id="C_SalesRegion_ID" value="" onreset="sc_C_SalesRegion_ID.resetSelector();" onchange="openbravo.Utilities.updateSmartClientComponentValue(this, sc_C_SalesRegion_ID.selectorField);"></input>
+                      <script id="selectorLink" src="../org.openbravo.client.kernel/OBUISEL_Selector/FF808181312D569C01312D8EE5430054?columnName=C_SalesRegion_ID&disabled=false&CssSize=TwoCells&DisplayLength=45.0&required=false"></script>
+                    </td>
+                  </tr>
+                </table>
+              </td>
+              <td class="TitleCell"></td>
+            </tr>           
             <tr id="glitemAddRow">
               <td class="TitleCell"></td>
               <td class="Button_RightAlign_ContentCell">
@@ -1105,7 +1317,13 @@
                   <table cellspacing="0" cellpadding="0" width="100%" class="DataGrid_Header_Table DataGrid_Body_Table" style="table-layout: auto;" id="gridGLItem">
                     <thead>
                       <tr class="DataGrid_Body_Row">
-                        <th class="DataGrid_Header_Cell" width="400">GL Item</th>
+                        <th class="DataGrid_Header_Cell" width="300">GL Item</th>
+                        <th class="DataGrid_Header_Cell DataGrid_Header_Cell_Inverse" width="100" id="c_bpartner_id_th">Business Partner</th>
+                        <th class="DataGrid_Header_Cell DataGrid_Header_Cell_Inverse" width="100" id="c_activity_id_th">Activity</th>
+                        <th class="DataGrid_Header_Cell DataGrid_Header_Cell_Inverse" width="100" id="m_product_id_th">Product</th>
+                        <th class="DataGrid_Header_Cell DataGrid_Header_Cell_Inverse" width="100" id="c_campaign_id_th">Campaign</th>
+                        <th class="DataGrid_Header_Cell DataGrid_Header_Cell_Inverse" width="100" id="c_project_id_th">Project</th>
+                        <th class="DataGrid_Header_Cell DataGrid_Header_Cell_Inverse" width="100" id="c_salesregion_id_th">Sales Region</th>
                         <th class="DataGrid_Header_Cell DataGrid_Header_Cell_Inverse" width="100">Received In</th>
                         <th class="DataGrid_Header_Cell DataGrid_Header_Cell_Inverse" width="100">Paid Out</th>
                         <th class="DataGrid_Header_LineNoCell" width="20"></th>
--- a/modules/org.openbravo.advpaymentmngt/src/org/openbravo/advpaymentmngt/ad_actionbutton/AddOrderOrInvoice.java	Thu Oct 13 18:24:25 2011 +0200
+++ b/modules/org.openbravo.advpaymentmngt/src/org/openbravo/advpaymentmngt/ad_actionbutton/AddOrderOrInvoice.java	Thu Oct 20 13:09:18 2011 +0200
@@ -51,9 +51,14 @@
 import org.openbravo.model.common.businesspartner.BusinessPartner;
 import org.openbravo.model.common.currency.Currency;
 import org.openbravo.model.common.enterprise.Organization;
+import org.openbravo.model.common.plm.Product;
 import org.openbravo.model.financialmgmt.gl.GLItem;
 import org.openbravo.model.financialmgmt.payment.FIN_Payment;
 import org.openbravo.model.financialmgmt.payment.FIN_PaymentScheduleDetail;
+import org.openbravo.model.marketing.Campaign;
+import org.openbravo.model.materialmgmt.cost.ABCActivity;
+import org.openbravo.model.project.Project;
+import org.openbravo.model.sales.SalesRegion;
 import org.openbravo.xmlEngine.XmlDocument;
 
 public class AddOrderOrInvoice extends HttpSecureAppServlet {
@@ -126,7 +131,7 @@
       String strDocumentType = vars.getStringParameter("inpDocumentType", "");
       String paymentCurrencyId = vars.getRequiredStringParameter("inpCurrencyId");
       BigDecimal exchangeRate = new BigDecimal(vars.getRequiredNumericParameter("inpExchangeRate",
-          "1.0"));
+          "1"));
       BigDecimal convertedAmount = new BigDecimal(vars.getRequiredNumericParameter(
           "inpActualConverted", strPaymentAmount));
       OBError message = null;
@@ -157,8 +162,37 @@
             } else {
               glItemAmt = glItemOutAmt.subtract(glItemInAmt);
             }
-            FIN_AddPayment.saveGLItem(payment, glItemAmt,
-                dao.getObject(GLItem.class, glItem.getString("glitemId")));
+            final String strGLItemId = glItem.getString("glitemId");
+            checkID(strGLItemId);
+
+            // Accounting Dimensions
+            final String strElement_BP = glItem.getString("cBpartnerDim");
+            checkID(strElement_BP);
+            final BusinessPartner businessPartner = dao.getObject(BusinessPartner.class,
+                strElement_BP);
+
+            final String strElement_PR = glItem.getString("mProductDim");
+            checkID(strElement_PR);
+            final Product product = dao.getObject(Product.class, strElement_PR);
+
+            final String strElement_PJ = glItem.getString("cProjectDim");
+            checkID(strElement_PJ);
+            final Project project = dao.getObject(Project.class, strElement_PJ);
+
+            final String strElement_AY = glItem.getString("cActivityDim");
+            checkID(strElement_AY);
+            final ABCActivity activity = dao.getObject(ABCActivity.class, strElement_AY);
+
+            final String strElement_SR = glItem.getString("cSalesregionDim");
+            checkID(strElement_SR);
+            final SalesRegion salesRegion = dao.getObject(SalesRegion.class, strElement_SR);
+
+            final String strElement_MC = glItem.getString("cCampaignDim");
+            checkID(strElement_MC);
+            final Campaign campaign = dao.getObject(Campaign.class, strElement_MC);
+
+            FIN_AddPayment.saveGLItem(payment, glItemAmt, dao.getObject(GLItem.class, strGLItemId),
+                businessPartner, product, project, campaign, activity, salesRegion);
           }
         }
         FIN_AddPayment.setFinancialTransactionAmountAndRate(payment, exchangeRate, convertedAmount);
@@ -223,6 +257,13 @@
 
   }
 
+  private void checkID(final String id) throws ServletException {
+    if (!IsIDFilter.instance.accept(id)) {
+      log4j.error("Input: " + id + " not accepted by filter: IsIDFilter");
+      throw new ServletException("Input: " + id + " is not an accepted input");
+    }
+  }
+
   private void printPage(HttpServletResponse response, VariablesSecureApp vars,
       String strPaymentId, String strWindowId, String strTabId) throws IOException,
       ServletException {
@@ -319,6 +360,20 @@
       throw new ServletException(ex);
     }
 
+    // Accounting Dimensions
+    final String strElement_BP = Utility.getContext(this, vars, "$Element_BP", strWindowId);
+    final String strElement_PR = Utility.getContext(this, vars, "$Element_PR", strWindowId);
+    final String strElement_PJ = Utility.getContext(this, vars, "$Element_PJ", strWindowId);
+    final String strElement_AY = Utility.getContext(this, vars, "$Element_AY", strWindowId);
+    final String strElement_SR = Utility.getContext(this, vars, "$Element_SR", strWindowId);
+    final String strElement_MC = Utility.getContext(this, vars, "$Element_MC", strWindowId);
+    xmlDocument.setParameter("strElement_BP", strElement_BP);
+    xmlDocument.setParameter("strElement_PR", strElement_PR);
+    xmlDocument.setParameter("strElement_PJ", strElement_PJ);
+    xmlDocument.setParameter("strElement_AY", strElement_AY);
+    xmlDocument.setParameter("strElement_SR", strElement_SR);
+    xmlDocument.setParameter("strElement_MC", strElement_MC);
+
     response.setContentType("text/html; charset=UTF-8");
     PrintWriter out = response.getWriter();
     out.println(xmlDocument.print());
--- a/modules/org.openbravo.advpaymentmngt/src/org/openbravo/advpaymentmngt/ad_actionbutton/AddOrderOrInvoice.xml	Thu Oct 13 18:24:25 2011 +0200
+++ b/modules/org.openbravo.advpaymentmngt/src/org/openbravo/advpaymentmngt/ad_actionbutton/AddOrderOrInvoice.xml	Thu Oct 20 13:09:18 2011 +0200
@@ -59,6 +59,14 @@
     <SUBREPORT id="reportActionDocument" name="reportActionDocument" report="org/openbravo/erpCommon/reference/List">
       <ARGUMENT name="parameterListSelected" withId="paramActionDocument"/>
     </SUBREPORT>
+    
+    <!-- Accounting Dimensions -->
+    <PARAMETER id="paramStrElement_BP" name="strElement_BP" attribute="value"/>
+    <PARAMETER id="paramStrElement_PR" name="strElement_PR" attribute="value"/>
+    <PARAMETER id="paramStrElement_PJ" name="strElement_PJ" attribute="value"/>
+    <PARAMETER id="paramStrElement_AY" name="strElement_AY" attribute="value"/>
+    <PARAMETER id="paramStrElement_SR" name="strElement_SR" attribute="value"/>
+    <PARAMETER id="paramStrElement_MC" name="strElement_MC" attribute="value"/>   
 
     <DISCARD id="discard"/>
 </REPORT>
--- a/modules/org.openbravo.advpaymentmngt/src/org/openbravo/advpaymentmngt/ad_actionbutton/AddPaymentFromInvoice.java	Thu Oct 13 18:24:25 2011 +0200
+++ b/modules/org.openbravo.advpaymentmngt/src/org/openbravo/advpaymentmngt/ad_actionbutton/AddPaymentFromInvoice.java	Thu Oct 20 13:09:18 2011 +0200
@@ -179,7 +179,7 @@
       String strReferenceNo = vars.getStringParameter("inpReferenceNo", "");
       String paymentCurrencyId = vars.getRequiredStringParameter("inpCurrencyId");
       BigDecimal exchangeRate = new BigDecimal(vars.getRequiredNumericParameter("inpExchangeRate",
-          "1.0"));
+          "1"));
       BigDecimal convertedAmount = new BigDecimal(vars.getRequiredNumericParameter(
           "inpActualConverted", strPaymentAmount));
       OBError message = null;
@@ -516,7 +516,7 @@
 
   private String findExchangeRate(Currency paymentCurrency, Currency financialAccountCurrency,
       Date paymentDate, Organization organization, int conversionRatePrecision) {
-    String exchangeRate = "1.0";
+    String exchangeRate = "1";
     if (financialAccountCurrency != null && !financialAccountCurrency.equals(paymentCurrency)) {
       final ConversionRate conversionRate = FIN_Utility.getConversionRate(paymentCurrency,
           financialAccountCurrency, paymentDate, organization);
--- a/modules/org.openbravo.advpaymentmngt/src/org/openbravo/advpaymentmngt/ad_actionbutton/AddPaymentFromTransaction.html	Thu Oct 13 18:24:25 2011 +0200
+++ b/modules/org.openbravo.advpaymentmngt/src/org/openbravo/advpaymentmngt/ad_actionbutton/AddPaymentFromTransaction.html	Thu Oct 20 13:09:18 2011 +0200
@@ -176,7 +176,8 @@
     try {
       if (XMLHttpRequestObj.responseText) {
         strText = XMLHttpRequestObj.responseText;
-        document.getElementById('paramCredit').value = strText;
+        var data = eval(strText);
+        document.getElementById('paramCredit').value = applyFormatJSToOBMasked(data.credit);
         displayLogicForCredit();
       }
     } catch (e) {
@@ -189,7 +190,8 @@
   var table = document.getElementById('sectionGLItemGrid'),
       glitemCount = OB.APRM.APFT_GLItems.length,
       glitemAmount = 0,
-      rowCount, row, cellGLItemDesc, cellGLITemReceivedInAmt, cellGLITemPaidOutAmt, cellRemoveButton, i, textNode;
+      glitemDescLength = 20, glitemDescCont = "...",
+      cellCount, row, cellGLItemDesc, cellGLITemReceivedInAmt, cellGLITemPaidOutAmt, cellRemoveButton, i, textNode, glAcctDimsDesc, acctDim, cellGLItemDim;
 
   table.innerHTML = '';
   if (glitemCount === 0) {
@@ -200,31 +202,57 @@
   }
   OB.APRM.HasGLItems = true;
   for (i = 0; i < glitemCount; i++) {
-    rowCount = table.rows.length;
-    row = table.insertRow(rowCount);
+    row = table.insertRow(table.rows.length);
     row.className = 'DataGrid_Body_Row DataGrid_Body_Row_'+i%2;
+    cellCount = 0;
     
-    cellGLItemDesc = row.insertCell(0);
+    cellGLItemDesc = row.insertCell(cellCount);
     textNode = document.createTextNode(OB.APRM.APFT_GLItems[i].glitemDesc);
     cellGLItemDesc.appendChild(textNode);
     cellGLItemDesc.className = 'DataGrid_Body_Cell';
+    cellCount++;
     
-    cellGLITemReceivedInAmt = row.insertCell(1);
+    // Accounting Dimensions
+    glAcctDimsDesc = ["cBpartnerDimDesc", "cActivityDimDesc", "mProductDimDesc", "cCampaignDimDesc", "cProjectDimDesc", "cSalesregionDimDesc"];
+    for (acctDim = 0; acctDim < glAcctDimsDesc.length; acctDim++) {
+      if (OB.APRM.APFT_GLItems[i][glAcctDimsDesc[acctDim]]) {
+        cellGLItemDim = row.insertCell(cellCount);
+        if (OB.APRM.APFT_GLItems[i][glAcctDimsDesc[acctDim]].length > glitemDescLength + glitemDescCont.length) {
+          textNode = document.createTextNode(OB.APRM.APFT_GLItems[i][glAcctDimsDesc[acctDim]].slice(0, glitemDescLength) + glitemDescCont);
+        } else {
+          textNode = document.createTextNode(OB.APRM.APFT_GLItems[i][glAcctDimsDesc[acctDim]]);
+        }
+        cellGLItemDim.appendChild(textNode);
+        cellGLItemDim.className = 'DataGrid_Body_Cell';
+        cellCount++;
+      } else if (OB.APRM.APFT_GLItems[i][glAcctDimsDesc[acctDim].replace("Desc", "Displayed")]) {
+        // The Acct. Dimen is displayed and the user has left it empty
+        cellGLItemDim = row.insertCell(cellCount);
+        textNode = document.createTextNode("");
+        cellGLItemDim.appendChild(textNode);
+        cellGLItemDim.className = 'DataGrid_Body_Cell';
+        cellCount++;
+      }
+    }
+    
+    cellGLITemReceivedInAmt = row.insertCell(cellCount);
     textNode = document.createTextNode(applyFormatJSToOBMasked(OB.APRM.APFT_GLItems[i].glitemReceivedInAmt));
     cellGLITemReceivedInAmt.appendChild(textNode);
     cellGLITemReceivedInAmt.className = 'DataGrid_Body_Cell_Amount';
+    cellCount++;
     
-    cellGLITemPaidOutAmt = row.insertCell(2);
+    cellGLITemPaidOutAmt = row.insertCell(cellCount);
     textNode = document.createTextNode(applyFormatJSToOBMasked(OB.APRM.APFT_GLItems[i].glitemPaidOutAmt));
     cellGLITemPaidOutAmt.appendChild(textNode);
     cellGLITemPaidOutAmt.className = 'DataGrid_Body_Cell_Amount';
+    cellCount++;
     
     if (isTrue('isReceipt')) {
       glitemAmount = subtract(applyFormatJSToOBMasked(OB.APRM.APFT_GLItems[i].glitemReceivedInAmt), applyFormatJSToOBMasked(OB.APRM.APFT_GLItems[i].glitemPaidOutAmt));
     } else {
       glitemAmount = subtract(applyFormatJSToOBMasked(OB.APRM.APFT_GLItems[i].glitemPaidOutAmt), applyFormatJSToOBMasked(OB.APRM.APFT_GLItems[i].glitemReceivedInAmt));
     }
-    cellRemoveButton = row.insertCell(3);
+    cellRemoveButton = row.insertCell(cellCount);
     cellRemoveButton.innerHTML = '<div><button type="button" id="buttonRemoveGLItem"'
         + ' class="ButtonLink_focus" onclick="removeGLItem(' + i + ', ' + applyFormatOBMaskedToJS(glitemAmount) + ');return false;"'
         + ' onfocus="buttonEvent(\'onfocus\', this); window.status=\'OK\'; return true;"'
@@ -285,6 +313,24 @@
     id: OB.APRM.APFT_GLItemsId,
     glitemId: frm.inpcGlitemId.value,
     glitemDesc: sc_C_Glitem_ID.selectorField.getDisplayValue(),
+    cBpartnerDim: frm.inpCBPartnerId_dim && frm.inpCBPartnerId_dim.value,
+    cBpartnerDimDesc: sc_C_BPartner_ID_dim.selectorField.getDisplayValue(),
+    cBpartnerDimDisplayed: frm.strElement_BP.value,
+    cActivityDim: frm.inpCActivityId && frm.inpCActivityId.value,
+    cActivityDimDesc: sc_C_Activity_ID.selectorField.getDisplayValue(),
+    cActivityDimDisplayed: frm.strElement_AY.value,
+    mProductDim: frm.inpMProductId && frm.inpMProductId.value,
+    mProductDimDesc:  sc_M_Product_ID.selectorField.getDisplayValue(),
+    mProductDimDisplayed: frm.strElement_PR.value,
+    cCampaignDim: frm.inpCampaignId && frm.inpCampaignId.value,
+    cCampaignDimDesc: sc_C_Campaign_ID.selectorField.getDisplayValue(),
+    cCampaignDimDisplayed: frm.strElement_MC.value,
+    cProjectDim: frm.inpCProjectId && frm.inpCProjectId.value,
+    cProjectDimDesc: sc_C_Project_ID.selectorField.getDisplayValue(),
+    cProjectDimDisplayed: frm.strElement_PJ.value,
+    cSalesregionDim: frm.inpCSalesRegionId && frm.inpCSalesRegionId.value,
+    cSalesregionDimDesc: sc_C_SalesRegion_ID.selectorField.getDisplayValue(),
+    cSalesregionDimDisplayed: frm.strElement_SR.value,
     glitemReceivedInAmt: OB.Utilities.Number.OBMaskedToJS(frm.inpGLItemReceivedInAmount.value,
                                                           getGlobalDecSeparator(),
                                                           getGlobalGroupSeparator()),
@@ -361,7 +407,7 @@
         selectedAction = diffAction[i].value;
         if ((frm.inpcBpartnerId.value==null || frm.inpcBpartnerId.value=="") && (selectedAction === "credit" || selectedAction === "refund") ) {
             setWindowElementFocus(frm.inpBpartnerId_DES);
-            showJSMessage(7);
+            showJSMessage('APRM_bpmandatory_creditrefund');
             return false;
         }
       }
@@ -444,12 +490,66 @@
   displayLogicElement('gridPayment', !toGLItem);
   displayLogicElement('totalGLItems', !toGLItem);
   
+  autoDisplayLogicDimensions(toGLItem);
+  
   resizeAreaCreateFrom();
   if (toGLItem) {
     loadGLItemList();
   }
   return true;
 }
+function autoDisplayLogicDimensions(isDisplayed) {
+  var displayLogicDimension = function (dimension, isDisplayed) {
+    displayLogicElement(dimension + '_dim_label', isDisplayed);
+    displayLogicElement(dimension + '_dim_inp', isDisplayed);
+    displayLogicElement(dimension + '_th', isDisplayed)
+  }
+  var displayTitle = false;
+  if (document.frmMain.strElement_BP.value === 'Y' && isDisplayed) {
+    displayLogicDimension('c_bpartner_id', true);
+    displayTitle = true;
+  } else {
+    displayLogicDimension('c_bpartner_id', false);
+  }  
+  if (document.frmMain.strElement_AY.value === 'Y' && isDisplayed) {
+    displayLogicDimension('c_activity_id', true);
+    displayTitle = true;
+  } else {
+    displayLogicDimension('c_activity_id', false);
+  }
+  
+  if (document.frmMain.strElement_PR.value === 'Y' && isDisplayed) {
+    displayLogicDimension('m_product_id', true);
+    displayTitle = true;
+  } else {
+    displayLogicDimension('m_product_id', false);
+  }
+  if (document.frmMain.strElement_MC.value === 'Y' && isDisplayed) {
+    displayLogicDimension('c_campaign_id', true);
+    displayTitle = true;
+  } else {
+    displayLogicDimension('c_campaign_id', false);
+  }
+  
+  if (document.frmMain.strElement_PJ.value === 'Y' && isDisplayed) {
+    displayLogicDimension('c_project_id', true);
+    displayTitle = true;
+  } else {
+    displayLogicDimension('c_project_id', false);
+  }
+  if (document.frmMain.strElement_SR.value === 'Y' && isDisplayed) {
+    displayLogicDimension('c_salesregion_id', true);
+    displayTitle = true;
+  } else {
+    displayLogicDimension('c_salesregion_id', false);
+  }
+  
+  if (displayTitle) {
+    displayLogicElement('acctDimensionsTitle', true);
+  } else {
+    displayLogicElement('acctDimensionsTitle', false);
+  }
+}
 function documentTypeOnChange(value){
   if ('G' === value) {
     //if we are not already on GL Item mode.
@@ -667,6 +767,12 @@
   <input type="hidden" name="isInGLItemMode" value="N"/>
   <input type="hidden" name="inpGLItems" value=""/>
   <input type="hidden" name="inpInheritedActualPayment" value="N" id="paramInheritedActualPayment"/>
+  <input type="hidden" name="strElement_BP" id="paramStrElement_BP" value=""/>
+  <input type="hidden" name="strElement_PR" id="paramStrElement_PR" value=""/>
+  <input type="hidden" name="strElement_PJ" id="paramStrElement_PJ" value=""/>
+  <input type="hidden" name="strElement_AY" id="paramStrElement_AY" value=""/>
+  <input type="hidden" name="strElement_SR" id="paramStrElement_SR" value=""/>
+  <input type="hidden" name="strElement_MC" id="paramStrElement_MC" value=""/>
   <div class="Popup_ContentPane_CircleLogo">
     <div class="Popup_WindowLogo">
       <img class="Popup_WindowLogo_Icon Popup_WindowLogo_Icon_process" src="../../../../../web/images/blank.gif" border=0/></img>
@@ -1375,6 +1481,110 @@
               </td>
               <td class="TitleCell"></td>
             </tr>
+                        
+            <tr id="acctDimensionsTitle">
+              <td colspan="6">
+                <table class="FieldGroup" cellspacing="0" cellpadding="0" border="0">
+                <tbody>
+                  <tr class="FieldGroup_TopMargin"/>
+                  <tr>
+                    <td class="FieldGroupTitle_Left"><img class="FieldGroupTitle_Left_bg" border="0" src="../../../../../web/images/blank.gif"/></td>
+                    <td class="FieldGroupTitle">Accounting Dimensions</td>
+                    <td class="FieldGroupTitle_Right"><img class="FieldGroupTitle_Right_bg" border="0" src="../../../../../web/images/blank.gif"/></td>
+                    <td class="FieldGroupContent"/>
+                  </tr>
+                  <tr class="FieldGroup_BottomMargin"/>
+                </tbody>
+                </table>
+              </td>
+            </tr>
+            <tr id="GLItemSection1_Dim">
+              <!-- Business Partner Dimension -->
+              <td id="c_bpartner_id_dim_label" class="TitleCell"><span class="LabelText">Business Partner</span></td>
+              <td id="c_bpartner_id_dim_inp" class="TextBox_ContentCell" colspan="2">
+                <table style="border:0px;border-collapse:collapse;">
+                  <tr>
+                    <td style="padding-top: 0px;">
+                      <script>var sc_C_BPartner_ID_dim = null;</script>
+                      <input type="hidden" name="inpCBPartnerId_dim" id="C_BPartner_ID_dim" value="" onreset="sc_C_BPartner_ID_dim.resetSelector();" onchange="openbravo.Utilities.updateSmartClientComponentValue(this, sc_C_BPartner_ID_dim.selectorField);"></input>
+                      <script id="selectorLink" src="../org.openbravo.client.kernel/OBUISEL_Selector/A98899B1C75A4F4EBD3414F1B654EFAB?columnName=C_BPartner_ID_dim&disabled=false&CssSize=TwoCells&DisplayLength=45.0&required=false"></script>
+                    </td>
+                  </tr>
+                </table>
+              </td>
+              <!-- Activity Dimension -->
+              <td id="c_activity_id_dim_label" class="TitleCell"><span class="LabelText">Activity</span></td>
+              <td id="c_activity_id_dim_inp" class="TextBox_ContentCell" colspan="1">
+                <table style="border:0px;border-collapse:collapse;">
+                  <tr>
+                    <td style="padding-top: 0px;">
+                      <script>var sc_C_Activity_ID = null;</script>
+                      <input type="hidden" name="inpCActivityId" id="C_Activity_ID" value="" onreset="sc_C_Activity_ID.resetSelector();" onchange="openbravo.Utilities.updateSmartClientComponentValue(this, sc_C_Activity_ID.selectorField);"></input>
+                      <script id="selectorLink" src="../org.openbravo.client.kernel/OBUISEL_Selector/FF808181312D569C01312D8C1EC40036?columnName=C_Activity_ID&disabled=false&CssSize=TwoCells&DisplayLength=45.0&required=false"></script>
+                    </td>
+                  </tr>
+                </table>
+              </td>             
+              <td class="TitleCell"></td>
+            </tr>
+            <tr id="GLItemSection2_Dim">
+              <!-- Product Dimension -->
+              <td id="m_product_id_dim_label" class="TitleCell"><span class="LabelText">Product</span></td>
+              <td id="m_product_id_dim_inp" class="TextBox_ContentCell" colspan="2">
+                <table style="border:0px;border-collapse:collapse;">
+                  <tr>
+                    <td style="padding-top: 0px;">
+                      <script>var sc_M_Product_ID = null;</script>
+                      <input type="hidden" name="inpMProductId" id="M_Product_ID" value="" onreset="sc_M_Product_ID.resetSelector();" onchange="openbravo.Utilities.updateSmartClientComponentValue(this, sc_M_Product_ID.selectorField);"></input>
+                      <script id="selectorLink" src="../org.openbravo.client.kernel/OBUISEL_Selector/FF808181312DA8D801312DDE869B000C?columnName=M_Product_ID&disabled=false&CssSize=TwoCells&DisplayLength=45.0&required=false"></script>
+                    </td>
+                  </tr>
+                </table>
+              </td>
+              <!-- Campaign Dimension -->
+              <td id="c_campaign_id_dim_label" class="TitleCell"><span class="LabelText">Campaign</span></td>
+              <td id="c_campaign_id_dim_inp" class="TextBox_ContentCell" colspan="1">
+                <table style="border:0px;border-collapse:collapse;">
+                  <tr>
+                    <td style="padding-top: 0px;">
+                      <script>var sc_C_Campaign_ID = null;</script>
+                      <input type="hidden" name="inpCampaignId" id="C_Campaign_ID" value="" onreset="sc_C_Campaign_ID.resetSelector();" onchange="openbravo.Utilities.updateSmartClientComponentValue(this, sc_C_Campaign_ID.selectorField);"></input>
+                      <script id="selectorLink" src="../org.openbravo.client.kernel/OBUISEL_Selector/FF808181312D569C01312D8DCCD50045?columnName=C_Campaign_ID&disabled=false&CssSize=TwoCells&DisplayLength=45.0&required=false"></script>
+                    </td>
+                  </tr>
+                </table>
+              </td>
+              <td class="TitleCell"></td>
+            </tr>
+            <tr id="GLItemSection3_Dim">
+              <!-- Project Dimension -->
+              <td id="c_project_id_dim_label" class="TitleCell"><span class="LabelText">Project</span></td>
+              <td id="c_project_id_dim_inp" class="TextBox_ContentCell" colspan="2">
+                <table style="border:0px;border-collapse:collapse;">
+                  <tr>
+                    <td style="padding-top: 0px;">
+                      <script>var sc_C_Project_ID = null;</script>
+                      <input type="hidden" name="inpCProjectId" id="C_Project_ID" value="" onreset="sc_C_Project_ID.resetSelector();" onchange="openbravo.Utilities.updateSmartClientComponentValue(this, sc_C_Project_ID.selectorField);"></input>
+                      <script id="selectorLink" src="../org.openbravo.client.kernel/OBUISEL_Selector/FF808181312D569C01312D90408D005D?columnName=C_Project_ID&disabled=false&CssSize=TwoCells&DisplayLength=45.0&required=false"></script>
+                    </td>
+                  </tr>
+                </table>
+              </td>
+              <!-- Sales Region Dimension -->
+              <td id="c_salesregion_id_dim_label" class="TitleCell"><span class="LabelText">Sales Region</span></td>
+              <td id="c_salesregion_id_dim_inp" class="TextBox_ContentCell" colspan="1">
+                <table style="border:0px;border-collapse:collapse;">
+                  <tr>
+                    <td style="padding-top: 0px;">
+                      <script>var sc_C_SalesRegion_ID = null;</script>
+                      <input type="hidden" name="inpCSalesRegionId" id="C_SalesRegion_ID" value="" onreset="sc_C_SalesRegion_ID.resetSelector();" onchange="openbravo.Utilities.updateSmartClientComponentValue(this, sc_C_SalesRegion_ID.selectorField);"></input>
+                      <script id="selectorLink" src="../org.openbravo.client.kernel/OBUISEL_Selector/FF808181312D569C01312D8EE5430054?columnName=C_SalesRegion_ID&disabled=false&CssSize=TwoCells&DisplayLength=45.0&required=false"></script>
+                    </td>
+                  </tr>
+                </table>
+              </td>
+              <td class="TitleCell"></td>
+            </tr>   
             <tr id="glitemAddRow">
               <td class="TitleCell"></td>
               <td class="Button_RightAlign_ContentCell">
@@ -1445,7 +1655,13 @@
                   <table cellspacing="0" cellpadding="0" width="100%" class="DataGrid_Header_Table DataGrid_Body_Table" style="table-layout: auto;" id="gridGLItem">
                     <thead>
                       <tr class="DataGrid_Body_Row">
-                        <th class="DataGrid_Header_Cell" width="400">GL Item</th>
+                         <th class="DataGrid_Header_Cell" width="300">GL Item</th>
+                        <th class="DataGrid_Header_Cell DataGrid_Header_Cell_Inverse" width="100" id="c_bpartner_id_th">Business Partner</th>
+                        <th class="DataGrid_Header_Cell DataGrid_Header_Cell_Inverse" width="100" id="c_activity_id_th">Activity</th>
+                        <th class="DataGrid_Header_Cell DataGrid_Header_Cell_Inverse" width="100" id="m_product_id_th">Product</th>
+                        <th class="DataGrid_Header_Cell DataGrid_Header_Cell_Inverse" width="100" id="c_campaign_id_th">Campaign</th>
+                        <th class="DataGrid_Header_Cell DataGrid_Header_Cell_Inverse" width="100" id="c_project_id_th">Project</th>
+                        <th class="DataGrid_Header_Cell DataGrid_Header_Cell_Inverse" width="100" id="c_salesregion_id_th">Sales Region</th>
                         <th class="DataGrid_Header_Cell DataGrid_Header_Cell_Inverse" width="100">Received In</th>
                         <th class="DataGrid_Header_Cell DataGrid_Header_Cell_Inverse" width="100">Paid Out</th>
                         <th class="DataGrid_Header_LineNoCell" width="20"></th>
--- a/modules/org.openbravo.advpaymentmngt/src/org/openbravo/advpaymentmngt/ad_actionbutton/AddPaymentFromTransaction.java	Thu Oct 13 18:24:25 2011 +0200
+++ b/modules/org.openbravo.advpaymentmngt/src/org/openbravo/advpaymentmngt/ad_actionbutton/AddPaymentFromTransaction.java	Thu Oct 20 13:09:18 2011 +0200
@@ -58,6 +58,7 @@
 import org.openbravo.model.common.currency.Currency;
 import org.openbravo.model.common.enterprise.DocumentType;
 import org.openbravo.model.common.enterprise.Organization;
+import org.openbravo.model.common.plm.Product;
 import org.openbravo.model.financialmgmt.gl.GLItem;
 import org.openbravo.model.financialmgmt.payment.FIN_BankStatementLine;
 import org.openbravo.model.financialmgmt.payment.FIN_FinancialAccount;
@@ -65,6 +66,10 @@
 import org.openbravo.model.financialmgmt.payment.FIN_PaymentMethod;
 import org.openbravo.model.financialmgmt.payment.FIN_PaymentScheduleDetail;
 import org.openbravo.model.financialmgmt.payment.FinAccPaymentMethod;
+import org.openbravo.model.marketing.Campaign;
+import org.openbravo.model.materialmgmt.cost.ABCActivity;
+import org.openbravo.model.project.Project;
+import org.openbravo.model.sales.SalesRegion;
 import org.openbravo.service.db.CallStoredProcedure;
 import org.openbravo.xmlEngine.XmlDocument;
 
@@ -87,9 +92,10 @@
           IsIDFilter.instance);
       String strCurrencyId = vars.getRequestGlobalVariable("inpCurrencyId", "");
       String strTransactionDate = vars.getStringParameter("inpMainDate", "");
+      String strWindowId = vars.getSessionValue("AddTransaction|windowId");
 
       printPage(response, vars, strFinancialAccountId, isReceipt, strFinBankStatementLineId,
-          strTransactionDate, strCurrencyId, conversionRatePrecision);
+          strTransactionDate, strCurrencyId, conversionRatePrecision, strWindowId);
 
     } else if (vars.commandIn("GRIDLIST")) {
       final String strBusinessPartnerId = vars.getRequestGlobalVariable("inpcBpartnerId", "");
@@ -120,13 +126,18 @@
     } else if (vars.commandIn("LOADCREDIT")) {
       final String strBusinessPartnerId = vars.getRequiredStringParameter("inpcBpartnerId");
       final boolean isReceipt = "Y".equals(vars.getRequiredStringParameter("isReceipt"));
-      String customerCredit = dao.getCustomerCredit(
-          OBDal.getInstance().get(BusinessPartner.class, strBusinessPartnerId), isReceipt)
-          .toString();
+      BigDecimal customerCredit = dao.getCustomerCredit(
+          OBDal.getInstance().get(BusinessPartner.class, strBusinessPartnerId), isReceipt);
       response.setContentType("text/html; charset=UTF-8");
       response.setHeader("Cache-Control", "no-cache");
       PrintWriter out = response.getWriter();
-      out.println(customerCredit);
+      JSONObject json = new JSONObject();
+      try {
+        json.put("credit", customerCredit);
+      } catch (JSONException e) {
+        log4j.error("Error parsing load credit JSON: " + customerCredit, e);
+      }
+      out.println("data = " + json.toString());
       out.close();
 
     } else if (vars.commandIn("EXCHANGERATE")) {
@@ -173,7 +184,7 @@
       String strReferenceNo = vars.getStringParameter("inpReferenceNo", "");
       String paymentCurrencyId = vars.getRequiredStringParameter("inpCurrencyId");
       BigDecimal exchangeRate = new BigDecimal(vars.getRequiredNumericParameter("inpExchangeRate",
-          "1.0"));
+          "1"));
       BigDecimal convertedAmount = new BigDecimal(vars.getRequiredNumericParameter(
           "inpActualConverted", strPaymentAmount));
       OBError message = null;
@@ -230,8 +241,37 @@
             } else {
               glItemAmt = glItemOutAmt.subtract(glItemInAmt);
             }
-            FIN_AddPayment.saveGLItem(payment, glItemAmt,
-                dao.getObject(GLItem.class, glItem.getString("glitemId")));
+            final String strGLItemId = glItem.getString("glitemId");
+            checkID(strGLItemId);
+
+            // Accounting Dimensions
+            final String strElement_BP = glItem.getString("cBpartnerDim");
+            checkID(strElement_BP);
+            final BusinessPartner businessPartner = dao.getObject(BusinessPartner.class,
+                strElement_BP);
+
+            final String strElement_PR = glItem.getString("mProductDim");
+            checkID(strElement_PR);
+            final Product product = dao.getObject(Product.class, strElement_PR);
+
+            final String strElement_PJ = glItem.getString("cProjectDim");
+            checkID(strElement_PJ);
+            final Project project = dao.getObject(Project.class, strElement_PJ);
+
+            final String strElement_AY = glItem.getString("cActivityDim");
+            checkID(strElement_AY);
+            final ABCActivity activity = dao.getObject(ABCActivity.class, strElement_AY);
+
+            final String strElement_SR = glItem.getString("cSalesregionDim");
+            checkID(strElement_SR);
+            final SalesRegion salesRegion = dao.getObject(SalesRegion.class, strElement_SR);
+
+            final String strElement_MC = glItem.getString("cCampaignDim");
+            checkID(strElement_MC);
+            final Campaign campaign = dao.getObject(Campaign.class, strElement_MC);
+
+            FIN_AddPayment.saveGLItem(payment, glItemAmt, dao.getObject(GLItem.class, strGLItemId),
+                businessPartner, product, project, campaign, activity, salesRegion);
           }
         }
         payment = FIN_AddPayment.savePayment(payment, isReceipt, null, null, null, null, null,
@@ -305,8 +345,8 @@
 
   private void printPage(HttpServletResponse response, VariablesSecureApp vars,
       String strFinancialAccountId, boolean isReceipt, String strFinBankStatementLineId,
-      String strTransactionDate, String strCurrencyId, int conversionRatePrecision)
-      throws IOException, ServletException {
+      String strTransactionDate, String strCurrencyId, int conversionRatePrecision,
+      String strWindowId) throws IOException, ServletException {
     log4j.debug("Output: Add Payment button pressed on Add Transaction popup.");
     dao = new AdvPaymentMngtDao();
     String defaultPaymentMethod = "";
@@ -398,15 +438,21 @@
         .getFinancialAccountCurrency(strFinancialAccountId);
     if (financialAccountCurrency != null) {
       xmlDocument.setParameter("financialAccountCurrencyId", financialAccountCurrency.getId());
-      xmlDocument.setParameter("financialAccountCurrencyPrecision", financialAccountCurrency
-          .getStandardPrecision().toString());
+      try {
+        OBContext.setAdminMode(true);
+        xmlDocument.setParameter("financialAccountCurrencyPrecision", financialAccountCurrency
+            .getStandardPrecision().toString());
+      } finally {
+        OBContext.restorePreviousMode();
+      }
     }
 
-    String exchangeRate = "1.0";
+    String exchangeRate = "1";
     if (financialAccountCurrency != null && !financialAccountCurrency.equals(paymentCurrency)) {
       exchangeRate = findExchangeRate(paymentCurrency, financialAccountCurrency, new Date(),
           financialAccount.getOrganization(), conversionRatePrecision);
     }
+
     xmlDocument.setParameter("exchangeRate", exchangeRate);
 
     // Payment Method combobox
@@ -453,6 +499,20 @@
       throw new ServletException(ex);
     }
 
+    // Accounting Dimensions
+    final String strElement_BP = Utility.getContext(this, vars, "$Element_BP", strWindowId);
+    final String strElement_PR = Utility.getContext(this, vars, "$Element_PR", strWindowId);
+    final String strElement_PJ = Utility.getContext(this, vars, "$Element_PJ", strWindowId);
+    final String strElement_AY = Utility.getContext(this, vars, "$Element_AY", strWindowId);
+    final String strElement_SR = Utility.getContext(this, vars, "$Element_SR", strWindowId);
+    final String strElement_MC = Utility.getContext(this, vars, "$Element_MC", strWindowId);
+    xmlDocument.setParameter("strElement_BP", strElement_BP);
+    xmlDocument.setParameter("strElement_PR", strElement_PR);
+    xmlDocument.setParameter("strElement_PJ", strElement_PJ);
+    xmlDocument.setParameter("strElement_AY", strElement_AY);
+    xmlDocument.setParameter("strElement_SR", strElement_SR);
+    xmlDocument.setParameter("strElement_MC", strElement_MC);
+
     response.setContentType("text/html; charset=UTF-8");
     PrintWriter out = response.getWriter();
     out.println(xmlDocument.print());
@@ -599,7 +659,7 @@
 
   private String findExchangeRate(Currency paymentCurrency, Currency financialAccountCurrency,
       Date paymentDate, Organization organization, int conversionRatePrecision) {
-    String exchangeRate = "1.0";
+    String exchangeRate = "1";
     if (financialAccountCurrency != null && !financialAccountCurrency.equals(paymentCurrency)) {
       final ConversionRate conversionRate = FIN_Utility.getConversionRate(paymentCurrency,
           financialAccountCurrency, paymentDate, organization);
@@ -627,6 +687,13 @@
     return FieldProviderFactory.getFieldProviderArray(result);
   }
 
+  private void checkID(final String id) throws ServletException {
+    if (!IsIDFilter.instance.accept(id)) {
+      log4j.error("Input: " + id + " not accepted by filter: IsIDFilter");
+      throw new ServletException("Input: " + id + " is not an accepted input");
+    }
+  }
+
   public String getServletInfo() {
     return "Servlet that presents the payment proposal";
     // end of getServletInfo() method
--- a/modules/org.openbravo.advpaymentmngt/src/org/openbravo/advpaymentmngt/ad_actionbutton/AddPaymentFromTransaction.xml	Thu Oct 13 18:24:25 2011 +0200
+++ b/modules/org.openbravo.advpaymentmngt/src/org/openbravo/advpaymentmngt/ad_actionbutton/AddPaymentFromTransaction.xml	Thu Oct 20 13:09:18 2011 +0200
@@ -77,6 +77,14 @@
     <SUBREPORT id="reportActionDocument" name="reportActionDocument" report="org/openbravo/erpCommon/reference/List">
       <ARGUMENT name="parameterListSelected" withId="paramActionDocument"/>
     </SUBREPORT>
+    
+    <!-- Accounting Dimensions -->
+    <PARAMETER id="paramStrElement_BP" name="strElement_BP" attribute="value"/>
+    <PARAMETER id="paramStrElement_PR" name="strElement_PR" attribute="value"/>
+    <PARAMETER id="paramStrElement_PJ" name="strElement_PJ" attribute="value"/>
+    <PARAMETER id="paramStrElement_AY" name="strElement_AY" attribute="value"/>
+    <PARAMETER id="paramStrElement_SR" name="strElement_SR" attribute="value"/>
+    <PARAMETER id="paramStrElement_MC" name="strElement_MC" attribute="value"/>  
 
     <DISCARD id="discard"/>
     
--- a/modules/org.openbravo.advpaymentmngt/src/org/openbravo/advpaymentmngt/ad_actionbutton/AddTransaction.java	Thu Oct 13 18:24:25 2011 +0200
+++ b/modules/org.openbravo.advpaymentmngt/src/org/openbravo/advpaymentmngt/ad_actionbutton/AddTransaction.java	Thu Oct 20 13:09:18 2011 +0200
@@ -36,6 +36,7 @@
 import org.hibernate.criterion.Restrictions;
 import org.openbravo.advpaymentmngt.dao.AdvPaymentMngtDao;
 import org.openbravo.advpaymentmngt.dao.TransactionsDao;
+import org.openbravo.advpaymentmngt.process.FIN_TransactionProcess;
 import org.openbravo.advpaymentmngt.utility.FIN_Utility;
 import org.openbravo.base.exception.OBException;
 import org.openbravo.base.filter.IsIDFilter;
@@ -46,6 +47,7 @@
 import org.openbravo.dal.service.OBCriteria;
 import org.openbravo.dal.service.OBDal;
 import org.openbravo.data.FieldProvider;
+import org.openbravo.database.ConnectionProvider;
 import org.openbravo.erpCommon.utility.DateTimeData;
 import org.openbravo.erpCommon.utility.FieldProviderFactory;
 import org.openbravo.erpCommon.utility.OBError;
@@ -62,6 +64,8 @@
 import org.openbravo.model.materialmgmt.cost.ABCActivity;
 import org.openbravo.model.project.Project;
 import org.openbravo.model.sales.SalesRegion;
+import org.openbravo.scheduling.ProcessBundle;
+import org.openbravo.service.db.DalConnectionProvider;
 import org.openbravo.xmlEngine.XmlDocument;
 
 public class AddTransaction extends HttpSecureAppServlet {
@@ -162,7 +166,11 @@
                   : "PWNC", depositAmt, paymentAmt, null, null, null,
               p.isReceipt() ? "BPD" : "BPW", FIN_Utility.getDate(strTransactionDate), p
                   .getCurrency(), p.getFinancialTransactionConvertRate(), p.getAmount());
-          TransactionsDao.process(finTrans);
+          OBError processTransactionError = processTransaction(vars, new DalConnectionProvider(),
+              "P", finTrans);
+          if (processTransactionError != null && processTransactionError.getType().equals("Error")) {
+            throw new OBException(processTransactionError.getMessage());
+          }
           if (!"".equals(strFinBankStatementLineId)) {
             matchBankStatementLine(vars, finTrans, strFinBankStatementLineId);
           }
@@ -211,8 +219,11 @@
             glItemDepositAmt, glItemPaymentAmt, project, campaign, activity, isReceipt ? "BPD"
                 : "BPW", FIN_Utility.getDate(strTransactionDate), null, null, null,
             businessPartner, product, salesRegion);
-
-        TransactionsDao.process(finTrans);
+        OBError processTransactionError = processTransaction(vars, new DalConnectionProvider(),
+            "P", finTrans);
+        if (processTransactionError != null && processTransactionError.getType().equals("Error")) {
+          throw new OBException(processTransactionError.getMessage());
+        }
         strMessage = "1 " + "@RowsInserted@";
         if (!"".equals(strFinBankStatementLineId)) {
           matchBankStatementLine(vars, finTrans, strFinBankStatementLineId);
@@ -232,8 +243,11 @@
             FIN_Utility.getDate(strTransactionDate), null, isReceipt ? "RDNC" : "PWNC",
             feeDepositAmt, feePaymentAmt, null, null, null, "BF",
             FIN_Utility.getDate(strTransactionDate), null, null, null);
-
-        TransactionsDao.process(finTrans);
+        OBError processTransactionError = processTransaction(vars, new DalConnectionProvider(),
+            "P", finTrans);
+        if (processTransactionError != null && processTransactionError.getType().equals("Error")) {
+          throw new OBException(processTransactionError.getMessage());
+        }
         strMessage = "1 " + "@RowsInserted@";
         if (!"".equals(strFinBankStatementLineId)) {
           matchBankStatementLine(vars, finTrans, strFinBankStatementLineId);
@@ -408,8 +422,10 @@
           finTrans.getAccount(), "N");
       bsline.setMatchingtype("AD");
       bsline.setFinancialAccountTransaction(finTrans);
-      if (finTrans.getFinPayment() != null)
+      if (finTrans.getFinPayment() != null) {
         bsline.setBusinessPartner(finTrans.getFinPayment().getBusinessPartner());
+        finTrans.getFinPayment().setStatus("RPPC");
+      }
       finTrans.setReconciliation(reconciliation);
       finTrans.setStatus("RPPC");
       OBDal.getInstance().save(bsline);
@@ -418,6 +434,33 @@
     }
   }
 
+  /**
+   * It calls the Transaction Process for the given transaction and action.
+   * 
+   * @param vars
+   *          VariablesSecureApp with the session data.
+   * @param conn
+   *          ConnectionProvider with the connection being used.
+   * @param strAction
+   *          String with the action of the process. {P, D, R}
+   * @param transaction
+   *          FIN_FinaccTransaction that needs to be processed.
+   * @return a OBError with the result message of the process.
+   * @throws Exception
+   */
+  private OBError processTransaction(VariablesSecureApp vars, ConnectionProvider conn,
+      String strAction, FIN_FinaccTransaction transaction) throws Exception {
+    ProcessBundle pb = new ProcessBundle("F68F2890E96D4D85A1DEF0274D105BCE", vars).init(conn);
+    HashMap<String, Object> parameters = new HashMap<String, Object>();
+    parameters.put("action", strAction);
+    parameters.put("Fin_FinAcc_Transaction_ID", transaction.getId());
+    pb.setParams(parameters);
+    OBError myMessage = null;
+    new FIN_TransactionProcess().execute(pb);
+    myMessage = (OBError) pb.getResult();
+    return myMessage;
+  }
+
   public String getServletInfo() {
     return "This servlet adds transaction for a financial account";
   }
--- a/modules/org.openbravo.advpaymentmngt/src/org/openbravo/advpaymentmngt/ad_actionbutton/ImportBankFile.java	Thu Oct 13 18:24:25 2011 +0200
+++ b/modules/org.openbravo.advpaymentmngt/src/org/openbravo/advpaymentmngt/ad_actionbutton/ImportBankFile.java	Thu Oct 20 13:09:18 2011 +0200
@@ -54,7 +54,7 @@
     if (vars.commandIn("DEFAULT")) {
       String strProcessId = vars.getStringParameter("inpProcessId");
       String strWindow = vars.getStringParameter("inpwindowId");
-      String strKey = vars.getStringParameter("Fin_Financial_Account_ID");
+      String strKey = vars.getStringParameter("inpfinFinancialAccountId");
 
       String strTabId = vars.getStringParameter("inpTabId");
       String strMessage = "";
--- a/modules/org.openbravo.advpaymentmngt/src/org/openbravo/advpaymentmngt/ad_actionbutton/MatchTransaction.java	Thu Oct 13 18:24:25 2011 +0200
+++ b/modules/org.openbravo.advpaymentmngt/src/org/openbravo/advpaymentmngt/ad_actionbutton/MatchTransaction.java	Thu Oct 20 13:09:18 2011 +0200
@@ -38,6 +38,7 @@
 import org.openbravo.advpaymentmngt.dao.MatchTransactionDao;
 import org.openbravo.advpaymentmngt.dao.TransactionsDao;
 import org.openbravo.advpaymentmngt.process.FIN_AddPayment;
+import org.openbravo.advpaymentmngt.process.FIN_TransactionProcess;
 import org.openbravo.advpaymentmngt.utility.FIN_MatchedTransaction;
 import org.openbravo.advpaymentmngt.utility.FIN_MatchingTransaction;
 import org.openbravo.advpaymentmngt.utility.FIN_Utility;
@@ -71,15 +72,17 @@
 import org.openbravo.model.financialmgmt.payment.FIN_ReconciliationLineTemp;
 import org.openbravo.model.financialmgmt.payment.FIN_ReconciliationLine_v;
 import org.openbravo.model.financialmgmt.payment.MatchingAlgorithm;
+import org.openbravo.scheduling.ProcessBundle;
 import org.openbravo.service.db.DalConnectionProvider;
 import org.openbravo.xmlEngine.XmlDocument;
 
 public class MatchTransaction extends HttpSecureAppServlet {
   private static final long serialVersionUID = 1L;
+  VariablesSecureApp vars = null;
 
   public void doPost(HttpServletRequest request, HttpServletResponse response)
       throws ServletException, IOException {
-    VariablesSecureApp vars = new VariablesSecureApp(request);
+    vars = new VariablesSecureApp(request);
 
     if (vars.commandIn("DEFAULT")) {
       String strOrgId = vars.getRequestGlobalVariable("inpadOrgId", "MatchTransaction.adOrgId");
@@ -928,7 +931,13 @@
       transaction.setCreatedByAlgorithm(true);
       OBDal.getInstance().save(transaction);
       OBDal.getInstance().flush();
-      TransactionsDao.process(transaction);
+      try {
+        processTransaction(new DalConnectionProvider(), "P", transaction);
+      } catch (Exception e) {
+        OBError newError = Utility.translateError(this, vars, vars.getLanguage(),
+            FIN_Utility.getExceptionMessage(e));
+        throw new OBException(newError.getMessage());
+      }
       return transaction;
     }
   }
@@ -1166,6 +1175,31 @@
     }
   }
 
+  /**
+   * It calls the Transaction Process for the given transaction and action.
+   * 
+   * @param conn
+   *          ConnectionProvider with the connection being used.
+   * @param strAction
+   *          String with the action of the process. {P, D, R}
+   * @param transaction
+   *          FIN_FinaccTransaction that needs to be processed.
+   * @return a OBError with the result message of the process.
+   * @throws Exception
+   */
+  private OBError processTransaction(ConnectionProvider conn, String strAction,
+      FIN_FinaccTransaction transaction) throws Exception {
+    ProcessBundle pb = new ProcessBundle("F68F2890E96D4D85A1DEF0274D105BCE", vars).init(conn);
+    HashMap<String, Object> parameters = new HashMap<String, Object>();
+    parameters.put("action", strAction);
+    parameters.put("Fin_FinAcc_Transaction_ID", transaction.getId());
+    pb.setParams(parameters);
+    OBError myMessage = null;
+    new FIN_TransactionProcess().execute(pb);
+    myMessage = (OBError) pb.getResult();
+    return myMessage;
+  }
+
   public String getServletInfo() {
     return "This servlet match imported bank statement lines for a financial account";
   }
--- a/modules/org.openbravo.advpaymentmngt/src/org/openbravo/advpaymentmngt/ad_reports/ReportReconciliation.java	Thu Oct 13 18:24:25 2011 +0200
+++ b/modules/org.openbravo.advpaymentmngt/src/org/openbravo/advpaymentmngt/ad_reports/ReportReconciliation.java	Thu Oct 20 13:09:18 2011 +0200
@@ -182,7 +182,6 @@
    * @return List with 2 values. The first one is the sum of outstanding payments (transactions) and
    *         the second is the sum of outstanding deposits (transactions).
    */
-  @SuppressWarnings("unchecked")
   private List<BigDecimal> getOutstandingPaymentAndDepositTotal(FIN_Reconciliation recon) {
     List<BigDecimal> outList = new ArrayList<BigDecimal>();
     OBContext.setAdminMode(true);
@@ -208,6 +207,7 @@
       obcTrans.setProjection(projections);
 
       if (obcTrans.list() != null && obcTrans.list().size() > 0) {
+        @SuppressWarnings("rawtypes")
         List o = obcTrans.list();
         Object[] resultSet = (Object[]) o.get(0);
         BigDecimal paymentAmt = (resultSet[0] != null) ? (BigDecimal) resultSet[0]
@@ -238,7 +238,6 @@
    *          Reconciliation
    * @return Sum of the un-reconciled bank statement lines.
    */
-  @SuppressWarnings("unchecked")
   private BigDecimal getUnreconciledBankStatmentLinesTotal(FIN_Reconciliation recon) {
     BigDecimal total = BigDecimal.ZERO;
     OBContext.setAdminMode(true);
@@ -266,6 +265,7 @@
       obcBsl.setProjection(projections);
 
       if (obcBsl.list() != null && obcBsl.list().size() > 0) {
+        @SuppressWarnings("rawtypes")
         List o = obcBsl.list();
         Object[] resultSet = (Object[]) o.get(0);
         BigDecimal credit = (resultSet[0] != null) ? (BigDecimal) resultSet[0] : BigDecimal.ZERO;
@@ -289,7 +289,6 @@
    * @return Sum of all the transactions in a higher date than the end date of the given
    *         reconciliation.
    */
-  @SuppressWarnings("unchecked")
   private BigDecimal getTransactionsTotalAfterReconciliationEndDate(FIN_Reconciliation recon) {
     BigDecimal balance = BigDecimal.ZERO;
     OBContext.setAdminMode(true);
@@ -305,6 +304,7 @@
       obcTrans.setProjection(projections);
 
       if (obcTrans.list() != null && obcTrans.list().size() > 0) {
+        @SuppressWarnings("rawtypes")
         List o = obcTrans.list();
         Object[] resultSet = (Object[]) o.get(0);
         BigDecimal paymentAmt = (resultSet[0] != null) ? (BigDecimal) resultSet[0]
--- a/modules/org.openbravo.advpaymentmngt/src/org/openbravo/advpaymentmngt/dao/AdvPaymentMngtDao.java	Thu Oct 13 18:24:25 2011 +0200
+++ b/modules/org.openbravo.advpaymentmngt/src/org/openbravo/advpaymentmngt/dao/AdvPaymentMngtDao.java	Thu Oct 20 13:09:18 2011 +0200
@@ -476,6 +476,38 @@
     return newPaymentScheduleDetail;
   }
 
+  /**
+   * Returns a new FIN_PaymentScheduleDetail for the given accounting dimensions
+   * 
+   * @param organization
+   * @param amount
+   * @param businessPartner
+   *          accounting dimension
+   * @param product
+   *          accounting dimension
+   * @param project
+   *          accounting dimension
+   * @param campaign
+   *          accounting dimension
+   * @param activity
+   *          accounting dimension
+   * @param salesRegion
+   *          accounting dimension
+   * @return
+   */
+  public FIN_PaymentScheduleDetail getNewPaymentScheduleDetail(Organization organization,
+      BigDecimal amount, BusinessPartner businessPartner, Product product, Project project,
+      Campaign campaign, ABCActivity activity, SalesRegion salesRegion) {
+    final FIN_PaymentScheduleDetail psd = getNewPaymentScheduleDetail(organization, amount);
+    psd.setBusinessPartner(businessPartner);
+    psd.setProduct(product);
+    psd.setProject(project);
+    psd.setSalesCampaign(campaign);
+    psd.setActivity(activity);
+    psd.setSalesRegion(salesRegion);
+    return psd;
+  }
+
   public FIN_PaymentPropDetail getNewPaymentProposalDetail(Organization organization,
       FIN_PaymentProposal paymentProposal, FIN_PaymentScheduleDetail paymentScheduleDetail,
       BigDecimal amount, BigDecimal writeoffamount, GLItem glitem) {
--- a/modules/org.openbravo.advpaymentmngt/src/org/openbravo/advpaymentmngt/dao/MatchTransactionDao.java	Thu Oct 13 18:24:25 2011 +0200
+++ b/modules/org.openbravo.advpaymentmngt/src/org/openbravo/advpaymentmngt/dao/MatchTransactionDao.java	Thu Oct 20 13:09:18 2011 +0200
@@ -382,7 +382,6 @@
    *          Reconciliation.
    * @return Ending balance of an automatic reconciliation.
    */
-  @SuppressWarnings("unchecked")
   public static BigDecimal getReconciliationEndingBalance(FIN_Reconciliation reconciliation) {
     BigDecimal total = BigDecimal.ZERO;
     OBContext.setAdminMode(true);
@@ -404,6 +403,7 @@
       obcBsl.setProjection(projections);
 
       if (obcBsl.list() != null && obcBsl.list().size() > 0) {
+        @SuppressWarnings("rawtypes")
         List o = obcBsl.list();
         Object[] resultSet = (Object[]) o.get(0);
         BigDecimal credit = (resultSet[0] != null) ? (BigDecimal) resultSet[0] : BigDecimal.ZERO;
@@ -425,7 +425,6 @@
    *          Reconciliation.
    * @return Last reconciliation UnMatched balance
    */
-  @SuppressWarnings("unchecked")
   public static BigDecimal getLastReconciliationUnmatchedBalance(
       FIN_Reconciliation lastReconciliation) {
     BigDecimal total = BigDecimal.ZERO;
@@ -455,6 +454,7 @@
       obcBsl.setProjection(projections);
 
       if (obcBsl.list() != null && obcBsl.list().size() > 0) {
+        @SuppressWarnings("rawtypes")
         List o = obcBsl.list();
         Object[] resultSet = (Object[]) o.get(0);
         BigDecimal credit = (resultSet[0] != null) ? (BigDecimal) resultSet[0] : BigDecimal.ZERO;
--- a/modules/org.openbravo.advpaymentmngt/src/org/openbravo/advpaymentmngt/dao/TransactionsDao.java	Thu Oct 13 18:24:25 2011 +0200
+++ b/modules/org.openbravo.advpaymentmngt/src/org/openbravo/advpaymentmngt/dao/TransactionsDao.java	Thu Oct 20 13:09:18 2011 +0200
@@ -152,6 +152,7 @@
     return maxLine;
   }
 
+  @Deprecated
   public static void process(FIN_FinaccTransaction finFinancialAccountTransaction) {
     final FIN_FinancialAccount financialAccount = OBDal.getInstance().get(
         FIN_FinancialAccount.class, finFinancialAccountTransaction.getAccount().getId());
--- a/modules/org.openbravo.advpaymentmngt/src/org/openbravo/advpaymentmngt/process/FIN_AddPayment.java	Thu Oct 13 18:24:25 2011 +0200
+++ b/modules/org.openbravo.advpaymentmngt/src/org/openbravo/advpaymentmngt/process/FIN_AddPayment.java	Thu Oct 20 13:09:18 2011 +0200
@@ -51,6 +51,7 @@
 import org.openbravo.model.common.enterprise.DocumentType;
 import org.openbravo.model.common.enterprise.Organization;
 import org.openbravo.model.common.invoice.Invoice;
+import org.openbravo.model.common.plm.Product;
 import org.openbravo.model.financialmgmt.gl.GLItem;
 import org.openbravo.model.financialmgmt.payment.FIN_FinancialAccount;
 import org.openbravo.model.financialmgmt.payment.FIN_Payment;
@@ -61,6 +62,10 @@
 import org.openbravo.model.financialmgmt.payment.FIN_PaymentSchedule;
 import org.openbravo.model.financialmgmt.payment.FIN_PaymentScheduleDetail;
 import org.openbravo.model.financialmgmt.payment.FinAccPaymentMethod;
+import org.openbravo.model.marketing.Campaign;
+import org.openbravo.model.materialmgmt.cost.ABCActivity;
+import org.openbravo.model.project.Project;
+import org.openbravo.model.sales.SalesRegion;
 import org.openbravo.scheduling.ProcessBundle;
 
 public class FIN_AddPayment {
@@ -339,6 +344,49 @@
   }
 
   /**
+   * It adds to the Payment a new Payment Detail with the given GL Item, amount and accounting
+   * dimensions
+   * 
+   * @param payment
+   *          Payment where the new Payment Detail needs to be added.
+   * @param glitemAmount
+   *          Amount of the new Payment Detail.
+   * @param glitem
+   *          GLItem to be set in the new Payment Detail.
+   * @param businessPartner
+   *          accounting dimension
+   * @param product
+   *          accounting dimension
+   * @param project
+   *          accounting dimension
+   * @param campaign
+   *          accounting dimension
+   * @param activity
+   *          accounting dimension
+   * @param salesRegion
+   *          accounting dimension
+   */
+  public static void saveGLItem(FIN_Payment payment, BigDecimal glitemAmount, GLItem glitem,
+      BusinessPartner businessPartner, Product product, Project project, Campaign campaign,
+      ABCActivity activity, SalesRegion salesRegion) {
+    // FIXME: added to access the FIN_PaymentSchedule and FIN_PaymentScheduleDetail tables to be
+    // removed when new security implementation is done
+    dao = new AdvPaymentMngtDao();
+    OBContext.setAdminMode();
+    try {
+      FIN_PaymentScheduleDetail psd = dao.getNewPaymentScheduleDetail(payment.getOrganization(),
+          glitemAmount, businessPartner, product, project, campaign, activity, salesRegion);
+      FIN_PaymentDetail pd = dao.getNewPaymentDetail(payment, psd, glitemAmount, BigDecimal.ZERO,
+          false, glitem);
+      pd.setFinPayment(payment);
+      OBDal.getInstance().save(pd);
+      OBDal.getInstance().save(payment);
+    } finally {
+      OBContext.restorePreviousMode();
+    }
+  }
+
+  /**
    * Removes the Payment Detail from the Payment when the Detail is related to a GLItem
    * 
    * @param payment
--- a/modules/org.openbravo.advpaymentmngt/src/org/openbravo/advpaymentmngt/process/FIN_ExecutePayment.java	Thu Oct 13 18:24:25 2011 +0200
+++ b/modules/org.openbravo.advpaymentmngt/src/org/openbravo/advpaymentmngt/process/FIN_ExecutePayment.java	Thu Oct 20 13:09:18 2011 +0200
@@ -28,7 +28,10 @@
 import org.openbravo.advpaymentmngt.utility.FIN_PaymentExecutionProcess;
 import org.openbravo.advpaymentmngt.utility.FIN_Utility;
 import org.openbravo.advpaymentmngt.utility.Value;
+import org.openbravo.base.secureApp.VariablesSecureApp;
+import org.openbravo.client.kernel.RequestContext;
 import org.openbravo.dal.service.OBDal;
+import org.openbravo.database.ConnectionProvider;
 import org.openbravo.erpCommon.utility.OBError;
 import org.openbravo.model.common.businesspartner.BusinessPartner;
 import org.openbravo.model.common.enterprise.Organization;
@@ -42,6 +45,8 @@
 import org.openbravo.model.financialmgmt.payment.PaymentExecutionProcessParameter;
 import org.openbravo.model.financialmgmt.payment.PaymentRun;
 import org.openbravo.model.financialmgmt.payment.PaymentRunPayment;
+import org.openbravo.scheduling.ProcessBundle;
+import org.openbravo.service.db.DalConnectionProvider;
 
 public class FIN_ExecutePayment {
   private AdvPaymentMngtDao dao;
@@ -124,7 +129,16 @@
                 && paymentRunPayment.getPayment().getAmount().compareTo(BigDecimal.ZERO) != 0) {
               FIN_FinaccTransaction transaction = TransactionsDao
                   .createFinAccTransaction(paymentRunPayment.getPayment());
-              TransactionsDao.process(transaction);
+              // VariablesSecureApp vars = new VariablesSecureApp(OBContext.getOBContext().getUser()
+              // .getId(), OBContext.getOBContext().getCurrentOrganization().getId(), OBContext
+              // .getOBContext().getRole().getId());
+              VariablesSecureApp vars = new VariablesSecureApp(RequestContext.get().getRequest());
+              OBError processTransactionError = processTransaction(vars,
+                  new DalConnectionProvider(), "P", transaction);
+              if (processTransactionError != null
+                  && processTransactionError.getType().equals("Error")) {
+                return processTransactionError;
+              }
             }
           }
           if ("PPM".equals(paymentStatus) || "RPR".equals(paymentStatus)
@@ -201,4 +215,31 @@
     }
   }
 
+  /**
+   * It calls the Transaction Process for the given transaction and action.
+   * 
+   * @param vars
+   *          VariablesSecureApp with the session data.
+   * @param conn
+   *          ConnectionProvider with the connection being used.
+   * @param strAction
+   *          String with the action of the process. {P, D, R}
+   * @param transaction
+   *          FIN_FinaccTransaction that needs to be processed.
+   * @return a OBError with the result message of the process.
+   * @throws Exception
+   */
+  private OBError processTransaction(VariablesSecureApp vars, ConnectionProvider conn,
+      String strAction, FIN_FinaccTransaction transaction) throws Exception {
+    ProcessBundle pb = new ProcessBundle("F68F2890E96D4D85A1DEF0274D105BCE", vars).init(conn);
+    HashMap<String, Object> parameters = new HashMap<String, Object>();
+    parameters.put("action", strAction);
+    parameters.put("Fin_FinAcc_Transaction_ID", transaction.getId());
+    pb.setParams(parameters);
+    OBError myMessage = null;
+    new FIN_TransactionProcess().execute(pb);
+    myMessage = (OBError) pb.getResult();
+    return myMessage;
+  }
+
 }
--- a/modules/org.openbravo.advpaymentmngt/src/org/openbravo/advpaymentmngt/process/FIN_PaymentProcess.java	Thu Oct 13 18:24:25 2011 +0200
+++ b/modules/org.openbravo.advpaymentmngt/src/org/openbravo/advpaymentmngt/process/FIN_PaymentProcess.java	Thu Oct 20 13:09:18 2011 +0200
@@ -20,6 +20,7 @@
 
 import java.math.BigDecimal;
 import java.util.ArrayList;
+import java.util.HashMap;
 import java.util.List;
 import java.util.Set;
 import java.util.TreeSet;
@@ -30,6 +31,7 @@
 import org.openbravo.advpaymentmngt.exception.NoExecutionProcessFoundException;
 import org.openbravo.advpaymentmngt.utility.FIN_Utility;
 import org.openbravo.base.exception.OBException;
+import org.openbravo.base.provider.OBProvider;
 import org.openbravo.base.secureApp.VariablesSecureApp;
 import org.openbravo.dal.core.OBContext;
 import org.openbravo.dal.service.OBCriteria;
@@ -38,8 +40,8 @@
 import org.openbravo.erpCommon.utility.OBError;
 import org.openbravo.erpCommon.utility.Utility;
 import org.openbravo.model.common.businesspartner.BusinessPartner;
+import org.openbravo.model.common.currency.ConversionRateDoc;
 import org.openbravo.model.common.invoice.Invoice;
-import org.openbravo.model.common.currency.ConversionRateDoc;
 import org.openbravo.model.financialmgmt.payment.FIN_FinaccTransaction;
 import org.openbravo.model.financialmgmt.payment.FIN_Payment;
 import org.openbravo.model.financialmgmt.payment.FIN_PaymentDetail;
@@ -298,7 +300,10 @@
                 && payment.getAmount().compareTo(BigDecimal.ZERO) != 0)
               triggerAutomaticFinancialAccountTransaction(vars, conProvider, payment);
           }
-
+          if (!payment.getAccount().getCurrency().equals(payment.getCurrency())
+              && getConversionRateDocument(payment).size() == 0) {
+            insertConversionRateDocument(payment);
+          }
         } finally {
           OBDal.getInstance().flush();
           OBContext.restorePreviousMode();
@@ -511,11 +516,13 @@
                     }
                   }
                   // Create merged Payment Schedule Detail with the pending to be paid amount
-                  final FIN_PaymentScheduleDetail mergedScheduleDetail = dao
-                      .getNewPaymentScheduleDetail(payment.getOrganization(), outStandingAmt);
-                  mergedScheduleDetail.setInvoicePaymentSchedule(paymentScheduleDetail
-                      .getInvoicePaymentSchedule());
-                  OBDal.getInstance().save(mergedScheduleDetail);
+                  if (outStandingAmt.compareTo(BigDecimal.ZERO) != 0) {
+                    final FIN_PaymentScheduleDetail mergedScheduleDetail = dao
+                        .getNewPaymentScheduleDetail(payment.getOrganization(), outStandingAmt);
+                    mergedScheduleDetail.setInvoicePaymentSchedule(paymentScheduleDetail
+                        .getInvoicePaymentSchedule());
+                    OBDal.getInstance().save(mergedScheduleDetail);
+                  }
                 } else if (paymentScheduleDetail.getOrderPaymentSchedule() != null) {
                   // Related to orders
                   for (final FIN_PaymentScheduleDetail ordScheDetail : paymentScheduleDetail
@@ -530,11 +537,15 @@
                     }
                   }
                   // Create merged Payment Schedule Detail with the pending to be paid amount
-                  final FIN_PaymentScheduleDetail mergedScheduleDetail = dao
-                      .getNewPaymentScheduleDetail(payment.getOrganization(), outStandingAmt);
-                  mergedScheduleDetail.setOrderPaymentSchedule(paymentScheduleDetail
-                      .getOrderPaymentSchedule());
-                  OBDal.getInstance().save(mergedScheduleDetail);
+                  if (outStandingAmt.compareTo(BigDecimal.ZERO) != 0) {
+                    final FIN_PaymentScheduleDetail mergedScheduleDetail = dao
+                        .getNewPaymentScheduleDetail(payment.getOrganization(), outStandingAmt);
+                    mergedScheduleDetail.setOrderPaymentSchedule(paymentScheduleDetail
+                        .getOrderPaymentSchedule());
+                    OBDal.getInstance().save(mergedScheduleDetail);
+                  }
+                } else if (paymentDetail.getGLItem() != null) {
+                  paymentScheduleDetail.setCanceled(true);
                 } else if (paymentScheduleDetail.getOrderPaymentSchedule() == null
                     && paymentScheduleDetail.getInvoicePaymentSchedule() == null) {
                   // Credit payment
@@ -606,7 +617,12 @@
   private void triggerAutomaticFinancialAccountTransaction(VariablesSecureApp vars,
       ConnectionProvider connectionProvider, FIN_Payment payment) {
     FIN_FinaccTransaction transaction = TransactionsDao.createFinAccTransaction(payment);
-    TransactionsDao.process(transaction);
+    try {
+      processTransaction(vars, connectionProvider, "P", transaction);
+    } catch (Exception e) {
+      OBDal.getInstance().rollbackAndClose();
+      e.printStackTrace(System.err);
+    }
     return;
   }
 
@@ -686,4 +702,66 @@
           totalPaid.toString(), paymentSchedule.getOutstandingAmount().toString()));
     }
   }
+
+  private List<ConversionRateDoc> getConversionRateDocument(FIN_Payment payment) {
+    OBContext.setAdminMode();
+    try {
+      OBCriteria<ConversionRateDoc> obc = OBDal.getInstance().createCriteria(
+          ConversionRateDoc.class);
+      obc.add(Restrictions.eq(ConversionRateDoc.PROPERTY_CURRENCY, payment.getCurrency()));
+      obc.add(Restrictions.eq(ConversionRateDoc.PROPERTY_TOCURRENCY, payment.getAccount()
+          .getCurrency()));
+      obc.add(Restrictions.eq(ConversionRateDoc.PROPERTY_PAYMENT, payment));
+      return obc.list();
+    } finally {
+      OBContext.restorePreviousMode();
+    }
+  }
+
+  private ConversionRateDoc insertConversionRateDocument(FIN_Payment payment) {
+    OBContext.setAdminMode();
+    try {
+      ConversionRateDoc newConversionRateDoc = OBProvider.getInstance()
+          .get(ConversionRateDoc.class);
+      newConversionRateDoc.setOrganization(payment.getOrganization());
+      newConversionRateDoc.setCurrency(payment.getCurrency());
+      newConversionRateDoc.setToCurrency(payment.getAccount().getCurrency());
+      newConversionRateDoc.setRate(payment.getFinancialTransactionConvertRate());
+      newConversionRateDoc.setForeignAmount(payment.getFinancialTransactionAmount());
+      newConversionRateDoc.setPayment(payment);
+      OBDal.getInstance().save(newConversionRateDoc);
+      OBDal.getInstance().flush();
+      return newConversionRateDoc;
+    } finally {
+      OBContext.restorePreviousMode();
+    }
+  }
+
+  /**
+   * It calls the Transaction Process for the given transaction and action.
+   * 
+   * @param vars
+   *          VariablesSecureApp with the session data.
+   * @param conn
+   *          ConnectionProvider with the connection being used.
+   * @param strAction
+   *          String with the action of the process. {P, D, R}
+   * @param transaction
+   *          FIN_FinaccTransaction that needs to be processed.
+   * @return a OBError with the result message of the process.
+   * @throws Exception
+   */
+  private OBError processTransaction(VariablesSecureApp vars, ConnectionProvider conn,
+      String strAction, FIN_FinaccTransaction transaction) throws Exception {
+    ProcessBundle pb = new ProcessBundle("F68F2890E96D4D85A1DEF0274D105BCE", vars).init(conn);
+    HashMap<String, Object> parameters = new HashMap<String, Object>();
+    parameters.put("action", strAction);
+    parameters.put("Fin_FinAcc_Transaction_ID", transaction.getId());
+    pb.setParams(parameters);
+    OBError myMessage = null;
+    new FIN_TransactionProcess().execute(pb);
+    myMessage = (OBError) pb.getResult();
+    return myMessage;
+  }
+
 }
--- a/modules/org.openbravo.advpaymentmngt/src/org/openbravo/advpaymentmngt/process/FIN_TransactionProcess.java	Thu Oct 13 18:24:25 2011 +0200
+++ b/modules/org.openbravo.advpaymentmngt/src/org/openbravo/advpaymentmngt/process/FIN_TransactionProcess.java	Thu Oct 20 13:09:18 2011 +0200
@@ -18,14 +18,21 @@
  */
 package org.openbravo.advpaymentmngt.process;
 
+import java.util.List;
+
+import org.hibernate.criterion.Restrictions;
+import org.openbravo.advpaymentmngt.APRM_FinaccTransactionV;
 import org.openbravo.advpaymentmngt.dao.AdvPaymentMngtDao;
 import org.openbravo.advpaymentmngt.utility.FIN_Utility;
+import org.openbravo.base.provider.OBProvider;
 import org.openbravo.base.secureApp.VariablesSecureApp;
 import org.openbravo.dal.core.OBContext;
+import org.openbravo.dal.service.OBCriteria;
 import org.openbravo.dal.service.OBDal;
 import org.openbravo.database.ConnectionProvider;
 import org.openbravo.erpCommon.utility.OBError;
 import org.openbravo.erpCommon.utility.Utility;
+import org.openbravo.model.common.currency.ConversionRateDoc;
 import org.openbravo.model.financialmgmt.payment.FIN_FinaccTransaction;
 import org.openbravo.model.financialmgmt.payment.FIN_FinancialAccount;
 import org.openbravo.model.financialmgmt.payment.FIN_Payment;
@@ -75,6 +82,11 @@
             transaction.setStatus(transaction.getDepositAmount().compareTo(
                 transaction.getPaymentAmount()) > 0 ? "RDNC" : "PWNC");
           }
+          if (transaction.getForeignCurrency() != null
+              && !transaction.getCurrency().equals(transaction.getForeignCurrency())
+              && getConversionRateDocument(transaction).size() == 0) {
+            insertConversionRateDocument(transaction);
+          }
           OBDal.getInstance().save(financialAccount);
           OBDal.getInstance().save(transaction);
           OBDal.getInstance().flush();
@@ -100,6 +112,20 @@
             bundle.setResult(msg);
             return;
           }
+          // Remove conversion rate at document level for the given transaction
+          OBContext.setAdminMode();
+          try {
+            OBCriteria<ConversionRateDoc> obc = OBDal.getInstance().createCriteria(
+                ConversionRateDoc.class);
+            obc.add(Restrictions.eq(ConversionRateDoc.PROPERTY_FINANCIALACCOUNTTRANSACTION,
+                transaction));
+            for (ConversionRateDoc conversionRateDoc : obc.list()) {
+              OBDal.getInstance().remove(conversionRateDoc);
+            }
+            OBDal.getInstance().flush();
+          } finally {
+            OBContext.restorePreviousMode();
+          }
           transaction.setProcessed(false);
           final FIN_FinancialAccount financialAccount = transaction.getAccount();
           financialAccount.setCurrentBalance(financialAccount.getCurrentBalance()
@@ -137,4 +163,38 @@
     }
   }
 
+  private List<ConversionRateDoc> getConversionRateDocument(FIN_FinaccTransaction transaction) {
+    OBContext.setAdminMode();
+    try {
+      OBCriteria<ConversionRateDoc> obc = OBDal.getInstance().createCriteria(
+          ConversionRateDoc.class);
+      obc.add(Restrictions.eq(ConversionRateDoc.PROPERTY_CURRENCY, transaction.getForeignCurrency()));
+      obc.add(Restrictions.eq(ConversionRateDoc.PROPERTY_TOCURRENCY, transaction.getCurrency()));
+      obc.add(Restrictions.eq(ConversionRateDoc.PROPERTY_FINANCIALACCOUNTTRANSACTION, transaction));
+      return obc.list();
+    } finally {
+      OBContext.restorePreviousMode();
+    }
+  }
+
+  private ConversionRateDoc insertConversionRateDocument(FIN_FinaccTransaction transaction) {
+    OBContext.setAdminMode();
+    try {
+      ConversionRateDoc newConversionRateDoc = OBProvider.getInstance()
+          .get(ConversionRateDoc.class);
+      newConversionRateDoc.setOrganization(transaction.getOrganization());
+      newConversionRateDoc.setCurrency(transaction.getForeignCurrency());
+      newConversionRateDoc.setToCurrency(transaction.getCurrency());
+      newConversionRateDoc.setRate(transaction.getForeignConversionRate());
+      newConversionRateDoc.setForeignAmount(transaction.getForeignAmount());
+      newConversionRateDoc.setFinancialAccountTransaction(OBDal.getInstance().get(
+          APRM_FinaccTransactionV.class, transaction.getId()));
+      OBDal.getInstance().save(newConversionRateDoc);
+      OBDal.getInstance().flush();
+      return newConversionRateDoc;
+    } finally {
+      OBContext.restorePreviousMode();
+    }
+  }
+
 }
--- a/modules/org.openbravo.advpaymentmngt/src/org/openbravo/advpaymentmngt/utility/FIN_BankStatementImport.java	Thu Oct 13 18:24:25 2011 +0200
+++ b/modules/org.openbravo.advpaymentmngt/src/org/openbravo/advpaymentmngt/utility/FIN_BankStatementImport.java	Thu Oct 20 13:09:18 2011 +0200
@@ -218,19 +218,21 @@
   }
 
   BusinessPartner matchBusinessPartnerByName(String partnername) {
+    if (partnername == null || "".equals(partnername)) {
+      return null;
+    }
     final StringBuilder whereClause = new StringBuilder();
-
+    List<Object> parameters = new ArrayList<Object>();
     OBContext.setAdminMode();
     try {
-
       whereClause.append(" as bsl ");
-      whereClause.append(" where bsl." + FIN_BankStatementLine.PROPERTY_BPARTNERNAME + " = '"
-          + partnername + "'");
+      whereClause.append(" where bsl." + FIN_BankStatementLine.PROPERTY_BPARTNERNAME + " = ?");
       whereClause.append(" and bsl." + FIN_BankStatementLine.PROPERTY_BUSINESSPARTNER
           + " is not null");
       whereClause.append(" order by bsl." + FIN_BankStatementLine.PROPERTY_CREATIONDATE + " desc");
+      parameters.add(partnername);
       final OBQuery<FIN_BankStatementLine> bsl = OBDal.getInstance().createQuery(
-          FIN_BankStatementLine.class, whereClause.toString());
+          FIN_BankStatementLine.class, whereClause.toString(), parameters);
       List<FIN_BankStatementLine> matchedLines = bsl.list();
       if (matchedLines.size() == 0)
         return null;
@@ -243,15 +245,19 @@
   }
 
   BusinessPartner finBPByName(String partnername) {
+    if (partnername == null || "".equals(partnername)) {
+      return null;
+    }
     final StringBuilder whereClause = new StringBuilder();
+    List<Object> parameters = new ArrayList<Object>();
 
     OBContext.setAdminMode();
     try {
-
       whereClause.append(" as bp ");
-      whereClause.append(" where bp." + BusinessPartner.PROPERTY_NAME + " = '" + partnername + "'");
+      whereClause.append(" where bp." + BusinessPartner.PROPERTY_NAME + " = ?");
+      parameters.add(partnername);
       final OBQuery<BusinessPartner> bp = OBDal.getInstance().createQuery(BusinessPartner.class,
-          whereClause.toString());
+          whereClause.toString(), parameters);
       List<BusinessPartner> matchedBP = bp.list();
       if (matchedBP.size() == 0)
         return null;
--- a/modules/org.openbravo.advpaymentmngt/web/org.openbravo.advpaymentmngt/FIN_Utilities.js	Thu Oct 13 18:24:25 2011 +0200
+++ b/modules/org.openbravo.advpaymentmngt/web/org.openbravo.advpaymentmngt/FIN_Utilities.js	Thu Oct 20 13:09:18 2011 +0200
@@ -619,9 +619,12 @@
       if (!validateSelectedAmounts(chk.value, compare(selectedTotal, '<', actualPayment), action)) {
         return false;
       }
-    } else if ( !allowNotSelectingPendingPayment || compare(actualPayment, '==', "0")){
-      showJSMessage('APRM_JSNOTLINESELECTED');
-      return false;
+    } else {
+      if (!(typeof OB !== 'undefined' && OB.APRM && OB.APRM.HasGLItems) &&
+          (!allowNotSelectingPendingPayment || compare(actualPayment, '==', "0"))){
+        showJSMessage('APRM_JSNOTLINESELECTED');
+        return false;
+      }	
     }
   } else {
     var total = chk.length;
@@ -634,7 +637,8 @@
         }
       }
     }
-    if (!isAnyChecked &&
+    if (!(typeof OB !== 'undefined' && OB.APRM && OB.APRM.HasGLItems) &&
+        !isAnyChecked &&
         (!allowNotSelectingPendingPayment || compare(actualPayment, '==', "0"))
         ) {
       showJSMessage('APRM_JSNOTLINESELECTED');
--- a/modules/org.openbravo.base.weld/src-db/database/sourcedata/AD_MODULE.xml	Thu Oct 13 18:24:25 2011 +0200
+++ b/modules/org.openbravo.base.weld/src-db/database/sourcedata/AD_MODULE.xml	Thu Oct 20 13:09:18 2011 +0200
@@ -6,7 +6,7 @@
 <!--C70732EA90A14EC0916078B85CC33D2D-->  <AD_ORG_ID><![CDATA[0]]></AD_ORG_ID>
 <!--C70732EA90A14EC0916078B85CC33D2D-->  <ISACTIVE><![CDATA[Y]]></ISACTIVE>
 <!--C70732EA90A14EC0916078B85CC33D2D-->  <NAME><![CDATA[JBoss Weld]]></NAME>
-<!--C70732EA90A14EC0916078B85CC33D2D-->  <VERSION><![CDATA[1.1.13698]]></VERSION>
+<!--C70732EA90A14EC0916078B85CC33D2D-->  <VERSION><![CDATA[1.1.13966]]></VERSION>
 <!--C70732EA90A14EC0916078B85CC33D2D-->  <DESCRIPTION><![CDATA[JBoss Weld]]></DESCRIPTION>
 <!--C70732EA90A14EC0916078B85CC33D2D-->  <HELP><![CDATA[Provides the JBoss Weld framework: Java Contexts and Dependency Injection for the Java EE platform (CDI). For more information see http://seamframework.org/Weld]]></HELP>
 <!--C70732EA90A14EC0916078B85CC33D2D-->  <URL><![CDATA[http://forge.openbravo.com/projects/weld]]></URL>
@@ -22,7 +22,7 @@
 <!--C70732EA90A14EC0916078B85CC33D2D-->  <ISTRANSLATIONMODULE><![CDATA[N]]></ISTRANSLATIONMODULE>
 <!--C70732EA90A14EC0916078B85CC33D2D-->  <HASREFERENCEDATA><![CDATA[N]]></HASREFERENCEDATA>
 <!--C70732EA90A14EC0916078B85CC33D2D-->  <UPDATEINFO><![CDATA[Bug fixing.]]></UPDATEINFO>
-<!--C70732EA90A14EC0916078B85CC33D2D-->  <VERSION_LABEL><![CDATA[MP3]]></VERSION_LABEL>
+<!--C70732EA90A14EC0916078B85CC33D2D-->  <VERSION_LABEL><![CDATA[MP4]]></VERSION_LABEL>
 <!--C70732EA90A14EC0916078B85CC33D2D-->  <ISCOMMERCIAL><![CDATA[N]]></ISCOMMERCIAL>
 <!--C70732EA90A14EC0916078B85CC33D2D--></AD_MODULE>
 
--- a/modules/org.openbravo.base.weld/src-db/database/sourcedata/AD_MODULE_DEPENDENCY.xml	Thu Oct 13 18:24:25 2011 +0200
+++ b/modules/org.openbravo.base.weld/src-db/database/sourcedata/AD_MODULE_DEPENDENCY.xml	Thu Oct 20 13:09:18 2011 +0200
@@ -7,7 +7,7 @@
 <!--8BDE81545C1A43EAAC4BA3C5ED754DC8-->  <ISACTIVE><![CDATA[Y]]></ISACTIVE>
 <!--8BDE81545C1A43EAAC4BA3C5ED754DC8-->  <AD_MODULE_ID><![CDATA[C70732EA90A14EC0916078B85CC33D2D]]></AD_MODULE_ID>
 <!--8BDE81545C1A43EAAC4BA3C5ED754DC8-->  <AD_DEPENDENT_MODULE_ID><![CDATA[0]]></AD_DEPENDENT_MODULE_ID>
-<!--8BDE81545C1A43EAAC4BA3C5ED754DC8-->  <STARTVERSION><![CDATA[3.0.13698]]></STARTVERSION>
+<!--8BDE81545C1A43EAAC4BA3C5ED754DC8-->  <STARTVERSION><![CDATA[3.0.13966]]></STARTVERSION>
 <!--8BDE81545C1A43EAAC4BA3C5ED754DC8-->  <ISINCLUDED><![CDATA[N]]></ISINCLUDED>
 <!--8BDE81545C1A43EAAC4BA3C5ED754DC8-->  <DEPENDANT_MODULE_NAME><![CDATA[Core]]></DEPENDANT_MODULE_NAME>
 <!--8BDE81545C1A43EAAC4BA3C5ED754DC8-->  <DEPENDENCY_ENFORCEMENT><![CDATA[MAJOR]]></DEPENDENCY_ENFORCEMENT>
--- a/modules/org.openbravo.client.application/src-db/database/model/tables/OBUIAPP_UIPERSONALIZATION.xml	Thu Oct 13 18:24:25 2011 +0200
+++ b/modules/org.openbravo.client.application/src-db/database/model/tables/OBUIAPP_UIPERSONALIZATION.xml	Thu Oct 20 13:09:18 2011 +0200
@@ -33,6 +33,10 @@
         <default/>
         <onCreateDefault/>
       </column>
+      <column name="TYPE" primaryKey="false" required="false" type="VARCHAR" size="60" autoIncrement="false">
+        <default/>
+        <onCreateDefault/>
+      </column>
       <column name="DESCRIPTION" primaryKey="false" required="false" type="NVARCHAR" size="255" autoIncrement="false">
         <default/>
         <onCreateDefault/>
@@ -41,6 +45,10 @@
         <default/>
         <onCreateDefault/>
       </column>
+      <column name="AD_WINDOW_ID" primaryKey="false" required="false" type="VARCHAR" size="32" autoIncrement="false">
+        <default/>
+        <onCreateDefault/>
+      </column>
       <column name="AD_USER_ID" primaryKey="false" required="false" type="VARCHAR" size="32" autoIncrement="false">
         <default/>
         <onCreateDefault/>
@@ -89,6 +97,9 @@
       <foreign-key foreignTable="AD_USER" name="OBUIAPP_UIPERS_USER">
         <reference local="AD_USER_ID" foreign="AD_USER_ID"/>
       </foreign-key>
+      <foreign-key foreignTable="AD_WINDOW" name="OBUIAPP_UIPERS_WIN" onDelete="cascade">
+        <reference local="AD_WINDOW_ID" foreign="AD_WINDOW_ID"/>
+      </foreign-key>
       <check name="OBUIAPP_UIPERSO_ISACTIVE_CHECK"><![CDATA[ISACTIVE IN ('Y', 'N')]]></check>
     </table>
   </database>
--- a/modules/org.openbravo.client.application/src-db/database/model/triggers/OBUIAPP_UIPERS_MOD_TRG.xml	Thu Oct 13 18:24:25 2011 +0200
+++ b/modules/org.openbravo.client.application/src-db/database/model/triggers/OBUIAPP_UIPERS_MOD_TRG.xml	Thu Oct 20 13:09:18 2011 +0200
@@ -69,6 +69,8 @@
         COALESCE(:NEW.AD_ORG_ID, '.') != COALESCE(:old.AD_ORG_ID, '.') OR
         COALESCE(:NEW.ISACTIVE, '.') != COALESCE(:old.ISACTIVE, '.') OR
         COALESCE(:NEW.AD_MODULE_ID, '.') != COALESCE(:old.AD_MODULE_ID, '.') OR
+        coalesce(:new.AD_WINDOW_ID, '.') != coalesce(:old.AD_WINDOW_ID, '.') or   
+        coalesce(:new.TYPE, '.') != coalesce(:old.TYPE, '.') or   
         coalesce(:new.AD_TAB_ID, '.') != coalesce(:old.AD_TAB_ID, '.') or   
         coalesce(:new.AD_USER_ID, '.') != coalesce(:old.AD_USER_ID, '.') or   
         coalesce(:new.DESCRIPTION, '.') != coalesce(:old.DESCRIPTION, '.') or   
--- a/modules/org.openbravo.client.application/src-db/database/sourcedata/AD_COLUMN.xml	Thu Oct 13 18:24:25 2011 +0200
+++ b/modules/org.openbravo.client.application/src-db/database/sourcedata/AD_COLUMN.xml	Thu Oct 20 13:09:18 2011 +0200
@@ -28,7 +28,7 @@
 <!--0060401C958644D4AA38E9226FBEE232-->  <ISDESENCRYPTABLE><![CDATA[N]]></ISDESENCRYPTABLE>
 <!--0060401C958644D4AA38E9226FBEE232-->  <DEVELOPMENTSTATUS><![CDATA[RE]]></DEVELOPMENTSTATUS>
 <!--0060401C958644D4AA38E9226FBEE232-->  <AD_MODULE_ID><![CDATA[9BA0836A3CD74EE4AB48753A47211BCC]]></AD_MODULE_ID>
-<!--0060401C958644D4AA38E9226FBEE232-->  <POSITION><![CDATA[14]]></POSITION>
+<!--0060401C958644D4AA38E9226FBEE232-->  <POSITION><![CDATA[16]]></POSITION>
 <!--0060401C958644D4AA38E9226FBEE232-->  <ISTRANSIENT><![CDATA[N]]></ISTRANSIENT>
 <!--0060401C958644D4AA38E9226FBEE232-->  <ISAUTOSAVE><![CDATA[Y]]></ISAUTOSAVE>
 <!--0060401C958644D4AA38E9226FBEE232-->  <VALIDATEONNEW><![CDATA[Y]]></VALIDATEONNEW>
@@ -1577,7 +1577,7 @@
 <!--7EA5AB885F84493CA2E998594BBC09C2-->  <ISDESENCRYPTABLE><![CDATA[N]]></ISDESENCRYPTABLE>
 <!--7EA5AB885F84493CA2E998594BBC09C2-->  <DEVELOPMENTSTATUS><![CDATA[RE]]></DEVELOPMENTSTATUS>
 <!--7EA5AB885F84493CA2E998594BBC09C2-->  <AD_MODULE_ID><![CDATA[9BA0836A3CD74EE4AB48753A47211BCC]]></AD_MODULE_ID>
-<!--7EA5AB885F84493CA2E998594BBC09C2-->  <POSITION><![CDATA[9]]></POSITION>
+<!--7EA5AB885F84493CA2E998594BBC09C2-->  <POSITION><![CDATA[10]]></POSITION>
 <!--7EA5AB885F84493CA2E998594BBC09C2-->  <ISTRANSIENT><![CDATA[N]]></ISTRANSIENT>
 <!--7EA5AB885F84493CA2E998594BBC09C2-->  <ISAUTOSAVE><![CDATA[Y]]></ISAUTOSAVE>
 <!--7EA5AB885F84493CA2E998594BBC09C2-->  <VALIDATEONNEW><![CDATA[Y]]></VALIDATEONNEW>
@@ -3619,7 +3619,7 @@
 <!--ABEE9EA6CC8344789ADA2ABC532DA2FF-->  <ISDESENCRYPTABLE><![CDATA[N]]></ISDESENCRYPTABLE>
 <!--ABEE9EA6CC8344789ADA2ABC532DA2FF-->  <DEVELOPMENTSTATUS><![CDATA[RE]]></DEVELOPMENTSTATUS>
 <!--ABEE9EA6CC8344789ADA2ABC532DA2FF-->  <AD_MODULE_ID><![CDATA[9BA0836A3CD74EE4AB48753A47211BCC]]></AD_MODULE_ID>
-<!--ABEE9EA6CC8344789ADA2ABC532DA2FF-->  <POSITION><![CDATA[16]]></POSITION>
+<!--ABEE9EA6CC8344789ADA2ABC532DA2FF-->  <POSITION><![CDATA[18]]></POSITION>
 <!--ABEE9EA6CC8344789ADA2ABC532DA2FF-->  <ISTRANSIENT><![CDATA[N]]></ISTRANSIENT>
 <!--ABEE9EA6CC8344789ADA2ABC532DA2FF-->  <ISAUTOSAVE><![CDATA[Y]]></ISAUTOSAVE>
 <!--ABEE9EA6CC8344789ADA2ABC532DA2FF-->  <VALIDATEONNEW><![CDATA[Y]]></VALIDATEONNEW>
@@ -3820,7 +3820,7 @@
 <!--B4FD9EC573F94B9096FF3A41284F338F-->  <ISDESENCRYPTABLE><![CDATA[N]]></ISDESENCRYPTABLE>
 <!--B4FD9EC573F94B9096FF3A41284F338F-->  <DEVELOPMENTSTATUS><![CDATA[RE]]></DEVELOPMENTSTATUS>
 <!--B4FD9EC573F94B9096FF3A41284F338F-->  <AD_MODULE_ID><![CDATA[9BA0836A3CD74EE4AB48753A47211BCC]]></AD_MODULE_ID>
-<!--B4FD9EC573F94B9096FF3A41284F338F-->  <POSITION><![CDATA[11]]></POSITION>
+<!--B4FD9EC573F94B9096FF3A41284F338F-->  <POSITION><![CDATA[13]]></POSITION>
 <!--B4FD9EC573F94B9096FF3A41284F338F-->  <ISTRANSIENT><![CDATA[N]]></ISTRANSIENT>
 <!--B4FD9EC573F94B9096FF3A41284F338F-->  <ISAUTOSAVE><![CDATA[Y]]></ISAUTOSAVE>
 <!--B4FD9EC573F94B9096FF3A41284F338F-->  <VALIDATEONNEW><![CDATA[Y]]></VALIDATEONNEW>
@@ -3887,7 +3887,7 @@
 <!--BB39498850B942A1B29086C89163F014-->  <ISDESENCRYPTABLE><![CDATA[N]]></ISDESENCRYPTABLE>
 <!--BB39498850B942A1B29086C89163F014-->  <DEVELOPMENTSTATUS><![CDATA[RE]]></DEVELOPMENTSTATUS>
 <!--BB39498850B942A1B29086C89163F014-->  <AD_MODULE_ID><![CDATA[9BA0836A3CD74EE4AB48753A47211BCC]]></AD_MODULE_ID>
-<!--BB39498850B942A1B29086C89163F014-->  <POSITION><![CDATA[15]]></POSITION>
+<!--BB39498850B942A1B29086C89163F014-->  <POSITION><![CDATA[17]]></POSITION>
 <!--BB39498850B942A1B29086C89163F014-->  <ISTRANSIENT><![CDATA[N]]></ISTRANSIENT>
 <!--BB39498850B942A1B29086C89163F014-->  <ISAUTOSAVE><![CDATA[Y]]></ISAUTOSAVE>
 <!--BB39498850B942A1B29086C89163F014-->  <VALIDATEONNEW><![CDATA[Y]]></VALIDATEONNEW>
@@ -3921,7 +3921,7 @@
 <!--BBA0362A5E424CDDBFA2A008A942F218-->  <ISDESENCRYPTABLE><![CDATA[N]]></ISDESENCRYPTABLE>
 <!--BBA0362A5E424CDDBFA2A008A942F218-->  <DEVELOPMENTSTATUS><![CDATA[RE]]></DEVELOPMENTSTATUS>
 <!--BBA0362A5E424CDDBFA2A008A942F218-->  <AD_MODULE_ID><![CDATA[9BA0836A3CD74EE4AB48753A47211BCC]]></AD_MODULE_ID>
-<!--BBA0362A5E424CDDBFA2A008A942F218-->  <POSITION><![CDATA[13]]></POSITION>
+<!--BBA0362A5E424CDDBFA2A008A942F218-->  <POSITION><![CDATA[15]]></POSITION>
 <!--BBA0362A5E424CDDBFA2A008A942F218-->  <ISTRANSIENT><![CDATA[N]]></ISTRANSIENT>
 <!--BBA0362A5E424CDDBFA2A008A942F218-->  <ISAUTOSAVE><![CDATA[Y]]></ISAUTOSAVE>
 <!--BBA0362A5E424CDDBFA2A008A942F218-->  <VALIDATEONNEW><![CDATA[Y]]></VALIDATEONNEW>
@@ -4229,6 +4229,40 @@
 <!--D9EDF11E8E264BD0A1A0D8F0C6986ED1-->  <VALIDATEONNEW><![CDATA[Y]]></VALIDATEONNEW>
 <!--D9EDF11E8E264BD0A1A0D8F0C6986ED1--></AD_COLUMN>
 
+<!--DCCA15863CFA47FE86AC680C44A8864E--><AD_COLUMN>
+<!--DCCA15863CFA47FE86AC680C44A8864E-->  <AD_COLUMN_ID><![CDATA[DCCA15863CFA47FE86AC680C44A8864E]]></AD_COLUMN_ID>
+<!--DCCA15863CFA47FE86AC680C44A8864E-->  <AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID>
+<!--DCCA15863CFA47FE86AC680C44A8864E-->  <AD_ORG_ID><![CDATA[0]]></AD_ORG_ID>
+<!--DCCA15863CFA47FE86AC680C44A8864E-->  <ISACTIVE><![CDATA[Y]]></ISACTIVE>
+<!--DCCA15863CFA47FE86AC680C44A8864E-->  <NAME><![CDATA[Type]]></NAME>
+<!--DCCA15863CFA47FE86AC680C44A8864E-->  <DESCRIPTION><![CDATA[A distinct item characteristic used for processes and sometimes grouped within a category.]]></DESCRIPTION>
+<!--DCCA15863CFA47FE86AC680C44A8864E-->  <HELP><![CDATA[The Type indicates the type of validation that will occur.  This can be SQL, Java Script or Java Language.]]></HELP>
+<!--DCCA15863CFA47FE86AC680C44A8864E-->  <COLUMNNAME><![CDATA[Type]]></COLUMNNAME>
+<!--DCCA15863CFA47FE86AC680C44A8864E-->  <AD_TABLE_ID><![CDATA[FF8081813157AED2013157B1F75F0007]]></AD_TABLE_ID>
+<!--DCCA15863CFA47FE86AC680C44A8864E-->  <AD_REFERENCE_ID><![CDATA[17]]></AD_REFERENCE_ID>
+<!--DCCA15863CFA47FE86AC680C44A8864E-->  <AD_REFERENCE_VALUE_ID><![CDATA[FF8081813201F2DE013201F5628C0003]]></AD_REFERENCE_VALUE_ID>
+<!--DCCA15863CFA47FE86AC680C44A8864E-->  <FIELDLENGTH><![CDATA[60]]></FIELDLENGTH>
+<!--DCCA15863CFA47FE86AC680C44A8864E-->  <ISKEY><![CDATA[N]]></ISKEY>
+<!--DCCA15863CFA47FE86AC680C44A8864E-->  <ISPARENT><![CDATA[N]]></ISPARENT>
+<!--DCCA15863CFA47FE86AC680C44A8864E-->  <ISMANDATORY><![CDATA[N]]></ISMANDATORY>
+<!--DCCA15863CFA47FE86AC680C44A8864E-->  <ISUPDATEABLE><![CDATA[Y]]></ISUPDATEABLE>
+<!--DCCA15863CFA47FE86AC680C44A8864E-->  <ISIDENTIFIER><![CDATA[N]]></ISIDENTIFIER>
+<!--DCCA15863CFA47FE86AC680C44A8864E-->  <SEQNO><![CDATA[180]]></SEQNO>
+<!--DCCA15863CFA47FE86AC680C44A8864E-->  <ISTRANSLATED><![CDATA[N]]></ISTRANSLATED>
+<!--DCCA15863CFA47FE86AC680C44A8864E-->  <ISENCRYPTED><![CDATA[N]]></ISENCRYPTED>
+<!--DCCA15863CFA47FE86AC680C44A8864E-->  <ISSELECTIONCOLUMN><![CDATA[N]]></ISSELECTIONCOLUMN>
+<!--DCCA15863CFA47FE86AC680C44A8864E-->  <AD_ELEMENT_ID><![CDATA[600]]></AD_ELEMENT_ID>
+<!--DCCA15863CFA47FE86AC680C44A8864E-->  <ISSESSIONATTR><![CDATA[N]]></ISSESSIONATTR>
+<!--DCCA15863CFA47FE86AC680C44A8864E-->  <ISSECONDARYKEY><![CDATA[N]]></ISSECONDARYKEY>
+<!--DCCA15863CFA47FE86AC680C44A8864E-->  <ISDESENCRYPTABLE><![CDATA[N]]></ISDESENCRYPTABLE>
+<!--DCCA15863CFA47FE86AC680C44A8864E-->  <DEVELOPMENTSTATUS><![CDATA[RE]]></DEVELOPMENTSTATUS>
+<!--DCCA15863CFA47FE86AC680C44A8864E-->  <AD_MODULE_ID><![CDATA[9BA0836A3CD74EE4AB48753A47211BCC]]></AD_MODULE_ID>
+<!--DCCA15863CFA47FE86AC680C44A8864E-->  <POSITION><![CDATA[9]]></POSITION>
+<!--DCCA15863CFA47FE86AC680C44A8864E-->  <ISTRANSIENT><![CDATA[N]]></ISTRANSIENT>
+<!--DCCA15863CFA47FE86AC680C44A8864E-->  <ISAUTOSAVE><![CDATA[Y]]></ISAUTOSAVE>
+<!--DCCA15863CFA47FE86AC680C44A8864E-->  <VALIDATEONNEW><![CDATA[Y]]></VALIDATEONNEW>
+<!--DCCA15863CFA47FE86AC680C44A8864E--></AD_COLUMN>
+
 <!--DF72F3EFC6074F2E9A7CCD70D60CE7AA--><AD_COLUMN>
 <!--DF72F3EFC6074F2E9A7CCD70D60CE7AA-->  <AD_COLUMN_ID><![CDATA[DF72F3EFC6074F2E9A7CCD70D60CE7AA]]></AD_COLUMN_ID>
 <!--DF72F3EFC6074F2E9A7CCD70D60CE7AA-->  <AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID>
@@ -4629,12 +4663,45 @@
 <!--F7DE0BA73FA64A68B898495072729D12-->  <ISDESENCRYPTABLE><![CDATA[N]]></ISDESENCRYPTABLE>
 <!--F7DE0BA73FA64A68B898495072729D12-->  <DEVELOPMENTSTATUS><![CDATA[RE]]></DEVELOPMENTSTATUS>
 <!--F7DE0BA73FA64A68B898495072729D12-->  <AD_MODULE_ID><![CDATA[9BA0836A3CD74EE4AB48753A47211BCC]]></AD_MODULE_ID>
-<!--F7DE0BA73FA64A68B898495072729D12-->  <POSITION><![CDATA[10]]></POSITION>
+<!--F7DE0BA73FA64A68B898495072729D12-->  <POSITION><![CDATA[11]]></POSITION>
 <!--F7DE0BA73FA64A68B898495072729D12-->  <ISTRANSIENT><![CDATA[N]]></ISTRANSIENT>
 <!--F7DE0BA73FA64A68B898495072729D12-->  <ISAUTOSAVE><![CDATA[Y]]></ISAUTOSAVE>
 <!--F7DE0BA73FA64A68B898495072729D12-->  <VALIDATEONNEW><![CDATA[Y]]></VALIDATEONNEW>
 <!--F7DE0BA73FA64A68B898495072729D12--></AD_COLUMN>
 
+<!--FB975B710F5544CC8BC99F981F63C1CD--><AD_COLUMN>
+<!--FB975B710F5544CC8BC99F981F63C1CD-->  <AD_COLUMN_ID><![CDATA[FB975B710F5544CC8BC99F981F63C1CD]]></AD_COLUMN_ID>
+<!--FB975B710F5544CC8BC99F981F63C1CD-->  <AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID>
+<!--FB975B710F5544CC8BC99F981F63C1CD-->  <AD_ORG_ID><![CDATA[0]]></AD_ORG_ID>
+<!--FB975B710F5544CC8BC99F981F63C1CD-->  <ISACTIVE><![CDATA[Y]]></ISACTIVE>
+<!--FB975B710F5544CC8BC99F981F63C1CD-->  <NAME><![CDATA[Window]]></NAME>
+<!--FB975B710F5544CC8BC99F981F63C1CD-->  <DESCRIPTION><![CDATA[A work area which can be used to create, view, edit, and process a record.]]></DESCRIPTION>
+<!--FB975B710F5544CC8BC99F981F63C1CD-->  <HELP><![CDATA[The Window field identifies a unique Window in the system.]]></HELP>
+<!--FB975B710F5544CC8BC99F981F63C1CD-->  <COLUMNNAME><![CDATA[AD_Window_ID]]></COLUMNNAME>
+<!--FB975B710F5544CC8BC99F981F63C1CD-->  <AD_TABLE_ID><![CDATA[FF8081813157AED2013157B1F75F0007]]></AD_TABLE_ID>
+<!--FB975B710F5544CC8BC99F981F63C1CD-->  <AD_REFERENCE_ID><![CDATA[19]]></AD_REFERENCE_ID>
+<!--FB975B710F5544CC8BC99F981F63C1CD-->  <FIELDLENGTH><![CDATA[32]]></FIELDLENGTH>
+<!--FB975B710F5544CC8BC99F981F63C1CD-->  <ISKEY><![CDATA[N]]></ISKEY>
+<!--FB975B710F5544CC8BC99F981F63C1CD-->  <ISPARENT><![CDATA[N]]></ISPARENT>
+<!--FB975B710F5544CC8BC99F981F63C1CD-->  <ISMANDATORY><![CDATA[Y]]></ISMANDATORY>
+<!--FB975B710F5544CC8BC99F981F63C1CD-->  <ISUPDATEABLE><![CDATA[Y]]></ISUPDATEABLE>
+<!--FB975B710F5544CC8BC99F981F63C1CD-->  <ISIDENTIFIER><![CDATA[N]]></ISIDENTIFIER>
+<!--FB975B710F5544CC8BC99F981F63C1CD-->  <SEQNO><![CDATA[190]]></SEQNO>
+<!--FB975B710F5544CC8BC99F981F63C1CD-->  <ISTRANSLATED><![CDATA[N]]></ISTRANSLATED>
+<!--FB975B710F5544CC8BC99F981F63C1CD-->  <ISENCRYPTED><![CDATA[N]]></ISENCRYPTED>
+<!--FB975B710F5544CC8BC99F981F63C1CD-->  <ISSELECTIONCOLUMN><![CDATA[N]]></ISSELECTIONCOLUMN>
+<!--FB975B710F5544CC8BC99F981F63C1CD-->  <AD_ELEMENT_ID><![CDATA[143]]></AD_ELEMENT_ID>
+<!--FB975B710F5544CC8BC99F981F63C1CD-->  <ISSESSIONATTR><![CDATA[N]]></ISSESSIONATTR>
+<!--FB975B710F5544CC8BC99F981F63C1CD-->  <ISSECONDARYKEY><![CDATA[N]]></ISSECONDARYKEY>
+<!--FB975B710F5544CC8BC99F981F63C1CD-->  <ISDESENCRYPTABLE><![CDATA[N]]></ISDESENCRYPTABLE>
+<!--FB975B710F5544CC8BC99F981F63C1CD-->  <DEVELOPMENTSTATUS><![CDATA[RE]]></DEVELOPMENTSTATUS>
+<!--FB975B710F5544CC8BC99F981F63C1CD-->  <AD_MODULE_ID><![CDATA[9BA0836A3CD74EE4AB48753A47211BCC]]></AD_MODULE_ID>
+<!--FB975B710F5544CC8BC99F981F63C1CD-->  <POSITION><![CDATA[12]]></POSITION>
+<!--FB975B710F5544CC8BC99F981F63C1CD-->  <ISTRANSIENT><![CDATA[N]]></ISTRANSIENT>
+<!--FB975B710F5544CC8BC99F981F63C1CD-->  <ISAUTOSAVE><![CDATA[Y]]></ISAUTOSAVE>
+<!--FB975B710F5544CC8BC99F981F63C1CD-->  <VALIDATEONNEW><![CDATA[Y]]></VALIDATEONNEW>
+<!--FB975B710F5544CC8BC99F981F63C1CD--></AD_COLUMN>
+
 <!--FF1D7BA688EF492D9D87FA2C728A92D1--><AD_COLUMN>
 <!--FF1D7BA688EF492D9D87FA2C728A92D1-->  <AD_COLUMN_ID><![CDATA[FF1D7BA688EF492D9D87FA2C728A92D1]]></AD_COLUMN_ID>
 <!--FF1D7BA688EF492D9D87FA2C728A92D1-->  <AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID>
@@ -4734,7 +4801,7 @@
 <!--FF8081813157AED2013157B8620F001C-->  <ISDESENCRYPTABLE><![CDATA[N]]></ISDESENCRYPTABLE>
 <!--FF8081813157AED2013157B8620F001C-->  <DEVELOPMENTSTATUS><![CDATA[RE]]></DEVELOPMENTSTATUS>
 <!--FF8081813157AED2013157B8620F001C-->  <AD_MODULE_ID><![CDATA[9BA0836A3CD74EE4AB48753A47211BCC]]></AD_MODULE_ID>
-<!--FF8081813157AED2013157B8620F001C-->  <POSITION><![CDATA[12]]></POSITION>
+<!--FF8081813157AED2013157B8620F001C-->  <POSITION><![CDATA[14]]></POSITION>
 <!--FF8081813157AED2013157B8620F001C-->  <ISTRANSIENT><![CDATA[N]]></ISTRANSIENT>
 <!--FF8081813157AED2013157B8620F001C-->  <ISAUTOSAVE><![CDATA[Y]]></ISAUTOSAVE>
 <!--FF8081813157AED2013157B8620F001C-->  <VALIDATEONNEW><![CDATA[Y]]></VALIDATEONNEW>
--- a/modules/org.openbravo.client.application/src-db/database/sourcedata/AD_FIELD.xml	Thu Oct 13 18:24:25 2011 +0200
+++ b/modules/org.openbravo.client.application/src-db/database/sourcedata/AD_FIELD.xml	Thu Oct 20 13:09:18 2011 +0200
@@ -41,7 +41,7 @@
 <!--05091C569B5B403DB8DE04889ACFC4A8-->  <ISDISPLAYED><![CDATA[Y]]></ISDISPLAYED>
 <!--05091C569B5B403DB8DE04889ACFC4A8-->  <DISPLAYLENGTH><![CDATA[20]]></DISPLAYLENGTH>
 <!--05091C569B5B403DB8DE04889ACFC4A8-->  <ISREADONLY><![CDATA[N]]></ISREADONLY>
-<!--05091C569B5B403DB8DE04889ACFC4A8-->  <SEQNO><![CDATA[80]]></SEQNO>
+<!--05091C569B5B403DB8DE04889ACFC4A8-->  <SEQNO><![CDATA[90]]></SEQNO>
 <!--05091C569B5B403DB8DE04889ACFC4A8-->  <SORTNO><![CDATA[1]]></SORTNO>
 <!--05091C569B5B403DB8DE04889ACFC4A8-->  <ISSAMELINE><![CDATA[N]]></ISSAMELINE>
 <!--05091C569B5B403DB8DE04889ACFC4A8-->  <ISFIELDONLY><![CDATA[N]]></ISFIELDONLY>
@@ -49,7 +49,7 @@
 <!--05091C569B5B403DB8DE04889ACFC4A8-->  <SHOWINRELATION><![CDATA[Y]]></SHOWINRELATION>
 <!--05091C569B5B403DB8DE04889ACFC4A8-->  <ISFIRSTFOCUSEDFIELD><![CDATA[N]]></ISFIRSTFOCUSEDFIELD>
 <!--05091C569B5B403DB8DE04889ACFC4A8-->  <AD_MODULE_ID><![CDATA[9BA0836A3CD74EE4AB48753A47211BCC]]></AD_MODULE_ID>
-<!--05091C569B5B403DB8DE04889ACFC4A8-->  <GRID_SEQNO><![CDATA[110]]></GRID_SEQNO>
+<!--05091C569B5B403DB8DE04889ACFC4A8-->  <GRID_SEQNO><![CDATA[130]]></GRID_SEQNO>
 <!--05091C569B5B403DB8DE04889ACFC4A8-->  <STARTINODDCOLUMN><![CDATA[N]]></STARTINODDCOLUMN>
 <!--05091C569B5B403DB8DE04889ACFC4A8-->  <STARTNEWLINE><![CDATA[Y]]></STARTNEWLINE>
 <!--05091C569B5B403DB8DE04889ACFC4A8-->  <ISSHOWNINSTATUSBAR><![CDATA[N]]></ISSHOWNINSTATUSBAR>
@@ -135,6 +135,33 @@
 <!--05A90B8FA5104697BFBCB14D3C49C41A-->  <ISSHOWNINSTATUSBAR><![CDATA[N]]></ISSHOWNINSTATUSBAR>
 <!--05A90B8FA5104697BFBCB14D3C49C41A--></AD_FIELD>
 
+<!--106031CC88C0465CBAB20EDE1B596D50--><AD_FIELD>
+<!--106031CC88C0465CBAB20EDE1B596D50-->  <AD_FIELD_ID><![CDATA[106031CC88C0465CBAB20EDE1B596D50]]></AD_FIELD_ID>
+<!--106031CC88C0465CBAB20EDE1B596D50-->  <AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID>
+<!--106031CC88C0465CBAB20EDE1B596D50-->  <AD_ORG_ID><![CDATA[0]]></AD_ORG_ID>
+<!--106031CC88C0465CBAB20EDE1B596D50-->  <ISACTIVE><![CDATA[Y]]></ISACTIVE>
+<!--106031CC88C0465CBAB20EDE1B596D50-->  <NAME><![CDATA[Type]]></NAME>
+<!--106031CC88C0465CBAB20EDE1B596D50-->  <DESCRIPTION><![CDATA[A distinct item characteristic used for processes and sometimes grouped within a category.]]></DESCRIPTION>
+<!--106031CC88C0465CBAB20EDE1B596D50-->  <HELP><![CDATA[The Type indicates the type of validation that will occur.  This can be SQL, Java Script or Java Language.]]></HELP>
+<!--106031CC88C0465CBAB20EDE1B596D50-->  <ISCENTRALLYMAINTAINED><![CDATA[Y]]></ISCENTRALLYMAINTAINED>
+<!--106031CC88C0465CBAB20EDE1B596D50-->  <AD_TAB_ID><![CDATA[FF8081813157AED2013157BF6D810023]]></AD_TAB_ID>
+<!--106031CC88C0465CBAB20EDE1B596D50-->  <AD_COLUMN_ID><![CDATA[DCCA15863CFA47FE86AC680C44A8864E]]></AD_COLUMN_ID>
+<!--106031CC88C0465CBAB20EDE1B596D50-->  <ISDISPLAYED><![CDATA[Y]]></ISDISPLAYED>
+<!--106031CC88C0465CBAB20EDE1B596D50-->  <DISPLAYLENGTH><![CDATA[60]]></DISPLAYLENGTH>
+<!--106031CC88C0465CBAB20EDE1B596D50-->  <ISREADONLY><![CDATA[N]]></ISREADONLY>
+<!--106031CC88C0465CBAB20EDE1B596D50-->  <SEQNO><![CDATA[50]]></SEQNO>
+<!--106031CC88C0465CBAB20EDE1B596D50-->  <ISSAMELINE><![CDATA[N]]></ISSAMELINE>
+<!--106031CC88C0465CBAB20EDE1B596D50-->  <ISFIELDONLY><![CDATA[N]]></ISFIELDONLY>
+<!--106031CC88C0465CBAB20EDE1B596D50-->  <ISENCRYPTED><![CDATA[N]]></ISENCRYPTED>
+<!--106031CC88C0465CBAB20EDE1B596D50-->  <SHOWINRELATION><![CDATA[Y]]></SHOWINRELATION>
+<!--106031CC88C0465CBAB20EDE1B596D50-->  <ISFIRSTFOCUSEDFIELD><![CDATA[N]]></ISFIRSTFOCUSEDFIELD>
+<!--106031CC88C0465CBAB20EDE1B596D50-->  <AD_MODULE_ID><![CDATA[9BA0836A3CD74EE4AB48753A47211BCC]]></AD_MODULE_ID>
+<!--106031CC88C0465CBAB20EDE1B596D50-->  <GRID_SEQNO><![CDATA[60]]></GRID_SEQNO>
+<!--106031CC88C0465CBAB20EDE1B596D50-->  <STARTINODDCOLUMN><![CDATA[N]]></STARTINODDCOLUMN>
+<!--106031CC88C0465CBAB20EDE1B596D50-->  <STARTNEWLINE><![CDATA[N]]></STARTNEWLINE>
+<!--106031CC88C0465CBAB20EDE1B596D50-->  <ISSHOWNINSTATUSBAR><![CDATA[N]]></ISSHOWNINSTATUSBAR>
+<!--106031CC88C0465CBAB20EDE1B596D50--></AD_FIELD>
+
 <!--13E58370460A4082AF6173313BA113C8--><AD_FIELD>
 <!--13E58370460A4082AF6173313BA113C8-->  <AD_FIELD_ID><![CDATA[13E58370460A4082AF6173313BA113C8]]></AD_FIELD_ID>
 <!--13E58370460A4082AF6173313BA113C8-->  <AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID>
@@ -176,7 +203,7 @@
 <!--1C35877D26B1432C9867E4F5EAEE17F8-->  <ISDISPLAYED><![CDATA[Y]]></ISDISPLAYED>
 <!--1C35877D26B1432C9867E4F5EAEE17F8-->  <DISPLAYLENGTH><![CDATA[32]]></DISPLAYLENGTH>
 <!--1C35877D26B1432C9867E4F5EAEE17F8-->  <ISREADONLY><![CDATA[N]]></ISREADONLY>
-<!--1C35877D26B1432C9867E4F5EAEE17F8-->  <SEQNO><![CDATA[40]]></SEQNO>
+<!--1C35877D26B1432C9867E4F5EAEE17F8-->  <SEQNO><![CDATA[30]]></SEQNO>
 <!--1C35877D26B1432C9867E4F5EAEE17F8-->  <ISSAMELINE><![CDATA[N]]></ISSAMELINE>
 <!--1C35877D26B1432C9867E4F5EAEE17F8-->  <ISFIELDONLY><![CDATA[N]]></ISFIELDONLY>
 <!--1C35877D26B1432C9867E4F5EAEE17F8-->  <ISENCRYPTED><![CDATA[N]]></ISENCRYPTED>
@@ -258,14 +285,14 @@
 <!--220497F9740C4949B9BB9DDFAFD8F2CD-->  <ISDISPLAYED><![CDATA[Y]]></ISDISPLAYED>
 <!--220497F9740C4949B9BB9DDFAFD8F2CD-->  <DISPLAYLENGTH><![CDATA[32]]></DISPLAYLENGTH>
 <!--220497F9740C4949B9BB9DDFAFD8F2CD-->  <ISREADONLY><![CDATA[N]]></ISREADONLY>
-<!--220497F9740C4949B9BB9DDFAFD8F2CD-->  <SEQNO><![CDATA[120]]></SEQNO>
+<!--220497F9740C4949B9BB9DDFAFD8F2CD-->  <SEQNO><![CDATA[130]]></SEQNO>
 <!--220497F9740C4949B9BB9DDFAFD8F2CD-->  <ISSAMELINE><![CDATA[N]]></ISSAMELINE>
 <!--220497F9740C4949B9BB9DDFAFD8F2CD-->  <ISFIELDONLY><![CDATA[N]]></ISFIELDONLY>
 <!--220497F9740C4949B9BB9DDFAFD8F2CD-->  <ISENCRYPTED><![CDATA[N]]></ISENCRYPTED>
 <!--220497F9740C4949B9BB9DDFAFD8F2CD-->  <SHOWINRELATION><![CDATA[Y]]></SHOWINRELATION>
 <!--220497F9740C4949B9BB9DDFAFD8F2CD-->  <ISFIRSTFOCUSEDFIELD><![CDATA[N]]></ISFIRSTFOCUSEDFIELD>
 <!--220497F9740C4949B9BB9DDFAFD8F2CD-->  <AD_MODULE_ID><![CDATA[9BA0836A3CD74EE4AB48753A47211BCC]]></AD_MODULE_ID>
-<!--220497F9740C4949B9BB9DDFAFD8F2CD-->  <GRID_SEQNO><![CDATA[100]]></GRID_SEQNO>
+<!--220497F9740C4949B9BB9DDFAFD8F2CD-->  <GRID_SEQNO><![CDATA[120]]></GRID_SEQNO>
 <!--220497F9740C4949B9BB9DDFAFD8F2CD-->  <STARTINODDCOLUMN><![CDATA[N]]></STARTINODDCOLUMN>
 <!--220497F9740C4949B9BB9DDFAFD8F2CD-->  <STARTNEWLINE><![CDATA[N]]></STARTNEWLINE>
 <!--220497F9740C4949B9BB9DDFAFD8F2CD-->  <ISSHOWNINSTATUSBAR><![CDATA[N]]></ISSHOWNINSTATUSBAR>
@@ -447,7 +474,7 @@
 <!--39417456DC474B588BF807DF92E618CC-->  <ISDISPLAYED><![CDATA[Y]]></ISDISPLAYED>
 <!--39417456DC474B588BF807DF92E618CC-->  <DISPLAYLENGTH><![CDATA[255]]></DISPLAYLENGTH>
 <!--39417456DC474B588BF807DF92E618CC-->  <ISREADONLY><![CDATA[N]]></ISREADONLY>
-<!--39417456DC474B588BF807DF92E618CC-->  <SEQNO><![CDATA[50]]></SEQNO>
+<!--39417456DC474B588BF807DF92E618CC-->  <SEQNO><![CDATA[40]]></SEQNO>
 <!--39417456DC474B588BF807DF92E618CC-->  <ISSAMELINE><![CDATA[N]]></ISSAMELINE>
 <!--39417456DC474B588BF807DF92E618CC-->  <ISFIELDONLY><![CDATA[N]]></ISFIELDONLY>
 <!--39417456DC474B588BF807DF92E618CC-->  <ISENCRYPTED><![CDATA[N]]></ISENCRYPTED>
@@ -551,6 +578,7 @@
 <!--421D1B31477E4B038E4D5A129EEBE399-->  <AD_TAB_ID><![CDATA[FF8081813157AED2013157BF6D810023]]></AD_TAB_ID>
 <!--421D1B31477E4B038E4D5A129EEBE399-->  <AD_COLUMN_ID><![CDATA[F7DE0BA73FA64A68B898495072729D12]]></AD_COLUMN_ID>
 <!--421D1B31477E4B038E4D5A129EEBE399-->  <ISDISPLAYED><![CDATA[Y]]></ISDISPLAYED>
+<!--421D1B31477E4B038E4D5A129EEBE399-->  <DISPLAYLOGIC><![CDATA[@type@!'Window']]></DISPLAYLOGIC>
 <!--421D1B31477E4B038E4D5A129EEBE399-->  <DISPLAYLENGTH><![CDATA[32]]></DISPLAYLENGTH>
 <!--421D1B31477E4B038E4D5A129EEBE399-->  <ISREADONLY><![CDATA[N]]></ISREADONLY>
 <!--421D1B31477E4B038E4D5A129EEBE399-->  <SEQNO><![CDATA[60]]></SEQNO>
@@ -560,9 +588,9 @@
 <!--421D1B31477E4B038E4D5A129EEBE399-->  <SHOWINRELATION><![CDATA[Y]]></SHOWINRELATION>
 <!--421D1B31477E4B038E4D5A129EEBE399-->  <ISFIRSTFOCUSEDFIELD><![CDATA[N]]></ISFIRSTFOCUSEDFIELD>
 <!--421D1B31477E4B038E4D5A129EEBE399-->  <AD_MODULE_ID><![CDATA[9BA0836A3CD74EE4AB48753A47211BCC]]></AD_MODULE_ID>
-<!--421D1B31477E4B038E4D5A129EEBE399-->  <GRID_SEQNO><![CDATA[60]]></GRID_SEQNO>
+<!--421D1B31477E4B038E4D5A129EEBE399-->  <GRID_SEQNO><![CDATA[70]]></GRID_SEQNO>
 <!--421D1B31477E4B038E4D5A129EEBE399-->  <STARTINODDCOLUMN><![CDATA[N]]></STARTINODDCOLUMN>
-<!--421D1B31477E4B038E4D5A129EEBE399-->  <STARTNEWLINE><![CDATA[Y]]></STARTNEWLINE>
+<!--421D1B31477E4B038E4D5A129EEBE399-->  <STARTNEWLINE><![CDATA[N]]></STARTNEWLINE>
 <!--421D1B31477E4B038E4D5A129EEBE399-->  <ISSHOWNINSTATUSBAR><![CDATA[N]]></ISSHOWNINSTATUSBAR>
 <!--421D1B31477E4B038E4D5A129EEBE399--></AD_FIELD>
 
@@ -712,14 +740,14 @@
 <!--67BFC51699894C3F80679B1C9B1D7DD3-->  <ISDISPLAYED><![CDATA[Y]]></ISDISPLAYED>
 <!--67BFC51699894C3F80679B1C9B1D7DD3-->  <DISPLAYLENGTH><![CDATA[32]]></DISPLAYLENGTH>
 <!--67BFC51699894C3F80679B1C9B1D7DD3-->  <ISREADONLY><![CDATA[N]]></ISREADONLY>
-<!--67BFC51699894C3F80679B1C9B1D7DD3-->  <SEQNO><![CDATA[110]]></SEQNO>
+<!--67BFC51699894C3F80679B1C9B1D7DD3-->  <SEQNO><![CDATA[120]]></SEQNO>
 <!--67BFC51699894C3F80679B1C9B1D7DD3-->  <ISSAMELINE><![CDATA[N]]></ISSAMELINE>
 <!--67BFC51699894C3F80679B1C9B1D7DD3-->  <ISFIELDONLY><![CDATA[N]]></ISFIELDONLY>
 <!--67BFC51699894C3F80679B1C9B1D7DD3-->  <ISENCRYPTED><![CDATA[N]]></ISENCRYPTED>
 <!--67BFC51699894C3F80679B1C9B1D7DD3-->  <SHOWINRELATION><![CDATA[Y]]></SHOWINRELATION>
 <!--67BFC51699894C3F80679B1C9B1D7DD3-->  <ISFIRSTFOCUSEDFIELD><![CDATA[N]]></ISFIRSTFOCUSEDFIELD>
 <!--67BFC51699894C3F80679B1C9B1D7DD3-->  <AD_MODULE_ID><![CDATA[9BA0836A3CD74EE4AB48753A47211BCC]]></AD_MODULE_ID>
-<!--67BFC51699894C3F80679B1C9B1D7DD3-->  <GRID_SEQNO><![CDATA[90]]></GRID_SEQNO>
+<!--67BFC51699894C3F80679B1C9B1D7DD3-->  <GRID_SEQNO><![CDATA[110]]></GRID_SEQNO>
 <!--67BFC51699894C3F80679B1C9B1D7DD3-->  <STARTINODDCOLUMN><![CDATA[N]]></STARTINODDCOLUMN>
 <!--67BFC51699894C3F80679B1C9B1D7DD3-->  <STARTNEWLINE><![CDATA[N]]></STARTNEWLINE>
 <!--67BFC51699894C3F80679B1C9B1D7DD3-->  <ISSHOWNINSTATUSBAR><![CDATA[N]]></ISSHOWNINSTATUSBAR>
@@ -765,14 +793,14 @@
 <!--79F725EF00774420845FCAAEC4720CFC-->  <ISDISPLAYED><![CDATA[Y]]></ISDISPLAYED>
 <!--79F725EF00774420845FCAAEC4720CFC-->  <DISPLAYLENGTH><![CDATA[32]]></DISPLAYLENGTH>
 <!--79F725EF00774420845FCAAEC4720CFC-->  <ISREADONLY><![CDATA[N]]></ISREADONLY>
-<!--79F725EF00774420845FCAAEC4720CFC-->  <SEQNO><![CDATA[100]]></SEQNO>
+<!--79F725EF00774420845FCAAEC4720CFC-->  <SEQNO><![CDATA[110]]></SEQNO>
 <!--79F725EF00774420845FCAAEC4720CFC-->  <ISSAMELINE><![CDATA[N]]></ISSAMELINE>
 <!--79F725EF00774420845FCAAEC4720CFC-->  <ISFIELDONLY><![CDATA[N]]></ISFIELDONLY>
 <!--79F725EF00774420845FCAAEC4720CFC-->  <ISENCRYPTED><![CDATA[N]]></ISENCRYPTED>
 <!--79F725EF00774420845FCAAEC4720CFC-->  <SHOWINRELATION><![CDATA[Y]]></SHOWINRELATION>
 <!--79F725EF00774420845FCAAEC4720CFC-->  <ISFIRSTFOCUSEDFIELD><![CDATA[N]]></ISFIRSTFOCUSEDFIELD>
 <!--79F725EF00774420845FCAAEC4720CFC-->  <AD_MODULE_ID><![CDATA[9BA0836A3CD74EE4AB48753A47211BCC]]></AD_MODULE_ID>
-<!--79F725EF00774420845FCAAEC4720CFC-->  <GRID_SEQNO><![CDATA[80]]></GRID_SEQNO>
+<!--79F725EF00774420845FCAAEC4720CFC-->  <GRID_SEQNO><![CDATA[100]]></GRID_SEQNO>
 <!--79F725EF00774420845FCAAEC4720CFC-->  <STARTINODDCOLUMN><![CDATA[N]]></STARTINODDCOLUMN>
 <!--79F725EF00774420845FCAAEC4720CFC-->  <STARTNEWLINE><![CDATA[N]]></STARTNEWLINE>
 <!--79F725EF00774420845FCAAEC4720CFC-->  <ISSHOWNINSTATUSBAR><![CDATA[N]]></ISSHOWNINSTATUSBAR>
@@ -1455,6 +1483,34 @@
 <!--E36CB4575FDB48D8A60FBBE04693511E-->  <ISSHOWNINSTATUSBAR><![CDATA[N]]></ISSHOWNINSTATUSBAR>
 <!--E36CB4575FDB48D8A60FBBE04693511E--></AD_FIELD>
 
+<!--E8FE37BEE1B44B36A8175082C76D471B--><AD_FIELD>
+<!--E8FE37BEE1B44B36A8175082C76D471B-->  <AD_FIELD_ID><![CDATA[E8FE37BEE1B44B36A8175082C76D471B]]></AD_FIELD_ID>
+<!--E8FE37BEE1B44B36A8175082C76D471B-->  <AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID>
+<!--E8FE37BEE1B44B36A8175082C76D471B-->  <AD_ORG_ID><![CDATA[0]]></AD_ORG_ID>
+<!--E8FE37BEE1B44B36A8175082C76D471B-->  <ISACTIVE><![CDATA[Y]]></ISACTIVE>
+<!--E8FE37BEE1B44B36A8175082C76D471B-->  <NAME><![CDATA[Window]]></NAME>
+<!--E8FE37BEE1B44B36A8175082C76D471B-->  <DESCRIPTION><![CDATA[A work area which can be used to create, view, edit, and process a record.]]></DESCRIPTION>
+<!--E8FE37BEE1B44B36A8175082C76D471B-->  <HELP><![CDATA[The Window field identifies a unique Window in the system.]]></HELP>
+<!--E8FE37BEE1B44B36A8175082C76D471B-->  <ISCENTRALLYMAINTAINED><![CDATA[Y]]></ISCENTRALLYMAINTAINED>
+<!--E8FE37BEE1B44B36A8175082C76D471B-->  <AD_TAB_ID><![CDATA[FF8081813157AED2013157BF6D810023]]></AD_TAB_ID>
+<!--E8FE37BEE1B44B36A8175082C76D471B-->  <AD_COLUMN_ID><![CDATA[FB975B710F5544CC8BC99F981F63C1CD]]></AD_COLUMN_ID>
+<!--E8FE37BEE1B44B36A8175082C76D471B-->  <ISDISPLAYED><![CDATA[Y]]></ISDISPLAYED>
+<!--E8FE37BEE1B44B36A8175082C76D471B-->  <DISPLAYLOGIC><![CDATA[@type@='Window']]></DISPLAYLOGIC>
+<!--E8FE37BEE1B44B36A8175082C76D471B-->  <DISPLAYLENGTH><![CDATA[32]]></DISPLAYLENGTH>
+<!--E8FE37BEE1B44B36A8175082C76D471B-->  <ISREADONLY><![CDATA[N]]></ISREADONLY>
+<!--E8FE37BEE1B44B36A8175082C76D471B-->  <SEQNO><![CDATA[70]]></SEQNO>
+<!--E8FE37BEE1B44B36A8175082C76D471B-->  <ISSAMELINE><![CDATA[N]]></ISSAMELINE>
+<!--E8FE37BEE1B44B36A8175082C76D471B-->  <ISFIELDONLY><![CDATA[N]]></ISFIELDONLY>
+<!--E8FE37BEE1B44B36A8175082C76D471B-->  <ISENCRYPTED><![CDATA[N]]></ISENCRYPTED>
+<!--E8FE37BEE1B44B36A8175082C76D471B-->  <SHOWINRELATION><![CDATA[Y]]></SHOWINRELATION>
+<!--E8FE37BEE1B44B36A8175082C76D471B-->  <ISFIRSTFOCUSEDFIELD><![CDATA[N]]></ISFIRSTFOCUSEDFIELD>
+<!--E8FE37BEE1B44B36A8175082C76D471B-->  <AD_MODULE_ID><![CDATA[9BA0836A3CD74EE4AB48753A47211BCC]]></AD_MODULE_ID>
+<!--E8FE37BEE1B44B36A8175082C76D471B-->  <GRID_SEQNO><![CDATA[80]]></GRID_SEQNO>
+<!--E8FE37BEE1B44B36A8175082C76D471B-->  <STARTINODDCOLUMN><![CDATA[N]]></STARTINODDCOLUMN>
+<!--E8FE37BEE1B44B36A8175082C76D471B-->  <STARTNEWLINE><![CDATA[N]]></STARTNEWLINE>
+<!--E8FE37BEE1B44B36A8175082C76D471B-->  <ISSHOWNINSTATUSBAR><![CDATA[N]]></ISSHOWNINSTATUSBAR>
+<!--E8FE37BEE1B44B36A8175082C76D471B--></AD_FIELD>
+
 <!--ED70A592E3B5452188644885C69C6333--><AD_FIELD>
 <!--ED70A592E3B5452188644885C69C6333-->  <AD_FIELD_ID><![CDATA[ED70A592E3B5452188644885C69C6333]]></AD_FIELD_ID>
 <!--ED70A592E3B5452188644885C69C6333-->  <AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID>
@@ -1470,14 +1526,14 @@
 <!--ED70A592E3B5452188644885C69C6333-->  <ISDISPLAYED><![CDATA[Y]]></ISDISPLAYED>
 <!--ED70A592E3B5452188644885C69C6333-->  <DISPLAYLENGTH><![CDATA[32]]></DISPLAYLENGTH>
 <!--ED70A592E3B5452188644885C69C6333-->  <ISREADONLY><![CDATA[N]]></ISREADONLY>
-<!--ED70A592E3B5452188644885C69C6333-->  <SEQNO><![CDATA[90]]></SEQNO>
+<!--ED70A592E3B5452188644885C69C6333-->  <SEQNO><![CDATA[100]]></SEQNO>
 <!--ED70A592E3B5452188644885C69C6333-->  <ISSAMELINE><![CDATA[N]]></ISSAMELINE>
 <!--ED70A592E3B5452188644885C69C6333-->  <ISFIELDONLY><![CDATA[N]]></ISFIELDONLY>
 <!--ED70A592E3B5452188644885C69C6333-->  <ISENCRYPTED><![CDATA[N]]></ISENCRYPTED>
 <!--ED70A592E3B5452188644885C69C6333-->  <SHOWINRELATION><![CDATA[Y]]></SHOWINRELATION>
 <!--ED70A592E3B5452188644885C69C6333-->  <ISFIRSTFOCUSEDFIELD><![CDATA[N]]></ISFIRSTFOCUSEDFIELD>
 <!--ED70A592E3B5452188644885C69C6333-->  <AD_MODULE_ID><![CDATA[9BA0836A3CD74EE4AB48753A47211BCC]]></AD_MODULE_ID>
-<!--ED70A592E3B5452188644885C69C6333-->  <GRID_SEQNO><![CDATA[70]]></GRID_SEQNO>
+<!--ED70A592E3B5452188644885C69C6333-->  <GRID_SEQNO><![CDATA[90]]></GRID_SEQNO>
 <!--ED70A592E3B5452188644885C69C6333-->  <STARTINODDCOLUMN><![CDATA[N]]></STARTINODDCOLUMN>
 <!--ED70A592E3B5452188644885C69C6333-->  <STARTNEWLINE><![CDATA[Y]]></STARTNEWLINE>
 <!--ED70A592E3B5452188644885C69C6333-->  <ISSHOWNINSTATUSBAR><![CDATA[N]]></ISSHOWNINSTATUSBAR>
@@ -1626,7 +1682,7 @@
 <!--FEFA683DB9F742689C59285E583DA644-->  <ISDISPLAYED><![CDATA[Y]]></ISDISPLAYED>
 <!--FEFA683DB9F742689C59285E583DA644-->  <DISPLAYLENGTH><![CDATA[1]]></DISPLAYLENGTH>
 <!--FEFA683DB9F742689C59285E583DA644-->  <ISREADONLY><![CDATA[N]]></ISREADONLY>
-<!--FEFA683DB9F742689C59285E583DA644-->  <SEQNO><![CDATA[70]]></SEQNO>
+<!--FEFA683DB9F742689C59285E583DA644-->  <SEQNO><![CDATA[80]]></SEQNO>
 <!--FEFA683DB9F742689C59285E583DA644-->  <ISSAMELINE><![CDATA[N]]></ISSAMELINE>
 <!--FEFA683DB9F742689C59285E583DA644-->  <ISFIELDONLY><![CDATA[N]]></ISFIELDONLY>
 <!--FEFA683DB9F742689C59285E583DA644-->  <ISENCRYPTED><![CDATA[N]]></ISENCRYPTED>
--- a/modules/org.openbravo.client.application/src-db/database/sourcedata/AD_MENU.xml	Thu Oct 13 18:24:25 2011 +0200
+++ b/modules/org.openbravo.client.application/src-db/database/sourcedata/AD_MENU.xml	Thu Oct 20 13:09:18 2011 +0200
@@ -1,5 +1,18 @@
 <?xml version='1.0' encoding='UTF-8'?>
 <data>
+<!--1005400002--><AD_MENU>
+<!--1005400002-->  <AD_MENU_ID><![CDATA[1005400002]]></AD_MENU_ID>
+<!--1005400002-->  <AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID>
+<!--1005400002-->  <AD_ORG_ID><![CDATA[0]]></AD_ORG_ID>
+<!--1005400002-->  <ISACTIVE><![CDATA[Y]]></ISACTIVE>
+<!--1005400002-->  <NAME><![CDATA[Register]]></NAME>
+<!--1005400002-->  <DESCRIPTION><![CDATA[Register your installation of Openbravo ERP in order to receive development and commercial updates and information]]></DESCRIPTION>
+<!--1005400002-->  <ISSUMMARY><![CDATA[N]]></ISSUMMARY>
+<!--1005400002-->  <ACTION><![CDATA[OBUIAPP_OpenView]]></ACTION>
+<!--1005400002-->  <AD_MODULE_ID><![CDATA[9BA0836A3CD74EE4AB48753A47211BCC]]></AD_MODULE_ID>
+<!--1005400002-->  <EM_OBUIAPP_VIEW_IMPL_ID><![CDATA[FF808081329B023101329B0CE2080013]]></EM_OBUIAPP_VIEW_IMPL_ID>
+<!--1005400002--></AD_MENU>
+
 <!--6FD97ECD72B4405FA1442FD8673AE571--><AD_MENU>
 <!--6FD97ECD72B4405FA1442FD8673AE571-->  <AD_MENU_ID><![CDATA[6FD97ECD72B4405FA1442FD8673AE571]]></AD_MENU_ID>
 <!--6FD97ECD72B4405FA1442FD8673AE571-->  <AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID>
--- a/modules/org.openbravo.client.application/src-db/database/sourcedata/AD_MESSAGE.xml	Thu Oct 13 18:24:25 2011 +0200
+++ b/modules/org.openbravo.client.application/src-db/database/sourcedata/AD_MESSAGE.xml	Thu Oct 20 13:09:18 2011 +0200
@@ -1362,7 +1362,7 @@
 <!--FF80808130DC55FE0130DC9631A60019-->  <AD_ORG_ID><![CDATA[0]]></AD_ORG_ID>
 <!--FF80808130DC55FE0130DC9631A60019-->  <ISACTIVE><![CDATA[Y]]></ISACTIVE>
 <!--FF80808130DC55FE0130DC9631A60019-->  <VALUE><![CDATA[OBUIAPP_ActivateMessage]]></VALUE>
-<!--FF80808130DC55FE0130DC9631A60019-->  <MSGTEXT><![CDATA[%0 only available for Professional and Basic Edition subscribers. <a target="_blank" href="http://www.openbravo.com/product/erp/editions/">Learn more</a> about the benefits of Openbravo's Professional and Basic Editions.]]></MSGTEXT>
+<!--FF80808130DC55FE0130DC9631A60019-->  <MSGTEXT><![CDATA[%0 only available for Professional and Basic Edition subscribers. <br/><a target="_blank" href="http://www.openbravo.com/product/erp/editions/">Learn more</a> about the benefits of Openbravo's Professional and Basic Editions.]]></MSGTEXT>
 <!--FF80808130DC55FE0130DC9631A60019-->  <MSGTIP><![CDATA[%0 is a place-holder used to show a feature description]]></MSGTIP>
 <!--FF80808130DC55FE0130DC9631A60019-->  <MSGTYPE><![CDATA[I]]></MSGTYPE>
 <!--FF80808130DC55FE0130DC9631A60019-->  <AD_MODULE_ID><![CDATA[9BA0836A3CD74EE4AB48753A47211BCC]]></AD_MODULE_ID>
@@ -1473,7 +1473,7 @@
 <!--FF8080813198F7290131995F17A8004E-->  <AD_ORG_ID><![CDATA[0]]></AD_ORG_ID>
 <!--FF8080813198F7290131995F17A8004E-->  <ISACTIVE><![CDATA[Y]]></ISACTIVE>
 <!--FF8080813198F7290131995F17A8004E-->  <VALUE><![CDATA[OBUIAPP_ActivateMessagePersonalization]]></VALUE>
-<!--FF8080813198F7290131995F17A8004E-->  <MSGTEXT><![CDATA[<a href="http://wiki.openbravo.com/wiki/User_Manual/Window_Personalization" target="_blank">Window Personalization</a> is a Premium Feature]]></MSGTEXT>
+<!--FF8080813198F7290131995F17A8004E-->  <MSGTEXT><![CDATA[<a href="http://wiki.openbravo.com/wiki/User_Manual/Window_Personalization" target="_blank">Form Personalization</a> is a Premium Feature]]></MSGTEXT>
 <!--FF8080813198F7290131995F17A8004E-->  <MSGTYPE><![CDATA[I]]></MSGTYPE>
 <!--FF8080813198F7290131995F17A8004E-->  <AD_MODULE_ID><![CDATA[9BA0836A3CD74EE4AB48753A47211BCC]]></AD_MODULE_ID>
 <!--FF8080813198F7290131995F17A8004E--></AD_MESSAGE>
@@ -2636,7 +2636,7 @@
 <!--FF8081813157C86B01315A092B6C0062-->  <AD_ORG_ID><![CDATA[0]]></AD_ORG_ID>
 <!--FF8081813157C86B01315A092B6C0062-->  <ISACTIVE><![CDATA[Y]]></ISACTIVE>
 <!--FF8081813157C86B01315A092B6C0062-->  <VALUE><![CDATA[OBUIAPP_Personalization_Toolbar_Button]]></VALUE>
-<!--FF8081813157C86B01315A092B6C0062-->  <MSGTEXT><![CDATA[Personalize the layout of this tab.]]></MSGTEXT>
+<!--FF8081813157C86B01315A092B6C0062-->  <MSGTEXT><![CDATA[Form Personalization]]></MSGTEXT>
 <!--FF8081813157C86B01315A092B6C0062-->  <MSGTYPE><![CDATA[I]]></MSGTYPE>
 <!--FF8081813157C86B01315A092B6C0062-->  <AD_MODULE_ID><![CDATA[9BA0836A3CD74EE4AB48753A47211BCC]]></AD_MODULE_ID>
 <!--FF8081813157C86B01315A092B6C0062--></AD_MESSAGE>
@@ -3015,4 +3015,138 @@
 <!--FF80818131D7B00F0131D7CBD2E9002A-->  <AD_MODULE_ID><![CDATA[9BA0836A3CD74EE4AB48753A47211BCC]]></AD_MODULE_ID>
 <!--FF80818131D7B00F0131D7CBD2E9002A--></AD_MESSAGE>
 
+<!--FF8081813216F38A013217412A0A000A--><AD_MESSAGE>
+<!--FF8081813216F38A013217412A0A000A-->  <AD_MESSAGE_ID><![CDATA[FF8081813216F38A013217412A0A000A]]></AD_MESSAGE_ID>
+<!--FF8081813216F38A013217412A0A000A-->  <AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID>
+<!--FF8081813216F38A013217412A0A000A-->  <AD_ORG_ID><![CDATA[0]]></AD_ORG_ID>
+<!--FF8081813216F38A013217412A0A000A-->  <ISACTIVE><![CDATA[Y]]></ISACTIVE>
+<!--FF8081813216F38A013217412A0A000A-->  <VALUE><![CDATA[OBUIAPP_SaveView]]></VALUE>
+<!--FF8081813216F38A013217412A0A000A-->  <MSGTEXT><![CDATA[Save View]]></MSGTEXT>
+<!--FF8081813216F38A013217412A0A000A-->  <MSGTYPE><![CDATA[I]]></MSGTYPE>
+<!--FF8081813216F38A013217412A0A000A-->  <AD_MODULE_ID><![CDATA[9BA0836A3CD74EE4AB48753A47211BCC]]></AD_MODULE_ID>
+<!--FF8081813216F38A013217412A0A000A--></AD_MESSAGE>
+
+<!--FF8081813216F38A01321741598A000F--><AD_MESSAGE>
+<!--FF8081813216F38A01321741598A000F-->  <AD_MESSAGE_ID><![CDATA[FF8081813216F38A01321741598A000F]]></AD_MESSAGE_ID>
+<!--FF8081813216F38A01321741598A000F-->  <AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID>
+<!--FF8081813216F38A01321741598A000F-->  <AD_ORG_ID><![CDATA[0]]></AD_ORG_ID>
+<!--FF8081813216F38A01321741598A000F-->  <ISACTIVE><![CDATA[Y]]></ISACTIVE>
+<!--FF8081813216F38A01321741598A000F-->  <VALUE><![CDATA[OBUIAPP_DeleteView]]></VALUE>
+<!--FF8081813216F38A01321741598A000F-->  <MSGTEXT><![CDATA[Delete View]]></MSGTEXT>
+<!--FF8081813216F38A01321741598A000F-->  <MSGTYPE><![CDATA[I]]></MSGTYPE>
+<!--FF8081813216F38A01321741598A000F-->  <AD_MODULE_ID><![CDATA[9BA0836A3CD74EE4AB48753A47211BCC]]></AD_MODULE_ID>
+<!--FF8081813216F38A01321741598A000F--></AD_MESSAGE>
+
+<!--FF8081813216F38A01321742648D0013--><AD_MESSAGE>
+<!--FF8081813216F38A01321742648D0013-->  <AD_MESSAGE_ID><![CDATA[FF8081813216F38A01321742648D0013]]></AD_MESSAGE_ID>
+<!--FF8081813216F38A01321742648D0013-->  <AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID>
+<!--FF8081813216F38A01321742648D0013-->  <AD_ORG_ID><![CDATA[0]]></AD_ORG_ID>
+<!--FF8081813216F38A01321742648D0013-->  <ISACTIVE><![CDATA[Y]]></ISACTIVE>
+<!--FF8081813216F38A01321742648D0013-->  <VALUE><![CDATA[OBUIAPP_ManageViews_Toolbar_Button]]></VALUE>
+<!--FF8081813216F38A01321742648D0013-->  <MSGTEXT><![CDATA[Save View]]></MSGTEXT>
+<!--FF8081813216F38A01321742648D0013-->  <MSGTYPE><![CDATA[I]]></MSGTYPE>
+<!--FF8081813216F38A01321742648D0013-->  <AD_MODULE_ID><![CDATA[9BA0836A3CD74EE4AB48753A47211BCC]]></AD_MODULE_ID>
+<!--FF8081813216F38A01321742648D0013--></AD_MESSAGE>
+
+<!--FF808181321A7CAB01321A8A6E670013--><AD_MESSAGE>
+<!--FF808181321A7CAB01321A8A6E670013-->  <AD_MESSAGE_ID><![CDATA[FF808181321A7CAB01321A8A6E670013]]></AD_MESSAGE_ID>
+<!--FF808181321A7CAB01321A8A6E670013-->  <AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID>
+<!--FF808181321A7CAB01321A8A6E670013-->  <AD_ORG_ID><![CDATA[0]]></AD_ORG_ID>
+<!--FF808181321A7CAB01321A8A6E670013-->  <ISACTIVE><![CDATA[Y]]></ISACTIVE>
+<!--FF808181321A7CAB01321A8A6E670013-->  <VALUE><![CDATA[OBUIAPP_View]]></VALUE>
+<!--FF808181321A7CAB01321A8A6E670013-->  <MSGTEXT><![CDATA[View]]></MSGTEXT>
+<!--FF808181321A7CAB01321A8A6E670013-->  <MSGTYPE><![CDATA[I]]></MSGTYPE>
+<!--FF808181321A7CAB01321A8A6E670013-->  <AD_MODULE_ID><![CDATA[9BA0836A3CD74EE4AB48753A47211BCC]]></AD_MODULE_ID>
+<!--FF808181321A7CAB01321A8A6E670013--></AD_MESSAGE>
+
+<!--FF808181321AE53401321B10CCA5000F--><AD_MESSAGE>
+<!--FF808181321AE53401321B10CCA5000F-->  <AD_MESSAGE_ID><![CDATA[FF808181321AE53401321B10CCA5000F]]></AD_MESSAGE_ID>
+<!--FF808181321AE53401321B10CCA5000F-->  <AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID>
+<!--FF808181321AE53401321B10CCA5000F-->  <AD_ORG_ID><![CDATA[0]]></AD_ORG_ID>
+<!--FF808181321AE53401321B10CCA5000F-->  <ISACTIVE><![CDATA[Y]]></ISACTIVE>
+<!--FF808181321AE53401321B10CCA5000F-->  <VALUE><![CDATA[OBUIAPP_Level]]></VALUE>
+<!--FF808181321AE53401321B10CCA5000F-->  <MSGTEXT><![CDATA[Level]]></MSGTEXT>
+<!--FF808181321AE53401321B10CCA5000F-->  <MSGTYPE><![CDATA[I]]></MSGTYPE>
+<!--FF808181321AE53401321B10CCA5000F-->  <AD_MODULE_ID><![CDATA[9BA0836A3CD74EE4AB48753A47211BCC]]></AD_MODULE_ID>
+<!--FF808181321AE53401321B10CCA5000F--></AD_MESSAGE>
+
+<!--FF808181321AE53401321B10FEE00014--><AD_MESSAGE>
+<!--FF808181321AE53401321B10FEE00014-->  <AD_MESSAGE_ID><![CDATA[FF808181321AE53401321B10FEE00014]]></AD_MESSAGE_ID>
+<!--FF808181321AE53401321B10FEE00014-->  <AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID>
+<!--FF808181321AE53401321B10FEE00014-->  <AD_ORG_ID><![CDATA[0]]></AD_ORG_ID>
+<!--FF808181321AE53401321B10FEE00014-->  <ISACTIVE><![CDATA[Y]]></ISACTIVE>
+<!--FF808181321AE53401321B10FEE00014-->  <VALUE><![CDATA[OBUIAPP_Value]]></VALUE>
+<!--FF808181321AE53401321B10FEE00014-->  <MSGTEXT><![CDATA[Value]]></MSGTEXT>
+<!--FF808181321AE53401321B10FEE00014-->  <MSGTYPE><![CDATA[I]]></MSGTYPE>
+<!--FF808181321AE53401321B10FEE00014-->  <AD_MODULE_ID><![CDATA[9BA0836A3CD74EE4AB48753A47211BCC]]></AD_MODULE_ID>
+<!--FF808181321AE53401321B10FEE00014--></AD_MESSAGE>
+
+<!--FF808181321E629B01321E67A6720009--><AD_MESSAGE>
+<!--FF808181321E629B01321E67A6720009-->  <AD_MESSAGE_ID><![CDATA[FF808181321E629B01321E67A6720009]]></AD_MESSAGE_ID>
+<!--FF808181321E629B01321E67A6720009-->  <AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID>
+<!--FF808181321E629B01321E67A6720009-->  <AD_ORG_ID><![CDATA[0]]></AD_ORG_ID>
+<!--FF808181321E629B01321E67A6720009-->  <ISACTIVE><![CDATA[Y]]></ISACTIVE>
+<!--FF808181321E629B01321E67A6720009-->  <VALUE><![CDATA[OBUIAPP_ViewHasBeenSaved]]></VALUE>
+<!--FF808181321E629B01321E67A6720009-->  <MSGTEXT><![CDATA[The view state has been saved.]]></MSGTEXT>
+<!--FF808181321E629B01321E67A6720009-->  <MSGTYPE><![CDATA[I]]></MSGTYPE>
+<!--FF808181321E629B01321E67A6720009-->  <AD_MODULE_ID><![CDATA[9BA0836A3CD74EE4AB48753A47211BCC]]></AD_MODULE_ID>
+<!--FF808181321E629B01321E67A6720009--></AD_MESSAGE>
+
+<!--FF808181321E629B01321E67D704000E--><AD_MESSAGE>
+<!--FF808181321E629B01321E67D704000E-->  <AD_MESSAGE_ID><![CDATA[FF808181321E629B01321E67D704000E]]></AD_MESSAGE_ID>
+<!--FF808181321E629B01321E67D704000E-->  <AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID>
+<!--FF808181321E629B01321E67D704000E-->  <AD_ORG_ID><![CDATA[0]]></AD_ORG_ID>
+<!--FF808181321E629B01321E67D704000E-->  <ISACTIVE><![CDATA[Y]]></ISACTIVE>
+<!--FF808181321E629B01321E67D704000E-->  <VALUE><![CDATA[OBUIAPP_ViewHasBeenDeleted]]></VALUE>
+<!--FF808181321E629B01321E67D704000E-->  <MSGTEXT><![CDATA[The view has been deleted.]]></MSGTEXT>
+<!--FF808181321E629B01321E67D704000E-->  <MSGTYPE><![CDATA[I]]></MSGTYPE>
+<!--FF808181321E629B01321E67D704000E-->  <AD_MODULE_ID><![CDATA[9BA0836A3CD74EE4AB48753A47211BCC]]></AD_MODULE_ID>
+<!--FF808181321E629B01321E67D704000E--></AD_MESSAGE>
+
+<!--FF80818132443EBA01324442C9E2000C--><AD_MESSAGE>
+<!--FF80818132443EBA01324442C9E2000C-->  <AD_MESSAGE_ID><![CDATA[FF80818132443EBA01324442C9E2000C]]></AD_MESSAGE_ID>
+<!--FF80818132443EBA01324442C9E2000C-->  <AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID>
+<!--FF80818132443EBA01324442C9E2000C-->  <AD_ORG_ID><![CDATA[0]]></AD_ORG_ID>
+<!--FF80818132443EBA01324442C9E2000C-->  <ISACTIVE><![CDATA[Y]]></ISACTIVE>
+<!--FF80818132443EBA01324442C9E2000C-->  <VALUE><![CDATA[OBUIAPP_SetDefaultView]]></VALUE>
+<!--FF80818132443EBA01324442C9E2000C-->  <MSGTEXT><![CDATA[Set Default View]]></MSGTEXT>
+<!--FF80818132443EBA01324442C9E2000C-->  <MSGTIP><![CDATA[Set Default View]]></MSGTIP>
+<!--FF80818132443EBA01324442C9E2000C-->  <MSGTYPE><![CDATA[I]]></MSGTYPE>
+<!--FF80818132443EBA01324442C9E2000C-->  <AD_MODULE_ID><![CDATA[9BA0836A3CD74EE4AB48753A47211BCC]]></AD_MODULE_ID>
+<!--FF80818132443EBA01324442C9E2000C--></AD_MESSAGE>
+
+<!--FF80818132443EBA0132444357CE0011--><AD_MESSAGE>
+<!--FF80818132443EBA0132444357CE0011-->  <AD_MESSAGE_ID><![CDATA[FF80818132443EBA0132444357CE0011]]></AD_MESSAGE_ID>
+<!--FF80818132443EBA0132444357CE0011-->  <AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID>
+<!--FF80818132443EBA0132444357CE0011-->  <AD_ORG_ID><![CDATA[0]]></AD_ORG_ID>
+<!--FF80818132443EBA0132444357CE0011-->  <ISACTIVE><![CDATA[Y]]></ISACTIVE>
+<!--FF80818132443EBA0132444357CE0011-->  <VALUE><![CDATA[OBUIAPP_DefaultView]]></VALUE>
+<!--FF80818132443EBA0132444357CE0011-->  <MSGTEXT><![CDATA[Set as Default]]></MSGTEXT>
+<!--FF80818132443EBA0132444357CE0011-->  <MSGTIP><![CDATA[Set as Default]]></MSGTIP>
+<!--FF80818132443EBA0132444357CE0011-->  <MSGTYPE><![CDATA[I]]></MSGTYPE>
+<!--FF80818132443EBA0132444357CE0011-->  <AD_MODULE_ID><![CDATA[9BA0836A3CD74EE4AB48753A47211BCC]]></AD_MODULE_ID>
+<!--FF80818132443EBA0132444357CE0011--></AD_MESSAGE>
+
+<!--FF80818132AE40480132AED3676C0126--><AD_MESSAGE>
+<!--FF80818132AE40480132AED3676C0126-->  <AD_MESSAGE_ID><![CDATA[FF80818132AE40480132AED3676C0126]]></AD_MESSAGE_ID>
+<!--FF80818132AE40480132AED3676C0126-->  <AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID>
+<!--FF80818132AE40480132AED3676C0126-->  <AD_ORG_ID><![CDATA[0]]></AD_ORG_ID>
+<!--FF80818132AE40480132AED3676C0126-->  <ISACTIVE><![CDATA[Y]]></ISACTIVE>
+<!--FF80818132AE40480132AED3676C0126-->  <VALUE><![CDATA[OBUIAPP_SaveAs]]></VALUE>
+<!--FF80818132AE40480132AED3676C0126-->  <MSGTEXT><![CDATA[Save as]]></MSGTEXT>
+<!--FF80818132AE40480132AED3676C0126-->  <MSGTYPE><![CDATA[I]]></MSGTYPE>
+<!--FF80818132AE40480132AED3676C0126-->  <AD_MODULE_ID><![CDATA[9BA0836A3CD74EE4AB48753A47211BCC]]></AD_MODULE_ID>
+<!--FF80818132AE40480132AED3676C0126--></AD_MESSAGE>
+
+<!--FF80818132D5240F0132D856F3D20023--><AD_MESSAGE>
+<!--FF80818132D5240F0132D856F3D20023-->  <AD_MESSAGE_ID><![CDATA[FF80818132D5240F0132D856F3D20023]]></AD_MESSAGE_ID>
+<!--FF80818132D5240F0132D856F3D20023-->  <AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID>
+<!--FF80818132D5240F0132D856F3D20023-->  <AD_ORG_ID><![CDATA[0]]></AD_ORG_ID>
+<!--FF80818132D5240F0132D856F3D20023-->  <ISACTIVE><![CDATA[Y]]></ISACTIVE>
+<!--FF80818132D5240F0132D856F3D20023-->  <VALUE><![CDATA[OBUIAPP_ActivateMessageWindowPersonalization]]></VALUE>
+<!--FF80818132D5240F0132D856F3D20023-->  <MSGTEXT><![CDATA[<a href="http://wiki.openbravo.com/wiki/User_Manual/Window_Personalization#Saved_and_Named_Views" target="_blank">Window Personalization</a> is a Premium Feature]]></MSGTEXT>
+<!--FF80818132D5240F0132D856F3D20023-->  <MSGTYPE><![CDATA[I]]></MSGTYPE>
+<!--FF80818132D5240F0132D856F3D20023-->  <AD_MODULE_ID><![CDATA[9BA0836A3CD74EE4AB48753A47211BCC]]></AD_MODULE_ID>
+<!--FF80818132D5240F0132D856F3D20023--></AD_MESSAGE>
+
 </data>
--- a/modules/org.openbravo.client.application/src-db/database/sourcedata/AD_MODULE.xml	Thu Oct 13 18:24:25 2011 +0200
+++ b/modules/org.openbravo.client.application/src-db/database/sourcedata/AD_MODULE.xml	Thu Oct 20 13:09:18 2011 +0200
@@ -6,7 +6,7 @@
 <!--9BA0836A3CD74EE4AB48753A47211BCC-->  <AD_ORG_ID><![CDATA[0]]></AD_ORG_ID>
 <!--9BA0836A3CD74EE4AB48753A47211BCC-->  <ISACTIVE><![CDATA[Y]]></ISACTIVE>
 <!--9BA0836A3CD74EE4AB48753A47211BCC-->  <NAME><![CDATA[User Interface Application]]></NAME>
-<!--9BA0836A3CD74EE4AB48753A47211BCC-->  <VERSION><![CDATA[2.1.13698]]></VERSION>
+<!--9BA0836A3CD74EE4AB48753A47211BCC-->  <VERSION><![CDATA[2.1.13966]]></VERSION>
 <!--9BA0836A3CD74EE4AB48753A47211BCC-->  <DESCRIPTION><![CDATA[Provides the main application components for the openbravo user interface]]></DESCRIPTION>
 <!--9BA0836A3CD74EE4AB48753A47211BCC-->  <HELP><![CDATA[Provides the main application components for the openbravo user interface. The main layout incorporates a navigation bar and a main view area.]]></HELP>
 <!--9BA0836A3CD74EE4AB48753A47211BCC-->  <URL><![CDATA[http://forge.openbravo.com/projects/clientapplication]]></URL>
@@ -22,7 +22,7 @@
 <!--9BA0836A3CD74EE4AB48753A47211BCC-->  <ISTRANSLATIONMODULE><![CDATA[N]]></ISTRANSLATIONMODULE>
 <!--9BA0836A3CD74EE4AB48753A47211BCC-->  <HASREFERENCEDATA><![CDATA[N]]></HASREFERENCEDATA>
 <!--9BA0836A3CD74EE4AB48753A47211BCC-->  <UPDATEINFO><![CDATA[Styling bugfixing]]></UPDATEINFO>
-<!--9BA0836A3CD74EE4AB48753A47211BCC-->  <VERSION_LABEL><![CDATA[MP3]]></VERSION_LABEL>
+<!--9BA0836A3CD74EE4AB48753A47211BCC-->  <VERSION_LABEL><![CDATA[MP4]]></VERSION_LABEL>
 <!--9BA0836A3CD74EE4AB48753A47211BCC-->  <ISCOMMERCIAL><![CDATA[N]]></ISCOMMERCIAL>
 <!--9BA0836A3CD74EE4AB48753A47211BCC--></AD_MODULE>
 
--- a/modules/org.openbravo.client.application/src-db/database/sourcedata/AD_MODULE_DEPENDENCY.xml	Thu Oct 13 18:24:25 2011 +0200
+++ b/modules/org.openbravo.client.application/src-db/database/sourcedata/AD_MODULE_DEPENDENCY.xml	Thu Oct 20 13:09:18 2011 +0200
@@ -7,7 +7,7 @@
 <!--15D7CE8D95D043189162DBABA54A1F61-->  <ISACTIVE><![CDATA[Y]]></ISACTIVE>
 <!--15D7CE8D95D043189162DBABA54A1F61-->  <AD_MODULE_ID><![CDATA[9BA0836A3CD74EE4AB48753A47211BCC]]></AD_MODULE_ID>
 <!--15D7CE8D95D043189162DBABA54A1F61-->  <AD_DEPENDENT_MODULE_ID><![CDATA[A44B9BA75C354D8FB2E3F7D6EB6BFDC4]]></AD_DEPENDENT_MODULE_ID>
-<!--15D7CE8D95D043189162DBABA54A1F61-->  <STARTVERSION><![CDATA[2.1.13698]]></STARTVERSION>
+<!--15D7CE8D95D043189162DBABA54A1F61-->  <STARTVERSION><![CDATA[2.1.13966]]></STARTVERSION>
 <!--15D7CE8D95D043189162DBABA54A1F61-->  <ISINCLUDED><![CDATA[N]]></ISINCLUDED>
 <!--15D7CE8D95D043189162DBABA54A1F61-->  <DEPENDANT_MODULE_NAME><![CDATA[JSON Datasource]]></DEPENDANT_MODULE_NAME>
 <!--15D7CE8D95D043189162DBABA54A1F61-->  <DEPENDENCY_ENFORCEMENT><![CDATA[MAJOR]]></DEPENDENCY_ENFORCEMENT>
@@ -21,7 +21,7 @@
 <!--60A170212F36499D83B8AD38D01F46B3-->  <ISACTIVE><![CDATA[Y]]></ISACTIVE>
 <!--60A170212F36499D83B8AD38D01F46B3-->  <AD_MODULE_ID><![CDATA[9BA0836A3CD74EE4AB48753A47211BCC]]></AD_MODULE_ID>
 <!--60A170212F36499D83B8AD38D01F46B3-->  <AD_DEPENDENT_MODULE_ID><![CDATA[4B828F4D03264080AA1D2057B13F613C]]></AD_DEPENDENT_MODULE_ID>
-<!--60A170212F36499D83B8AD38D01F46B3-->  <STARTVERSION><![CDATA[2.1.13698]]></STARTVERSION>
+<!--60A170212F36499D83B8AD38D01F46B3-->  <STARTVERSION><![CDATA[2.1.13966]]></STARTVERSION>
 <!--60A170212F36499D83B8AD38D01F46B3-->  <ISINCLUDED><![CDATA[N]]></ISINCLUDED>
 <!--60A170212F36499D83B8AD38D01F46B3-->  <DEPENDANT_MODULE_NAME><![CDATA[User Interface Client Kernel]]></DEPENDANT_MODULE_NAME>
 <!--60A170212F36499D83B8AD38D01F46B3-->  <DEPENDENCY_ENFORCEMENT><![CDATA[MAJOR]]></DEPENDENCY_ENFORCEMENT>
@@ -35,7 +35,7 @@
 <!--824D60CB352E4099B1D8C903CA139DAE-->  <ISACTIVE><![CDATA[Y]]></ISACTIVE>
 <!--824D60CB352E4099B1D8C903CA139DAE-->  <AD_MODULE_ID><![CDATA[9BA0836A3CD74EE4AB48753A47211BCC]]></AD_MODULE_ID>
 <!--824D60CB352E4099B1D8C903CA139DAE-->  <AD_DEPENDENT_MODULE_ID><![CDATA[0]]></AD_DEPENDENT_MODULE_ID>
-<!--824D60CB352E4099B1D8C903CA139DAE-->  <STARTVERSION><![CDATA[3.0.13698]]></STARTVERSION>
+<!--824D60CB352E4099B1D8C903CA139DAE-->  <STARTVERSION><![CDATA[3.0.13966]]></STARTVERSION>
 <!--824D60CB352E4099B1D8C903CA139DAE-->  <ISINCLUDED><![CDATA[N]]></ISINCLUDED>
 <!--824D60CB352E4099B1D8C903CA139DAE-->  <DEPENDANT_MODULE_NAME><![CDATA[core]]></DEPENDANT_MODULE_NAME>
 <!--824D60CB352E4099B1D8C903CA139DAE-->  <DEPENDENCY_ENFORCEMENT><![CDATA[MAJOR]]></DEPENDENCY_ENFORCEMENT>
@@ -49,7 +49,7 @@
 <!--E8FD820AFE3D4FE08C02FC47769026AD-->  <ISACTIVE><![CDATA[Y]]></ISACTIVE>
 <!--E8FD820AFE3D4FE08C02FC47769026AD-->  <AD_MODULE_ID><![CDATA[9BA0836A3CD74EE4AB48753A47211BCC]]></AD_MODULE_ID>
 <!--E8FD820AFE3D4FE08C02FC47769026AD-->  <AD_DEPENDENT_MODULE_ID><![CDATA[EC356CEE3D46416CA1EBEEB9AB82EDB9]]></AD_DEPENDENT_MODULE_ID>
-<!--E8FD820AFE3D4FE08C02FC47769026AD-->  <STARTVERSION><![CDATA[8.1.13698]]></STARTVERSION>
+<!--E8FD820AFE3D4FE08C02FC47769026AD-->  <STARTVERSION><![CDATA[8.1.13966]]></STARTVERSION>
 <!--E8FD820AFE3D4FE08C02FC47769026AD-->  <ISINCLUDED><![CDATA[N]]></ISINCLUDED>
 <!--E8FD820AFE3D4FE08C02FC47769026AD-->  <DEPENDANT_MODULE_NAME><![CDATA[Smartclient]]></DEPENDANT_MODULE_NAME>
 <!--E8FD820AFE3D4FE08C02FC47769026AD-->  <DEPENDENCY_ENFORCEMENT><![CDATA[MAJOR]]></DEPENDENCY_ENFORCEMENT>
--- a/modules/org.openbravo.client.application/src-db/database/sourcedata/AD_REFERENCE.xml	Thu Oct 13 18:24:25 2011 +0200
+++ b/modules/org.openbravo.client.application/src-db/database/sourcedata/AD_REFERENCE.xml	Thu Oct 20 13:09:18 2011 +0200
@@ -13,4 +13,18 @@
 <!--D6193AA7FAB6429C8F34249FBF5A5F50-->  <ISVALUEDISPLAYED><![CDATA[N]]></ISVALUEDISPLAYED>
 <!--D6193AA7FAB6429C8F34249FBF5A5F50--></AD_REFERENCE>
 
+<!--FF8081813201F2DE013201F5628C0003--><AD_REFERENCE>
+<!--FF8081813201F2DE013201F5628C0003-->  <AD_REFERENCE_ID><![CDATA[FF8081813201F2DE013201F5628C0003]]></AD_REFERENCE_ID>
+<!--FF8081813201F2DE013201F5628C0003-->  <AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID>
+<!--FF8081813201F2DE013201F5628C0003-->  <AD_ORG_ID><![CDATA[0]]></AD_ORG_ID>
+<!--FF8081813201F2DE013201F5628C0003-->  <ISACTIVE><![CDATA[Y]]></ISACTIVE>
+<!--FF8081813201F2DE013201F5628C0003-->  <NAME><![CDATA[Personalization Type]]></NAME>
+<!--FF8081813201F2DE013201F5628C0003-->  <DESCRIPTION><![CDATA[The type of the personalization record]]></DESCRIPTION>
+<!--FF8081813201F2DE013201F5628C0003-->  <HELP><![CDATA[The type of the personalization record]]></HELP>
+<!--FF8081813201F2DE013201F5628C0003-->  <AD_MODULE_ID><![CDATA[9BA0836A3CD74EE4AB48753A47211BCC]]></AD_MODULE_ID>
+<!--FF8081813201F2DE013201F5628C0003-->  <ISBASEREFERENCE><![CDATA[N]]></ISBASEREFERENCE>
+<!--FF8081813201F2DE013201F5628C0003-->  <PARENTREFERENCE_ID><![CDATA[17]]></PARENTREFERENCE_ID>
+<!--FF8081813201F2DE013201F5628C0003-->  <ISVALUEDISPLAYED><![CDATA[N]]></ISVALUEDISPLAYED>
+<!--FF8081813201F2DE013201F5628C0003--></AD_REFERENCE>
+
 </data>
--- a/modules/org.openbravo.client.application/src-db/database/sourcedata/AD_REF_LIST.xml	Thu Oct 13 18:24:25 2011 +0200
+++ b/modules/org.openbravo.client.application/src-db/database/sourcedata/AD_REF_LIST.xml	Thu Oct 20 13:09:18 2011 +0200
@@ -170,7 +170,7 @@
 <!--FF8081812E9F4334012E9F4855820012-->  <AD_ORG_ID><![CDATA[0]]></AD_ORG_ID>
 <!--FF8081812E9F4334012E9F4855820012-->  <ISACTIVE><![CDATA[Y]]></ISACTIVE>
 <!--FF8081812E9F4334012E9F4855820012-->  <VALUE><![CDATA[OBUIAPP_RecentDocumentsList]]></VALUE>
-<!--FF8081812E9F4334012E9F4855820012-->  <NAME><![CDATA[OBUIAPP_RecentDocumentsList]]></NAME>
+<!--FF8081812E9F4334012E9F4855820012-->  <NAME><![CDATA[Recent Documents List Setting]]></NAME>
 <!--FF8081812E9F4334012E9F4855820012-->  <DESCRIPTION><![CDATA[Recent documents opened by the user]]></DESCRIPTION>
 <!--FF8081812E9F4334012E9F4855820012-->  <AD_REFERENCE_ID><![CDATA[A26BA480E2014707B47257024C3CBFF7]]></AD_REFERENCE_ID>
 <!--FF8081812E9F4334012E9F4855820012-->  <AD_MODULE_ID><![CDATA[9BA0836A3CD74EE4AB48753A47211BCC]]></AD_MODULE_ID>
@@ -200,4 +200,43 @@
 <!--FF80818131899595013189D97101005B-->  <AD_MODULE_ID><![CDATA[9BA0836A3CD74EE4AB48753A47211BCC]]></AD_MODULE_ID>
 <!--FF80818131899595013189D97101005B--></AD_REF_LIST>
 
+<!--FF8081813201F2DE013201F5AB740007--><AD_REF_LIST>
+<!--FF8081813201F2DE013201F5AB740007-->  <AD_REF_LIST_ID><![CDATA[FF8081813201F2DE013201F5AB740007]]></AD_REF_LIST_ID>
+<!--FF8081813201F2DE013201F5AB740007-->  <AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID>
+<!--FF8081813201F2DE013201F5AB740007-->  <AD_ORG_ID><![CDATA[0]]></AD_ORG_ID>
+<!--FF8081813201F2DE013201F5AB740007-->  <ISACTIVE><![CDATA[Y]]></ISACTIVE>
+<!--FF8081813201F2DE013201F5AB740007-->  <VALUE><![CDATA[Form]]></VALUE>
+<!--FF8081813201F2DE013201F5AB740007-->  <NAME><![CDATA[Form]]></NAME>
+<!--FF8081813201F2DE013201F5AB740007-->  <DESCRIPTION><![CDATA[Form]]></DESCRIPTION>
+<!--FF8081813201F2DE013201F5AB740007-->  <AD_REFERENCE_ID><![CDATA[FF8081813201F2DE013201F5628C0003]]></AD_REFERENCE_ID>
+<!--FF8081813201F2DE013201F5AB740007-->  <AD_MODULE_ID><![CDATA[9BA0836A3CD74EE4AB48753A47211BCC]]></AD_MODULE_ID>
+<!--FF8081813201F2DE013201F5AB740007-->  <SEQNO><![CDATA[10]]></SEQNO>
+<!--FF8081813201F2DE013201F5AB740007--></AD_REF_LIST>
+
+<!--FF8081813201F2DE013201F6127C000B--><AD_REF_LIST>
+<!--FF8081813201F2DE013201F6127C000B-->  <AD_REF_LIST_ID><![CDATA[FF8081813201F2DE013201F6127C000B]]></AD_REF_LIST_ID>
+<!--FF8081813201F2DE013201F6127C000B-->  <AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID>
+<!--FF8081813201F2DE013201F6127C000B-->  <AD_ORG_ID><![CDATA[0]]></AD_ORG_ID>
+<!--FF8081813201F2DE013201F6127C000B-->  <ISACTIVE><![CDATA[Y]]></ISACTIVE>
+<!--FF8081813201F2DE013201F6127C000B-->  <VALUE><![CDATA[Window]]></VALUE>
+<!--FF8081813201F2DE013201F6127C000B-->  <NAME><![CDATA[Window]]></NAME>
+<!--FF8081813201F2DE013201F6127C000B-->  <DESCRIPTION><![CDATA[Window]]></DESCRIPTION>
+<!--FF8081813201F2DE013201F6127C000B-->  <AD_REFERENCE_ID><![CDATA[FF8081813201F2DE013201F5628C0003]]></AD_REFERENCE_ID>
+<!--FF8081813201F2DE013201F6127C000B-->  <AD_MODULE_ID><![CDATA[9BA0836A3CD74EE4AB48753A47211BCC]]></AD_MODULE_ID>
+<!--FF8081813201F2DE013201F6127C000B-->  <SEQNO><![CDATA[20]]></SEQNO>
+<!--FF8081813201F2DE013201F6127C000B--></AD_REF_LIST>
+
+<!--FF80818132443EBA01324440CCE80007--><AD_REF_LIST>
+<!--FF80818132443EBA01324440CCE80007-->  <AD_REF_LIST_ID><![CDATA[FF80818132443EBA01324440CCE80007]]></AD_REF_LIST_ID>
+<!--FF80818132443EBA01324440CCE80007-->  <AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID>
+<!--FF80818132443EBA01324440CCE80007-->  <AD_ORG_ID><![CDATA[0]]></AD_ORG_ID>
+<!--FF80818132443EBA01324440CCE80007-->  <ISACTIVE><![CDATA[Y]]></ISACTIVE>
+<!--FF80818132443EBA01324440CCE80007-->  <VALUE><![CDATA[OBUIAPP_DefaultSavedView]]></VALUE>
+<!--FF80818132443EBA01324440CCE80007-->  <NAME><![CDATA[Default View Setting]]></NAME>
+<!--FF80818132443EBA01324440CCE80007-->  <DESCRIPTION><![CDATA[The id of the default view for the user]]></DESCRIPTION>
+<!--FF80818132443EBA01324440CCE80007-->  <AD_REFERENCE_ID><![CDATA[A26BA480E2014707B47257024C3CBFF7]]></AD_REFERENCE_ID>
+<!--FF80818132443EBA01324440CCE80007-->  <AD_MODULE_ID><![CDATA[9BA0836A3CD74EE4AB48753A47211BCC]]></AD_MODULE_ID>
+<!--FF80818132443EBA01324440CCE80007-->  <SEQNO><![CDATA[100]]></SEQNO>
+<!--FF80818132443EBA01324440CCE80007--></AD_REF_LIST>
+
 </data>
--- a/modules/org.openbravo.client.application/src-db/database/sourcedata/AD_TREENODE.xml	Thu Oct 13 18:24:25 2011 +0200
+++ b/modules/org.openbravo.client.application/src-db/database/sourcedata/AD_TREENODE.xml	Thu Oct 20 13:09:18 2011 +0200
@@ -11,6 +11,17 @@
 <!--258D19F188E94196936EF06CF608664C-->  <SEQNO><![CDATA[40]]></SEQNO>
 <!--258D19F188E94196936EF06CF608664C--></AD_TREENODE>
 
+<!--52118BF1A3E74D84E040007F01005FEC--><AD_TREENODE>
+<!--52118BF1A3E74D84E040007F01005FEC-->  <AD_TREENODE_ID><![CDATA[52118BF1A3E74D84E040007F01005FEC]]></AD_TREENODE_ID>
+<!--52118BF1A3E74D84E040007F01005FEC-->  <AD_TREE_ID><![CDATA[10]]></AD_TREE_ID>
+<!--52118BF1A3E74D84E040007F01005FEC-->  <NODE_ID><![CDATA[1005400002]]></NODE_ID>
+<!--52118BF1A3E74D84E040007F01005FEC-->  <AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID>
+<!--52118BF1A3E74D84E040007F01005FEC-->  <AD_ORG_ID><![CDATA[0]]></AD_ORG_ID>
+<!--52118BF1A3E74D84E040007F01005FEC-->  <ISACTIVE><![CDATA[Y]]></ISACTIVE>
+<!--52118BF1A3E74D84E040007F01005FEC-->  <PARENT_ID><![CDATA[161]]></PARENT_ID>
+<!--52118BF1A3E74D84E040007F01005FEC-->  <SEQNO><![CDATA[260]]></SEQNO>
+<!--52118BF1A3E74D84E040007F01005FEC--></AD_TREENODE>
+
 <!--76DC645312694D7A8E686BF48C3B490C--><AD_TREENODE>
 <!--76DC645312694D7A8E686BF48C3B490C-->  <AD_TREENODE_ID><![CDATA[76DC645312694D7A8E686BF48C3B490C]]></AD_TREENODE_ID>
 <!--76DC645312694D7A8E686BF48C3B490C-->  <AD_TREE_ID><![CDATA[10]]></AD_TREE_ID>
--- a/modules/org.openbravo.client.application/src-db/database/sourcedata/OBCLKER_TEMPLATE_DEPENDENCY.xml	Thu Oct 13 18:24:25 2011 +0200
+++ b/modules/org.openbravo.client.application/src-db/database/sourcedata/OBCLKER_TEMPLATE_DEPENDENCY.xml	Thu Oct 20 13:09:18 2011 +0200
@@ -1,12 +1,13 @@
 <?xml version='1.0' encoding='UTF-8'?>
 <data>
-<!--76A793FCC33848C1835159B8E6C5FCAB--><OBCLKER_TEMPLATE_DEPENDENCY>
-<!--76A793FCC33848C1835159B8E6C5FCAB-->  <OBCLKER_TEMPLATE_DEPENDENCY_ID><![CDATA[76A793FCC33848C1835159B8E6C5FCAB]]></OBCLKER_TEMPLATE_DEPENDENCY_ID>
-<!--76A793FCC33848C1835159B8E6C5FCAB-->  <AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID>
-<!--76A793FCC33848C1835159B8E6C5FCAB-->  <AD_ORG_ID><![CDATA[0]]></AD_ORG_ID>
-<!--76A793FCC33848C1835159B8E6C5FCAB-->  <OBCLKER_TEMPLATE_ID><![CDATA[C1D176407A354A40815DC46D24D70EB8]]></OBCLKER_TEMPLATE_ID>
-<!--76A793FCC33848C1835159B8E6C5FCAB-->  <DEPENDSON_TEMPLATE_ID><![CDATA[33E04D0799794C6F95F05149D2E04E78]]></DEPENDSON_TEMPLATE_ID>
-<!--76A793FCC33848C1835159B8E6C5FCAB-->  <ISACTIVE><![CDATA[Y]]></ISACTIVE>
-<!--76A793FCC33848C1835159B8E6C5FCAB--></OBCLKER_TEMPLATE_DEPENDENCY>
+<!--FF808181324E2FEC01324E3F2E620015--><OBCLKER_TEMPLATE_DEPENDENCY>
+<!--FF808181324E2FEC01324E3F2E620015-->  <OBCLKER_TEMPLATE_DEPENDENCY_ID><![CDATA[FF808181324E2FEC01324E3F2E620015]]></OBCLKER_TEMPLATE_DEPENDENCY_ID>
+<!--FF808181324E2FEC01324E3F2E620015-->  <AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID>
+<!--FF808181324E2FEC01324E3F2E620015-->  <AD_ORG_ID><![CDATA[0]]></AD_ORG_ID>
+<!--FF808181324E2FEC01324E3F2E620015-->  <OBCLKER_TEMPLATE_ID><![CDATA[B5124C0A450D4D3A867AEAC7DF64D6F0]]></OBCLKER_TEMPLATE_ID>
+<!--FF808181324E2FEC01324E3F2E620015-->  <DEPENDSON_TEMPLATE_ID><![CDATA[33E04D0799794C6F95F05149D2E04E78]]></DEPENDSON_TEMPLATE_ID>
+<!--FF808181324E2FEC01324E3F2E620015-->  <DESCRIPTION><![CDATA[Field Template]]></DESCRIPTION>
+<!--FF808181324E2FEC01324E3F2E620015-->  <ISACTIVE><![CDATA[Y]]></ISACTIVE>
+<!--FF808181324E2FEC01324E3F2E620015--></OBCLKER_TEMPLATE_DEPENDENCY>
 
 </data>
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/modules/org.openbravo.client.application/src-db/database/sourcedata/OBUIAPP_MENU_PARAMETERS.xml	Thu Oct 20 13:09:18 2011 +0200
@@ -0,0 +1,25 @@
+<?xml version='1.0' encoding='UTF-8'?>
+<data>
+<!--FF808081329B023101329B110E0F0027--><OBUIAPP_MENU_PARAMETERS>
+<!--FF808081329B023101329B110E0F0027-->  <OBUIAPP_MENU_PARAMETERS_ID><![CDATA[FF808081329B023101329B110E0F0027]]></OBUIAPP_MENU_PARAMETERS_ID>
+<!--FF808081329B023101329B110E0F0027-->  <AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID>
+<!--FF808081329B023101329B110E0F0027-->  <AD_ORG_ID><![CDATA[0]]></AD_ORG_ID>
+<!--FF808081329B023101329B110E0F0027-->  <AD_MODULE_ID><![CDATA[9BA0836A3CD74EE4AB48753A47211BCC]]></AD_MODULE_ID>
+<!--FF808081329B023101329B110E0F0027-->  <AD_MENU_ID><![CDATA[1005400002]]></AD_MENU_ID>
+<!--FF808081329B023101329B110E0F0027-->  <NAME><![CDATA[popup]]></NAME>
+<!--FF808081329B023101329B110E0F0027-->  <PARAMETERVALUE><![CDATA[true]]></PARAMETERVALUE>
+<!--FF808081329B023101329B110E0F0027-->  <ISACTIVE><![CDATA[Y]]></ISACTIVE>
+<!--FF808081329B023101329B110E0F0027--></OBUIAPP_MENU_PARAMETERS>
+
+<!--FF808081329B023101329B1188FA002B--><OBUIAPP_MENU_PARAMETERS>
+<!--FF808081329B023101329B1188FA002B-->  <OBUIAPP_MENU_PARAMETERS_ID><![CDATA[FF808081329B023101329B1188FA002B]]></OBUIAPP_MENU_PARAMETERS_ID>
+<!--FF808081329B023101329B1188FA002B-->  <AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID>
+<!--FF808081329B023101329B1188FA002B-->  <AD_ORG_ID><![CDATA[0]]></AD_ORG_ID>
+<!--FF808081329B023101329B1188FA002B-->  <AD_MODULE_ID><![CDATA[9BA0836A3CD74EE4AB48753A47211BCC]]></AD_MODULE_ID>
+<!--FF808081329B023101329B1188FA002B-->  <AD_MENU_ID><![CDATA[1005400002]]></AD_MENU_ID>
+<!--FF808081329B023101329B1188FA002B-->  <NAME><![CDATA[showsItself]]></NAME>
+<!--FF808081329B023101329B1188FA002B-->  <PARAMETERVALUE><![CDATA[true]]></PARAMETERVALUE>
+<!--FF808081329B023101329B1188FA002B-->  <ISACTIVE><![CDATA[Y]]></ISACTIVE>
+<!--FF808081329B023101329B1188FA002B--></OBUIAPP_MENU_PARAMETERS>
+
+</data>
--- a/modules/org.openbravo.client.application/src-db/database/sourcedata/OBUIAPP_VIEW_IMPL.xml	Thu Oct 13 18:24:25 2011 +0200
+++ b/modules/org.openbravo.client.application/src-db/database/sourcedata/OBUIAPP_VIEW_IMPL.xml	Thu Oct 20 13:09:18 2011 +0200
@@ -9,4 +9,14 @@
 <!--FF8080812EB90459012EBA225DDB0029-->  <ISACTIVE><![CDATA[Y]]></ISACTIVE>
 <!--FF8080812EB90459012EBA225DDB0029--></OBUIAPP_VIEW_IMPL>
 
+<!--FF808081329B023101329B0CE2080013--><OBUIAPP_VIEW_IMPL>
+<!--FF808081329B023101329B0CE2080013-->  <OBUIAPP_VIEW_IMPL_ID><![CDATA[FF808081329B023101329B0CE2080013]]></OBUIAPP_VIEW_IMPL_ID>
+<!--FF808081329B023101329B0CE2080013-->  <AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID>
+<!--FF808081329B023101329B0CE2080013-->  <AD_ORG_ID><![CDATA[0]]></AD_ORG_ID>
+<!--FF808081329B023101329B0CE2080013-->  <AD_MODULE_ID><![CDATA[9BA0836A3CD74EE4AB48753A47211BCC]]></AD_MODULE_ID>
+<!--FF808081329B023101329B0CE2080013-->  <NAME><![CDATA[OBUIAPP_RegistrationView]]></NAME>
+<!--FF808081329B023101329B0CE2080013-->  <DESCRIPTION><![CDATA[Opens registration popup]]></DESCRIPTION>
+<!--FF808081329B023101329B0CE2080013-->  <ISACTIVE><![CDATA[Y]]></ISACTIVE>
+<!--FF808081329B023101329B0CE2080013--></OBUIAPP_VIEW_IMPL>
+
 </data>
--- a/modules/org.openbravo.client.application/src/org/openbravo/client/application/ApplicationComponentProvider.java	Thu Oct 13 18:24:25 2011 +0200
+++ b/modules/org.openbravo.client.application/src/org/openbravo/client/application/ApplicationComponentProvider.java	Thu Oct 20 13:09:18 2011 +0200
@@ -195,6 +195,8 @@
     globalResources.add(createStaticResource(
         "web/org.openbravo.client.application/js/grid/ob-view-grid.js", false));
     globalResources.add(createStaticResource(
+        "web/org.openbravo.client.application/js/form/ob-onchange-registry.js", false));
+    globalResources.add(createStaticResource(
         "web/org.openbravo.client.application/js/utilities/ob-keyboard-manager.js", false));
     globalResources.add(createStaticResource(
         "web/org.openbravo.client.application/js/classic/ob-classic-popup.js", false));
@@ -240,6 +242,16 @@
         .add(createStaticResource(
             "web/org.openbravo.client.application/js/personalization/ob-personalize-form-toolbar-button.js",
             false));
+    globalResources.add(createStaticResource(
+        "web/org.openbravo.client.application/js/personalization/ob-manage-views.js", false));
+    globalResources
+        .add(createStaticResource(
+            "web/org.openbravo.client.application/js/personalization/ob-manage-views-popups.js",
+            false));
+    globalResources
+        .add(createStaticResource(
+            "web/org.openbravo.client.application/js/personalization/ob-manage-views-toolbar.js",
+            false));
 
     // Styling
     globalResources.add(createStyleSheetResource(
--- a/modules/org.openbravo.client.application/src/org/openbravo/client/application/StorePropertyActionHandler.java	Thu Oct 13 18:24:25 2011 +0200
+++ b/modules/org.openbravo.client.application/src/org/openbravo/client/application/StorePropertyActionHandler.java	Thu Oct 20 13:09:18 2011 +0200
@@ -54,7 +54,10 @@
         return new JSONObject(
             "{msg: 'No property name in request, ignoring property store request'}");
       }
-      final String cleanedData = data == null ? null : data.replaceAll("\\n", "");
+      String cleanedData = data == null ? null : data.replaceAll("\\n", "");
+      if (cleanedData != null && cleanedData.startsWith("\"") && cleanedData.endsWith("\"")) {
+        cleanedData = cleanedData.substring(1, cleanedData.length() - 1);
+      }
       String windowId = (String) parameters.get("windowId");
       Window window = null;
       if (windowId != null) {
--- a/modules/org.openbravo.client.application/src/org/openbravo/client/application/personalization/PersonalizationActionHandler.java	Thu Oct 13 18:24:25 2011 +0200
+++ b/modules/org.openbravo.client.application/src/org/openbravo/client/application/personalization/PersonalizationActionHandler.java	Thu Oct 20 13:09:18 2011 +0200
@@ -26,6 +26,7 @@
 import org.codehaus.jettison.json.JSONObject;
 import org.openbravo.base.exception.OBException;
 import org.openbravo.client.application.UIPersonalization;
+import org.openbravo.client.application.window.OBViewFieldHandler;
 import org.openbravo.client.application.window.OBViewFormComponent;
 import org.openbravo.client.kernel.BaseActionHandler;
 import org.openbravo.dal.core.OBContext;
@@ -53,6 +54,7 @@
   private static final String ROLEID = "roleId";
   private static final String USERID = "userId";
   private static final String TABID = "tabId";
+  private static final String WINDOWID = "windowId";
 
   @Inject
   private PersonalizationHandler personalizationHandler;
@@ -60,6 +62,9 @@
   @Inject
   private OBViewFormComponent viewFormComponent;
 
+  @Inject
+  private OBViewFieldHandler fieldHandler;
+
   protected JSONObject execute(Map<String, Object> parameters, String data) {
 
     try {
@@ -67,34 +72,37 @@
       if (!parameters.containsKey(ACTION)) {
         throw new IllegalStateException("Mandatory parameter " + ACTION + " not present");
       }
-      if (!parameters.containsKey(PERSONALIZATIONID) && !parameters.containsKey(TABID)) {
-        throw new IllegalStateException("Mandatory parameter " + TABID + " not present");
+      if (!parameters.containsKey(PERSONALIZATIONID) && !parameters.containsKey(TABID)
+          && !parameters.containsKey(WINDOWID)) {
+        throw new IllegalStateException("Mandatory parameter " + TABID + "/" + WINDOWID
+            + " not present");
       }
       final String action = (String) parameters.get(ACTION);
       final String tabId = (String) parameters.get(TABID);
+      final String windowId = (String) parameters.get(WINDOWID);
       if (action.equals(ACTION_DELETE)) {
         final String persId = (String) parameters.get(PERSONALIZATIONID);
         final UIPersonalization uiPersonalization = OBDal.getInstance().get(
             UIPersonalization.class, persId);
-        OBDal.getInstance().remove(uiPersonalization);
+        if (uiPersonalization != null) {
+          // is null if already removed
+          OBDal.getInstance().remove(uiPersonalization);
+        }
         return new JSONObject().put("result", "success");
       } else if (action.equals(ACTION_STORE)) {
-        final UIPersonalization uiPersonalization = personalizationHandler.storePersonalization(
-            (String) parameters.get(PERSONALIZATIONID), (String) parameters.get(CLIENTID),
-            (String) parameters.get(ORGID), (String) parameters.get(ROLEID),
-            (String) parameters.get(USERID), tabId, (String) parameters.get(TARGET), data);
+        final UIPersonalization uiPersonalization = personalizationHandler
+            .storePersonalization((String) parameters.get(PERSONALIZATIONID),
+                (String) parameters.get(CLIENTID), (String) parameters.get(ORGID),
+                (String) parameters.get(ROLEID), (String) parameters.get(USERID), tabId, windowId,
+                (String) parameters.get(TARGET), data);
         final JSONObject result = new JSONObject();
-        if (uiPersonalization.getUser() != null
-            && uiPersonalization.getUser().getId()
-                .equals(OBContext.getOBContext().getUser().getId())) {
-          result.put("canDelete", true);
-        }
         result.put("personalizationId", uiPersonalization.getId());
         return result;
       } else if (action.equals(ACTION_FORM)) {
         viewFormComponent.setParameters(parameters);
         viewFormComponent.setTemplateId(TEMPLATE_ID);
-        viewFormComponent.setTab(OBDal.getInstance().get(Tab.class, tabId));
+        fieldHandler.setTab(OBDal.getInstance().get(Tab.class, tabId));
+        viewFormComponent.setFieldHandler(fieldHandler);
         final String formJS = viewFormComponent.generate();
         final JSONObject formProps = new JSONObject(formJS);
         return formProps;
--- a/modules/org.openbravo.client.application/src/org/openbravo/client/application/personalization/PersonalizationHandler.java	Thu Oct 13 18:24:25 2011 +0200
+++ b/modules/org.openbravo.client.application/src/org/openbravo/client/application/personalization/PersonalizationHandler.java	Thu Oct 20 13:09:18 2011 +0200
@@ -20,21 +20,30 @@
 package org.openbravo.client.application.personalization;
 
 import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Comparator;
+import java.util.HashMap;
 import java.util.List;
+import java.util.Map;
 
 import javax.enterprise.context.RequestScoped;
 
 import org.apache.log4j.Logger;
+import org.codehaus.jettison.json.JSONArray;
+import org.codehaus.jettison.json.JSONException;
 import org.codehaus.jettison.json.JSONObject;
 import org.openbravo.base.exception.OBException;
 import org.openbravo.base.provider.OBProvider;
+import org.openbravo.client.application.ApplicationUtils;
 import org.openbravo.client.application.UIPersonalization;
 import org.openbravo.dal.core.DalUtil;
 import org.openbravo.dal.core.OBContext;
 import org.openbravo.dal.service.OBDal;
 import org.openbravo.dal.service.OBQuery;
 import org.openbravo.model.ad.access.Role;
+import org.openbravo.model.ad.access.RoleOrganization;
 import org.openbravo.model.ad.access.User;
+import org.openbravo.model.ad.access.UserRoles;
 import org.openbravo.model.ad.system.Client;
 import org.openbravo.model.ad.ui.Tab;
 import org.openbravo.model.ad.ui.Window;
@@ -43,11 +52,10 @@
 /**
  * Handles personalization settings, stores them and retrieves them, taking into account priority
  * order.
- * 
  */
 @RequestScoped
 public class PersonalizationHandler {
-  private static final Logger log4j = Logger.getLogger(PersonalizationHandler.class);
+  private static final Logger log = Logger.getLogger(PersonalizationHandler.class);
 
   /**
    * Returns all the personalization settings in an object keyed by tabid. The current client, org,
@@ -61,21 +69,58 @@
   public JSONObject getPersonalizationForWindow(Window window) {
     OBContext.setAdminMode(false);
     try {
-      final JSONObject result = new JSONObject();
+      // first get the form layouts per tab
+      final JSONObject formPersonalization = new JSONObject();
       for (Tab tab : window.getADTabList()) {
         final UIPersonalization uiPersonalization = getPersonalizationForTab(tab);
         if (uiPersonalization == null || uiPersonalization.getValue() == null) {
-          result.put(tab.getId(), (Object) null);
+          formPersonalization.put(tab.getId(), (Object) null);
         } else {
-          final JSONObject persJSON = new JSONObject(uiPersonalization.getValue());
-          // if on user level then allow delete
-          if (uiPersonalization.getUser() != null) {
-            persJSON.put("canDelete", true);
+          try {
+            final JSONObject persJSON = new JSONObject(uiPersonalization.getValue());
+            // if on user level then allow delete
+            if (uiPersonalization.getUser() != null) {
+              persJSON.put("canDelete", true);
+            }
+            persJSON.put("personalizationId", uiPersonalization.getId());
+            formPersonalization.put(tab.getId(), persJSON);
+          } catch (Exception e) {
+            // on purpose not rethrowing to be robust
+            log.error("Exception when getting personalization records for window " + window, e);
           }
-          persJSON.put("personalizationId", uiPersonalization.getId());
-          result.put(tab.getId(), persJSON);
         }
       }
+
+      final List<RoleOrganization> adminOrgs = ApplicationUtils.getAdminOrgs();
+      final List<UserRoles> adminRoles = ApplicationUtils.getAdminRoles();
+
+      // and get the personalization records on view level
+      final List<UIPersonalization> personalizations = getPersonalizationsForWindow(window);
+      final JSONArray windowPersonalization = new JSONArray();
+      for (UIPersonalization uiPersonalization : personalizations) {
+        try {
+          final JSONObject persJSON = new JSONObject(uiPersonalization.getValue());
+
+          if (canEdit(uiPersonalization, adminOrgs, adminRoles)) {
+            persJSON.put("canEdit", true);
+          }
+
+          persJSON.put("clientId", getNullOrId(uiPersonalization.getVisibleAtClient()));
+          persJSON.put("orgId", getNullOrId(uiPersonalization.getVisibleAtOrganization()));
+          persJSON.put("roleId", getNullOrId(uiPersonalization.getVisibleAtRole()));
+          persJSON.put("userId", getNullOrId(uiPersonalization.getUser()));
+          persJSON.put("personalizationId", uiPersonalization.getId());
+          windowPersonalization.put(persJSON);
+        } catch (Exception e) {
+          // on purpose not rethrowing to be robust
+          log.error("Exception when getting personalization records for window " + window, e);
+        }
+      }
+
+      final JSONObject result = new JSONObject();
+      result.put("forms", formPersonalization);
+      result.put("views", windowPersonalization);
+      result.put("formData", getAdminFormSettings(adminOrgs, adminRoles));
       return result;
     } catch (Exception e) {
       throw new OBException("Exception when getting personalization settings for window " + window,
@@ -85,6 +130,94 @@
     }
   }
 
+  private boolean canEdit(UIPersonalization uiPersonalization, List<RoleOrganization> adminOrgs,
+      final List<UserRoles> adminRoles) {
+    // if on user level then allow delete
+    if (uiPersonalization.getUser() != null) {
+      return true;
+    }
+    if (ApplicationUtils.isClientAdmin() && uiPersonalization.getVisibleAtClient() != null) {
+      return true;
+    }
+    if (uiPersonalization.getVisibleAtOrganization() != null) {
+      final String orgId = (String) DalUtil.getId(uiPersonalization.getVisibleAtOrganization());
+      for (RoleOrganization roleOrg : adminOrgs) {
+        if (DalUtil.getId(roleOrg).equals(orgId)) {
+          return true;
+        }
+      }
+    }
+    if (uiPersonalization.getVisibleAtRole() != null) {
+      final String roleId = (String) DalUtil.getId(uiPersonalization.getVisibleAtRole());
+      for (UserRoles userRole : adminRoles) {
+        if (DalUtil.getId(userRole.getRole()).equals(roleId)) {
+          return true;
+        }
+      }
+    }
+
+    return false;
+  }
+
+  private Object getNullOrId(Object object) {
+    if (object == null) {
+      return null;
+    }
+    return DalUtil.getId(object);
+  }
+
+  // when changing code here, also check the
+  // MyOpenbravoComponent.getAdminModeValueMap code
+  private JSONObject getAdminFormSettings(List<RoleOrganization> adminOrgs,
+      final List<UserRoles> adminRoles) {
+    final JSONObject result = new JSONObject();
+    if (!ApplicationUtils.isClientAdmin() && !ApplicationUtils.isOrgAdmin()
+        && !ApplicationUtils.isRoleAdmin()) {
+      return result;
+    }
+
+    try {
+
+      final Role currentRole = OBDal.getInstance().get(Role.class,
+          OBContext.getOBContext().getRole().getId());
+
+      if (currentRole.getId().equals("0")) {
+        result.put("system", true);
+        return result;
+      }
+
+      if (ApplicationUtils.isClientAdmin()) {
+        final JSONObject clientObject = new JSONObject();
+        clientObject.put(OBContext.getOBContext().getCurrentClient().getId(), OBContext
+            .getOBContext().getCurrentClient().getIdentifier());
+        result.put("clients", clientObject);
+      }
+
+      final Map<String, String> orgs = new HashMap<String, String>();
+      for (RoleOrganization currentRoleOrg : adminOrgs) {
+        orgs.put(currentRoleOrg.getOrganization().getId(), currentRoleOrg.getOrganization()
+            .getName());
+      }
+
+      final Map<String, String> roles = new HashMap<String, String>();
+      for (UserRoles currentUserRole : adminRoles) {
+        roles.put(currentUserRole.getRole().getId(), currentUserRole.getRole().getName());
+      }
+
+      if (orgs.size() > 0) {
+        result.put("orgs", orgs);
+      }
+      if (roles.size() > 0) {
+        result.put("roles", roles);
+      }
+
+      return result;
+    } catch (JSONException e) {
+      log.error("Error building 'Admin Mode' value map: " + e.getMessage(), e);
+    }
+    return result;
+  }
+
   /**
    * Returns all the personalization settings for a tab. The current client, org, role and user are
    * taken into account to find the correct personalization entry. If no personalization entries are
@@ -99,7 +232,7 @@
     try {
       return getPersonalization(OBContext.getOBContext().getCurrentClient().getId(), OBContext
           .getOBContext().getCurrentOrganization().getId(), OBContext.getOBContext().getRole()
-          .getId(), OBContext.getOBContext().getUser().getId(), tab.getId(), false);
+          .getId(), OBContext.getOBContext().getUser().getId(), tab.getId(), null, false);
     } catch (Exception e) {
       throw new OBException("Exception when getting personalization settings for tab " + tab, e);
     } finally {
@@ -107,18 +240,68 @@
     }
   }
 
+  // note will return the personalizations in order of their priority
+  private List<UIPersonalization> getPersonalizationsForWindow(Window window) {
+    OBContext.setAdminMode(false);
+    try {
+      final List<UIPersonalization> personalizations = getPersonalizations(OBContext.getOBContext()
+          .getCurrentClient().getId(), OBContext.getOBContext().getCurrentOrganization().getId(),
+          OBContext.getOBContext().getUser().getId(), OBContext.getOBContext().getRole().getId(),
+          null, window.getId(), false);
+      sortPersonalizations(personalizations);
+      return personalizations;
+    } catch (Exception e) {
+      throw new OBException("Exception when getting personalization settings for window " + window,
+          e);
+    } finally {
+      OBContext.restorePreviousMode();
+    }
+  }
+
+  private void sortPersonalizations(List<UIPersonalization> personalizations) {
+    final String orgId = OBContext.getOBContext().getCurrentOrganization().getId();
+
+    List<String> parentTree = null;
+    if (orgId != null) {
+      parentTree = OBContext.getOBContext()
+          .getOrganizationStructureProvider(OBContext.getOBContext().getCurrentClient().getId())
+          .getParentList(orgId, true);
+    }
+    Collections.sort(personalizations, new PersonalizationComparator(parentTree));
+  }
+
+  private static class PersonalizationComparator implements Comparator<UIPersonalization> {
+
+    private List<String> parentTree;
+
+    private PersonalizationComparator(List<String> parentTree) {
+      this.parentTree = parentTree;
+    }
+
+    @Override
+    public int compare(UIPersonalization o1, UIPersonalization o2) {
+      final int higherPriority = isHigherPriority(o1, o2, parentTree);
+      if (higherPriority == 1) {
+        return 1;
+      } else if (higherPriority == 2) {
+        return -1;
+      }
+      return 0;
+    }
+  }
+
   public UIPersonalization getPersonalization(String clientId, String orgId, String roleId,
-      String userId, String tabId, boolean exactMatch) {
+      String userId, String tabId, String windowId, boolean exactMatch) {
     OBContext.setAdminMode(false);
     try {
       final List<UIPersonalization> pers = getPersonalizations(clientId, orgId, userId, roleId,
-          tabId, exactMatch);
+          tabId, windowId, exactMatch);
       if (pers.isEmpty()) {
         return null;
       }
       if (exactMatch) {
         if (pers.size() > 1) {
-          log4j.warn("There are/is more than one ui personalization record "
+          log.warn("There are/is more than one ui personalization record "
               + "for a certain exact match, ignoring it, just picking the first one: "
               + pers.get(0));
         }
@@ -185,7 +368,7 @@
    * @return the persisted record
    */
   public UIPersonalization storePersonalization(String persId, String clientId, String orgId,
-      String roleId, String userId, String tabId, String target, String value) {
+      String roleId, String userId, String tabId, String windowId, String target, String value) {
     OBContext.setAdminMode(false);
     try {
       UIPersonalization uiPersonalization;
@@ -195,7 +378,8 @@
           throw new IllegalArgumentException("UI Personalization with id " + persId + " not found");
         }
       } else {
-        uiPersonalization = getPersonalization(clientId, orgId, roleId, userId, tabId, true);
+        uiPersonalization = getPersonalization(clientId, orgId, roleId, userId, tabId, windowId,
+            true);
       }
 
       if (uiPersonalization == null) {
@@ -203,25 +387,44 @@
         uiPersonalization.setClient(OBDal.getInstance().get(Client.class, "0"));
         uiPersonalization.setOrganization(OBDal.getInstance().get(Organization.class, "0"));
 
-        if (clientId != null) {
-          uiPersonalization.setVisibleAtClient(OBDal.getInstance().get(Client.class, clientId));
-          // also store it in that client
-          uiPersonalization.setClient(uiPersonalization.getVisibleAtClient());
-        }
-        if (orgId != null) {
-          uiPersonalization.setVisibleAtOrganization(OBDal.getInstance().get(Organization.class,
-              orgId));
+        if (tabId != null) {
+          uiPersonalization.setTab(OBDal.getInstance().get(Tab.class, tabId));
+          uiPersonalization.setType("Form");
         }
 
-        if (roleId != null) {
-          uiPersonalization.setVisibleAtRole(OBDal.getInstance().get(Role.class, roleId));
+        if (windowId != null) {
+          uiPersonalization.setWindow(OBDal.getInstance().get(Window.class, windowId));
+          uiPersonalization.setType("Window");
         }
+      }
 
-        if (userId != null) {
-          uiPersonalization.setUser(OBDal.getInstance().get(User.class, userId));
-        }
-        uiPersonalization.setTab(OBDal.getInstance().get(Tab.class, tabId));
+      if (clientId != null) {
+        uiPersonalization.setVisibleAtClient(OBDal.getInstance().get(Client.class, clientId));
+        // also store it in that client
+        uiPersonalization.setClient(uiPersonalization.getVisibleAtClient());
+      } else {
+        uiPersonalization.setVisibleAtClient(null);
       }
+
+      if (orgId != null) {
+        uiPersonalization.setVisibleAtOrganization(OBDal.getInstance().get(Organization.class,
+            orgId));
+      } else {
+        uiPersonalization.setVisibleAtOrganization(null);
+      }
+
+      if (roleId != null) {
+        uiPersonalization.setVisibleAtRole(OBDal.getInstance().get(Role.class, roleId));
+      } else {
+        uiPersonalization.setVisibleAtRole(null);
+      }
+
+      if (userId != null) {
+        uiPersonalization.setUser(OBDal.getInstance().get(User.class, userId));
+      } else {
+        uiPersonalization.setUser(null);
+      }
+
       final JSONObject jsonValue = new JSONObject(value);
       JSONObject jsonObject;
       if (uiPersonalization.getValue() != null) {
@@ -242,7 +445,7 @@
   }
 
   private static List<UIPersonalization> getPersonalizations(String clientId, String orgId,
-      String userId, String roleId, String tabId, boolean exactMatch) {
+      String userId, String roleId, String tabId, String windowId, boolean exactMatch) {
 
     List<Object> parameters = new ArrayList<Object>();
     StringBuilder hql = new StringBuilder();
@@ -307,8 +510,13 @@
       hql.append(" p.user is null) ");
     }
 
-    hql.append(" and  p.tab.id = ? ");
-    parameters.add(tabId);
+    if (tabId != null) {
+      hql.append(" and  p.tab.id = ? ");
+      parameters.add(tabId);
+    } else {
+      hql.append(" and  p.window.id = ? ");
+      parameters.add(windowId);
+    }
 
     OBQuery<UIPersonalization> qPers = OBDal.getInstance().createQuery(UIPersonalization.class,
         hql.toString());
--- a/modules/org.openbravo.client.application/src/org/openbravo/client/application/templates/ob-standard-view-window.js.ftl	Thu Oct 13 18:24:25 2011 +0200
+++ b/modules/org.openbravo.client.application/src/org/openbravo/client/application/templates/ob-standard-view-window.js.ftl	Thu Oct 20 13:09:18 2011 +0200
@@ -17,10 +17,10 @@
  * Contributor(s):  ______________________________________.
  ************************************************************************
 */
+// contains the code for creating a class reflecting the standard window
+// tell the view manager what got loaded...
 -->
-// contains the code for creating a class reflecting the standard window
-//jslint
-// tell the view manager what got loaded...
+/*jslint*/
 OB.Layout.ViewManager.loadedWindowClassName = '${data.windowClientClassName?js_string}';
 
 isc.ClassFactory.defineClass('${data.windowClientClassName?js_string}', isc.OBStandardWindow).addProperties({
--- a/modules/org.openbravo.client.application/src/org/openbravo/client/application/templates/ob-view-field.js.ftl	Thu Oct 13 18:24:25 2011 +0200
+++ b/modules/org.openbravo.client.application/src/org/openbravo/client/application/templates/ob-view-field.js.ftl	Thu Oct 20 13:09:18 2011 +0200
@@ -17,77 +17,135 @@
  * Contributor(s):  ______________________________________.
  ************************************************************************
 */
+
+Note, the below template contains many if statements to minimize the output if
+the outputted value is already covered by a default.
 -->
 
-<#macro createField fieldDefinition>
-    {
-        name: '${fieldDefinition.name?js_string}',
-        title: '${fieldDefinition.label?js_string}',
-        type: '${fieldDefinition.type}',
-        disabled: ${fieldDefinition.readOnly?string},
-        readonly: ${fieldDefinition.readOnly?string},
-        updatable: ${fieldDefinition.updatable?string},
-        parentProperty: ${fieldDefinition.parentProperty?string},
-        colSpan: ${fieldDefinition.colSpan},
-        rowSpan: ${fieldDefinition.rowSpan},
-        startRow: ${fieldDefinition.startRow?string},
-        endRow: ${fieldDefinition.endRow?string},
-        personalizable: ${fieldDefinition.personalizable?string},
-        hasDefaultValue: ${fieldDefinition.hasDefaultValue?string},
-        <#if fieldDefinition.standardField>
-        columnName: '${fieldDefinition.columnName?string}',
-        inpColumnName: '${fieldDefinition.inpColumnName?string}',
-        referencedKeyColumnName: '${fieldDefinition.referencedKeyColumnName?string}',
-        targetEntity: '${fieldDefinition.targetEntity?string}',
-        <#if !fieldDefinition.displayed>
-        visible: false,
-        displayed: false,
-        alwaysTakeSpace: false,
+<#macro createField field>
+{
+<@compress single_line=true>
+    name: '${field.name?js_string}',
+    <#if field.label != ''>
+        title: '${field.label?js_string}',
+    </#if>
+    <#if field.required>
+        required: ${field.required?string},
+    </#if>
+    <#if field.readOnly>
+        disabled: true,
+    </#if>
+    <#if !field.updatable>
+        updatable: false,
+    </#if>
+    <#if field.onChangeFunction??>
+        onChangeFunction: ${field.onChangeFunction?js_string},
+    </#if>
+    <#if field.sessionProperty>
+        sessionProperty: true,
+    </#if>
+    <#if field.parentProperty>
+        parentProperty: true,
+    </#if>
+    <#if field.showColSpan>
+        colSpan: ${field.colSpan},
+    </#if>
+    <#if field.rowSpan != 1>
+        rowSpan: ${field.rowSpan},
+    </#if>
+    <#if field.showStartRow>
+        startRow: ${field.startRow?string},
+    </#if>
+    <#if field.showEndRow>
+        endRow: ${field.endRow?string},
+    </#if>
+    <#if !field.personalizable>
+        personalizable: false,
+    </#if>
+    <#if field.hasDefaultValue>
+        hasDefaultValue: true,
+    </#if>
+</@compress>
+    <#if field.standardField>
+<@compress single_line=true>
+        <#if field.columnName != ''>
+            columnName: '${field.columnName?string}',
         </#if>
-        required: ${fieldDefinition.required?string},
-          <#if fieldDefinition.redrawOnChange?string = "true" && fieldDefinition.displayed>
-          redrawOnChange: true,
-          changed: function(form, item, value) {
-            if (this.pickValue && !this._pickedValue) {
-                return;
-            }
-            this.Super('changed', arguments);
-            form.onFieldChanged(form, item, value);
-            form.view.toolBar.refreshCustomButtonsView(form.view);
-          },
-          </#if>
-          <#if fieldDefinition.showIf != "" && fieldDefinition.displayed>
-          showIf: function(item, value, form, values) {            
-            var context = form.view.getContextInfo(false, true, true),
-                currentValues = values || form.view.getCurrentValues();
-            
-            OB.Utilities.fixNull250(currentValues);
-
-            return !this.hiddenInForm && context && (${fieldDefinition.showIf});
-          },          
-          </#if>
-          <#if fieldDefinition.searchField>
-          displayField: '${fieldDefinition.name?js_string}._identifier',
-          valueField: '${fieldDefinition.name?js_string}',
-          showPickerIcon: ${(!fieldDefinition.parentProperty)?string},
-          </#if>
-          <#if fieldDefinition.firstFocusedField>
-          firstFocusedField: true,
-          </#if>
+        <#if field.inpColumnName != ''>
+            inpColumnName: '${field.inpColumnName?string}',
         </#if>
-        <#if fieldDefinition.type = "OBSectionItem" || fieldDefinition.type = "OBNoteSectionItem" || fieldDefinition.type = "OBLinkedItemSectionItem"  || fieldDefinition.type = "OBAttachmentsSectionItem" || fieldDefinition.type = "OBAuditSectionItem">
-          <#if !fieldDefinition.displayed>
-          visible: false,
-          </#if>
-        sectionExpanded: ${fieldDefinition.expanded?string},
-        defaultValue: '${fieldDefinition.label?js_string}',
-        itemIds: [
-        <#list fieldDefinition.children as childField>
-        '${childField.name?js_string}'<#if childField_has_next>,</#if>
-        </#list>
-        ],
+        <#if field.referencedKeyColumnName != ''>
+            refColumnName: '${field.referencedKeyColumnName?string}',
         </#if>
-        ${fieldDefinition.fieldProperties}
-        dummy: ''
-    }
-</#macro>
+        <#if field.targetEntity != ''>
+            targetEntity: '${field.targetEntity?string}',
+        </#if>
+        <#if !field.displayed>
+            displayed: false,
+        </#if>
+        <#if field.redrawOnChange && field.displayed>
+            redrawOnChange: true,
+        </#if>
+        <#if field.showIf != "" && field.displayed>
+            showIf: function(item, value, form, currentValues, context) {
+                return (${field.showIf});          
+            },          
+        </#if>
+        <#if field.searchField>
+            displayField: '${field.name?js_string}._identifier',
+            <#if field.parentProperty>
+                showPickerIcon: ${(!field.parentProperty)?string},
+            </#if>
+        </#if>
+        <#if field.firstFocusedField>
+            firstFocusedField: true,
+        </#if>
+</@compress>
+    </#if>
+    <#if field.type = "OBSectionItem" || field.type = "OBNoteSectionItem" || field.type = "OBLinkedItemSectionItem"  || field.type = "OBAttachmentsSectionItem" || field.type = "OBAuditSectionItem">
+<@compress single_line=true>
+        <#if !field.displayed>
+            displayed: false,
+        </#if>
+        <#if field.expanded>
+            sectionExpanded: ${field.expanded?string},
+        </#if>
+        <#if field.label != ''>
+            defaultValue: '${field.label?js_string}',
+        </#if>
+        <#if field.hasChildren>
+            itemIds: [
+            <#list field.children as childField>
+            '${childField.name?js_string}'<#if childField_has_next>,</#if>
+            </#list>
+            ],
+        </#if>
+</@compress>
+    </#if>
+    ${field.fieldProperties}
+    <#if field.isGridProperty>
+<@compress single_line=true>
+        gridProps: {
+            sort: ${field.gridSort?string}
+            <#if field.autoExpand>
+                , autoExpand: ${field.autoExpand?string}
+            </#if>
+            <#if field.cellAlign??>
+                , cellAlign: '${field.cellAlign?js_string}'
+            </#if>
+            <#if !field.showInitiallyInGrid>
+                , showIf: '${field.showInitiallyInGrid?string}'
+            </#if>            
+            <#if field.gridEditorFieldProperties != "">
+                , editorProps: {
+                  ${field.gridEditorFieldProperties}
+                }
+            </#if>
+            ${field.gridFieldProperties}
+            ${field.filterEditorProperties}
+        },
+</@compress>
+    </#if>
+    type: '${field.type}'
+}
+</#macro>
\ No newline at end of file
--- a/modules/org.openbravo.client.application/src/org/openbravo/client/application/templates/ob-view-form.js.ftl	Thu Oct 13 18:24:25 2011 +0200
+++ b/modules/org.openbravo.client.application/src/org/openbravo/client/application/templates/ob-view-form.js.ftl	Thu Oct 20 13:09:18 2011 +0200
@@ -19,46 +19,29 @@
 */
 -->
 {
-    // use theFields instead of fields, when the form
-    // gets created, initialized, the datasource is
-    // set (ob-standard-view.js buildStructure) 
-    // causing re-initialization of the fields,
-    // removing the current ones and recreating new ones
-    // by using theFields, the form initially does not
-    // have fields, which prevents this initial destroy step
-    theFields: [
-    <#list data.fields as field>
-      <@createField field/><#if field_has_next>,</#if>
-    </#list>    
-    ],
-
-    statusBarFields: [
-    <#list data.statusBarFields as sbf>
-      '${sbf?js_string}'<#if sbf_has_next>,</#if>
-    </#list>
-    ],
-
+    <#if data.fieldHandler.hasStatusBarFields>
+    <#--
+    // this this is the view    
+    -->
+    statusBarFields: this.statusBarFields<#if data.fieldHandler.hasFieldsWithReadOnlyIf>,</#if>
+    </#if>
+    
+<#--
     // except for the fields all other form properties should be added to the formProperties
     // the formProperties are re-used for inline grid editing
+-->
+   <#if data.fieldHandler.hasFieldsWithReadOnlyIf>
     obFormProperties: {
       onFieldChanged: function(form, item, value) {
         var f = form || this,
             context = this.view.getContextInfo(false, true),
             currentValues = f.view.getCurrentValues(), otherItem;
-        <#list data.fields as field>
+        <#list data.fieldHandler.fields as field>
         <#if field.readOnlyIf != "">
-          otherItem = f.getItem('${field.name}');
-          if (otherItem && otherItem.disable && otherItem.enable) {
-            if (f.readOnly) {
-              otherItem.disable();
-            } else if(${field.readOnlyIf}) {
-              otherItem.disable();
-            } else {
-              otherItem.enable();
-            }
-          }
+            f.disableItem('${field.name}', ${field.readOnlyIf});
         </#if>
         </#list>
       }
     }
-}
+    </#if>
+}
\ No newline at end of file
--- a/modules/org.openbravo.client.application/src/org/openbravo/client/application/templates/ob-view-grid.js.ftl	Thu Oct 13 18:24:25 2011 +0200
+++ b/modules/org.openbravo.client.application/src/org/openbravo/client/application/templates/ob-view-grid.js.ftl	Thu Oct 20 13:09:18 2011 +0200
@@ -21,104 +21,23 @@
 
 isc.OBViewGrid.create({
     uiPattern: '${data.uiPattern}', 
-    fields:[
-    <#list data.fields as field>
-        { 
-        autoExpand: ${field.autoExpand}, type: '${field.type}',
-        <#if field.cellAlign??>
-        cellAlign: '${field.cellAlign?js_string}',
-        </#if>
-        editorProperties: {
-          ${field.gridEditorFieldProperties}
-          // note need to be repeated for editor fields
-          , columnName: '${field.columnName?js_string}'
-          , inpColumnName: '${field.inpColumnName?js_string}'
-          , referencedKeyColumnName: '${field.referencedKeyColumnName?js_string}'        
-          , targetEntity: '${field.targetEntity?js_string}'
-          , disabled: ${field.readOnly?string}
-          , readonly: ${field.readOnly?string}
-          , updatable: ${field.updatable?string}
-          <#if field.redrawOnChange?string = "true" >
-          , redrawOnChange: true
-          , changed: function(form, item, value) {
-              if (this.pickValue && !this._pickedValue) {
-                return;
-              }
-              this.Super('changed', arguments);
-              form.onFieldChanged(form, item, value);
-              form.view.toolBar.refreshCustomButtonsView(form.view);
-            }
-          </#if>
-          <#if field.firstFocusedField>
-          , firstFocusedField: true
-          </#if>          
-          <#if field.showIf != "">
-          , showIf: function(item, value, form, currentValues) {
-              currentValues = currentValues || form.view.getCurrentValues();
-              var context = form.view.getContextInfo(false, true);
-              return context && (${field.showIf});
-            }
-          </#if>
-          
-        }
-        ${field.gridFieldProperties}
-        ${field.filterEditorProperties}
-        , title: '${field.title?js_string}'
-        , prompt: '${field.title?js_string}'
-        , required: ${field.required?string}
-        , escapeHTML: true
-        , showIf: '${field.initialShow?string}'
-        , columnName: '${field.columnName?js_string}'
-        , inpColumnName: '${field.inpColumnName?js_string}'
-        , referencedKeyColumnName: '${field.referencedKeyColumnName?js_string}'        
-        , targetEntity: '${field.targetEntity?js_string}'
-       }
-       <#if field_has_next>,</#if>
-    </#list>
-    <#list data.auditFields as field>
-     ,
-       { 
-        autoExpand: false, type: '${field.type}',
-        editorProperties: {
-          width: '*'
-          , columnName: '${field.columnName?js_string}'
-          , targetEntity: '${field.targetEntity?js_string}'
-          , disabled: true
-          , updatable: false
-        }
-        , showHover: false, 
-        width: isc.OBGrid.getDefaultColumnWidth(30), 
-        name: '${field.columnName?js_string}', 
-        canExport: true, 
-        canHide: true, 
-        editorType: '${field.editorType?js_string}',
-        filterEditorType: '${field.filterEditorType?js_string}',
-        ${field.displayFieldJS}
-         filterOnKeypress: true, canFilter:true, required: false
-        , title: '${field.title?js_string}'
-        , prompt: '${field.title?js_string}'
-        , escapeHTML: true
-        , showIf: 'false'
-        , columnName: '${field.columnName?js_string}'
-        , inpColumnName: ''
-        , targetEntity: '${field.targetEntity?js_string}'
-       }
-    </#list>
-    ],
-    autoExpandFieldNames:[
-    <#list data.autoExpandFields as field>
-        '${field}'<#if field_has_next>,</#if>
-    </#list>
-    ],
-    whereClause: '${data.whereClause?js_string}',
-    orderByClause: '${data.orderByClause?js_string}',
-    sortField: '${data.sortField?js_string}',
-    filterClause: '${data.filterClause?js_string}',
-    filterName: '${data.filterName?js_string}',
+     
+    <#if data.whereClause != "">
+        whereClause: '${data.whereClause?js_string}',
+    </#if>
+    <#if data.orderByClause != "">
+        orderByClause: '${data.orderByClause?js_string}',
+    </#if>
+    <#if data.sortField != "">
+        sortField: '${data.sortField?js_string}',
+    </#if>
+    <#if data.filterClause != "">
+        filterClause: '${data.filterClause?js_string}',
+    </#if>
+    <#if data.filterName != "">
+        filterName: '${data.filterName?js_string}',
+    </#if>
     
-    foreignKeyFieldNames:[
-    <#list data.foreignKeyFields as field>
-        '${field}'<#if field_has_next>,</#if>
-    </#list>
-    ]
+    // the this is the view instance
+    fields: this.gridFields
 })
--- a/modules/org.openbravo.client.application/src/org/openbravo/client/application/templates/ob-view-personalization-form.js.ftl	Thu Oct 13 18:24:25 2011 +0200
+++ b/modules/org.openbravo.client.application/src/org/openbravo/client/application/templates/ob-view-personalization-form.js.ftl	Thu Oct 20 13:09:18 2011 +0200
@@ -20,56 +20,58 @@
 -->
 {
     fields: [
-    <#list data.fields as fieldDefinition>
+    <#list data.fieldHandler.fields as field>
       {
-        name: '${fieldDefinition.name?js_string}',
-        title: '${fieldDefinition.label?js_string}',
-        type: '${fieldDefinition.type}',
-        colSpan: ${fieldDefinition.colSpan},
-        rowSpan: ${fieldDefinition.rowSpan},
-        startRow: ${fieldDefinition.startRow?string},
-        endRow: ${fieldDefinition.endRow?string},
-        personalizable: ${fieldDefinition.personalizable?string},
+        name: '${field.name?js_string}',
+        title: '${field.label?js_string}',
+        type: '${field.type}',
+        colSpan: ${field.colSpan},
+        rowSpan: ${field.rowSpan},
+        startRow: ${field.startRow?string},
+        endRow: ${field.endRow?string},
+        personalizable: ${field.personalizable?string},
         isPreviewFormItem: true,
         disabled: true,
         showDisabled: false,
-        <#if !fieldDefinition.displayed>
+        <#if !field.displayed>
         width: '',
         <#else>
         width: '*',
         </#if>
-        <#if fieldDefinition.showIf != "" && fieldDefinition.displayed>
+        <#if field.showIf != "" && field.displayed>
           hasShowIf: true,            
         </#if>
-        <#if fieldDefinition.standardField>
-            <#if !fieldDefinition.displayed>
+        <#if field.standardField>
+            <#if !field.displayed>
                 alwaysTakeSpace: false,
                 displayed: false,
             </#if>
-            required: ${fieldDefinition.required?string},
-            hasDefaultValue: ${fieldDefinition.hasDefaultValue?string},
-            <#if fieldDefinition.searchField>
-                showPickerIcon: ${(!fieldDefinition.parentProperty)?string},
+            required: ${field.required?string},
+            hasDefaultValue: ${field.hasDefaultValue?string},
+            <#if field.searchField>
+                showPickerIcon: ${(!field.parentProperty)?string},
             </#if>
         </#if>
-        <#if fieldDefinition.type = "OBSectionItem" || fieldDefinition.type = "OBNoteSectionItem" || fieldDefinition.type = "OBLinkedItemSectionItem"  || fieldDefinition.type = "OBAttachmentsSectionItem" || fieldDefinition.type = "OBAuditSectionItem">
-          <#if !fieldDefinition.displayed>
+        <#if field.type = "OBSectionItem" || field.type = "OBNoteSectionItem" || field.type = "OBLinkedItemSectionItem"  || field.type = "OBAttachmentsSectionItem" || field.type = "OBAuditSectionItem">
+          <#if !field.displayed>
           visible: false,
           </#if>
-          defaultValue: '${fieldDefinition.label?js_string}',
+          <#if field.hasChildren>
           itemIds: [
-            <#list fieldDefinition.children as childField>
+            <#list field.children as childField>
                 '${childField.name?js_string}'<#if childField_has_next>,</#if>
             </#list>
-            ]
+            ],
+          </#if>
+          defaultValue: '${field.label?js_string}'
         </#if>
     }
-      <#if fieldDefinition_has_next>,</#if>
+      <#if field_has_next>,</#if>
     </#list>    
     ],
 
     statusBarFields: [
-    <#list data.statusBarFields as sbf>
+    <#list data.fieldHandler.statusBarFields as sbf>
       '${sbf?js_string}'<#if sbf_has_next>,</#if>
     </#list>
     ]
--- a/modules/org.openbravo.client.application/src/org/openbravo/client/application/templates/ob-view-tab.js.ftl	Thu Oct 13 18:24:25 2011 +0200
+++ b/modules/org.openbravo.client.application/src/org/openbravo/client/application/templates/ob-view-tab.js.ftl	Thu Oct 20 13:09:18 2011 +0200
@@ -32,93 +32,123 @@
         moduleId: '${tabComponent.moduleId}',
     </#if>
     
-    defaultEditMode: ${tabComponent.defaultEditMode},
+    <#if tabComponent.defaultEditMode>
+    defaultEditMode: ${tabComponent.defaultEditMode?string},
+    </#if> 
     mapping250: '${tabComponent.mapping250?js_string}',
-    isAcctTab: ${tabComponent.acctTab?string}, 
+    <#if tabComponent.acctTab>
+    isAcctTab: ${tabComponent.acctTab?string},
+    </#if> 
+    <#if tabComponent.trlTab>
     isTrlTab: ${tabComponent.trlTab?string},
+    </#if> 
     
     standardProperties:{
+<@compress single_line=true>
       inpTabId: '${tabComponent.tabId}',
       inpwindowId: '${tabComponent.windowId}',
       inpTableId: '${tabComponent.tableId?js_string}',
-      inpkeyColumnId: '${tabComponent.keyColumnId?js_string}',
-      inpKeyName: '${tabComponent.keyName?js_string}'
+      inpkeyColumnId: '${tabComponent.keyProperty.columnId?js_string}',
+      keyProperty: '${tabComponent.keyProperty.name?js_string}',
+      inpKeyName: '${tabComponent.keyInpName?js_string}',
+      keyColumnName: '${tabComponent.keyColumnName?js_string}',
+      keyPropertyType: '${tabComponent.keyPropertyType?js_string}'      
+</@compress>
     },
-    
-    propertyToColumns:[
-      <#list tabComponent.allFields as field>
-        {
-          property: '${field.propertyName?js_string}',
-          inpColumn: '${field.columnName?js_string}', 
-          dbColumn: '${field.dbColumnName?js_string}', 
-          sessionProperty: ${field.session},
-          type: '${field.typeName?js_string}'
-        }<#if field_has_next>,</#if>
-      </#list>
-    ],
-    
+     
     actionToolbarButtons: [
     <#list tabComponent.buttonFields as field>
+<@compress single_line=true>
       {id: '${field.id?js_string}', 
        title: '${field.label?js_string}',
        obManualURL: '${field.url?js_string}',
        command: '${field.command?js_string}',
        property: '${field.propertyName?js_string}',
-       autosave: ${field.autosave?string},
        processId: '${field.processId?js_string}',
        <#if !field.modal>modal: ${field.modal?string},</#if>
+       <#if field.hasLabelValues>
        labelValue: {<#list field.labelValues as value>
            '${value.value?js_string}': '${value.label?js_string}'<#if value_has_next>,</#if>
        </#list>
-         }
+         },
+       </#if>
        <#if field.showIf != "">
-       , displayIf: function(item, value, form, currentValues) {
-         currentValues = currentValues || form.view.getCurrentValues();
-         OB.Utilities.fixNull250(currentValues);
-         var context = form.view.getContextInfo(false, true, true);
-         return context && (${field.showIf});
-       }
+       displayIf: function(form, currentValues, context) {
+         return (${field.showIf});
+       },
        </#if>
        <#if field.readOnlyIf != "">
-       , readOnlyIf: function(item, value, form, currentValues) {
-         currentValues = currentValues || form.view.getCurrentValues();
-         OB.Utilities.fixNull250(currentValues);
-         var context = form.view.getContextInfo(false, true, true);
-         return context && (${field.readOnlyIf});
-       }
+       readOnlyIf: function(form, currentValues, context) {
+         return (${field.readOnlyIf});
+       },
        </#if>
+       autosave: ${field.autosave?string}
       }<#if field_has_next>,</#if>
+</@compress>
     </#list>],
     
     showParentButtons: ${tabComponent.showParentButtons?string},
     
     buttonsHaveSessionLogic: ${tabComponent.buttonSessionLogic?string},
     
+    fields: [
+    <#list tabComponent.fieldHandler.fields as field>
+      <@createField field/><#if field_has_next>,</#if>
+    </#list>    
+    ],
+    
+    statusBarFields: [
+<@compress single_line=true>
+    <#list tabComponent.fieldHandler.statusBarFields as sbf>
+      '${sbf?js_string}'<#if sbf_has_next>,</#if>
+    </#list>
+</@compress>
+    ],
+    
+    initialPropertyToColumns:[
+    <#list tabComponent.otherFields as field>
+<@compress single_line=true>
+        {
+            property: '${field.propertyName?js_string}',
+            inpColumn: '${field.inpColumnName?js_string}', 
+            dbColumn: '${field.dbColumnName?js_string}',
+            <#if field.session>
+                sessionProperty: ${field.session?string},
+            </#if>
+            type: '${field.type?js_string}'
+        }<#if field_has_next>,</#if>
+</@compress>
+    </#list>
+    ],
+    
     iconToolbarButtons: [
     <#list tabComponent.iconButtons as button>
+<@compress single_line=true>
       {
         action: function(){ ${button.action} },
         buttonType: '${button.type?js_string}',
         prompt: '${button.label?js_string}'
       }<#if button_has_next>,</#if>
+</@compress>
     </#list>],
     
-    <#if tabComponent.childTabs?size &gt; 0>
+    <#if tabComponent.childTabs?has_content>
         hasChildTabs: true,
+        createViewStructure: function() {
+            <#list tabComponent.childTabs as childTabComponent>
+            this.addChildView(
+                isc.OBStandardView.create({
+                    <@createView childTabComponent/>
+                })
+            );
+            </#list>
+        },
     </#if>
     initWidget: function() {
+        this.prepareFields();
         this.dataSource = ${tabComponent.dataSourceJavaScript};
-        this.viewForm = isc.OBViewForm.create(${tabComponent.viewForm}); 
+        this.viewForm = isc.OBViewForm.create(isc.clone(OB.ViewFormProperties), ${tabComponent.viewForm}); 
         this.viewGrid = ${tabComponent.viewGrid};
         this.Super('initWidget', arguments);
-      },
-    createViewStructure: function() {
-        <#list tabComponent.childTabs as childTabComponent>
-        this.addChildView(
-            isc.OBStandardView.create({
-                <@createView childTabComponent/>
-            })
-        );
-        </#list>
     }
-</#macro>  
+</#macro>
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/modules/org.openbravo.client.application/src/org/openbravo/client/application/window/OBViewFieldHandler.java	Thu Oct 20 13:09:18 2011 +0200
@@ -0,0 +1,1612 @@
+/*
+ *************************************************************************
+ * 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) 2011 Openbravo SLU
+ * All Rights Reserved.
+ * Contributor(s):  ______________________________________.
+ ************************************************************************
+ */
+package org.openbravo.client.application.window;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Comparator;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.log4j.Logger;
+import org.openbravo.base.model.Property;
+import org.openbravo.base.model.domaintype.ForeignKeyDomainType;
+import org.openbravo.client.application.ApplicationUtils;
+import org.openbravo.client.application.DynamicExpressionParser;
+import org.openbravo.client.kernel.KernelUtils;
+import org.openbravo.client.kernel.reference.FKSearchUIDefinition;
+import org.openbravo.client.kernel.reference.StringUIDefinition;
+import org.openbravo.client.kernel.reference.UIDefinition;
+import org.openbravo.client.kernel.reference.UIDefinitionController;
+import org.openbravo.dal.service.OBDal;
+import org.openbravo.data.Sqlc;
+import org.openbravo.model.ad.ui.Element;
+import org.openbravo.model.ad.ui.Field;
+import org.openbravo.model.ad.ui.FieldGroup;
+import org.openbravo.model.ad.ui.Tab;
+
+/**
+ * The backing bean for generating the fields in the tab.
+ * 
+ * @author mtaal
+ * @author iperdomo
+ */
+
+public class OBViewFieldHandler {
+
+  private static Logger log = Logger.getLogger(OBViewFieldHandler.class);
+
+  private String parentProperty;
+
+  private static final long ONE_COLUMN_MAX_LENGTH = 60;
+  private static final String TEXT_AD_REFERENCE_ID = "14";
+  private static final String IMAGEBLOB_AD_REFERENCE_ID = "4AA6C3BE9D3B4D84A3B80489505A23E5";
+
+  private static final String AUDIT_GROUP_ID = "1000100001";
+  private static final String MORE_INFO_GROUP_ID = "402880E72F1C15A5012F1C7AA98B00E8";
+
+  private Tab tab;
+  private List<String> statusBarFields;
+
+  private List<String> windowEntities = null;
+  private List<OBViewFieldDefinition> fields;
+
+  private List<Field> ignoredFields = new ArrayList<Field>();
+
+  public Tab getTab() {
+    return tab;
+  }
+
+  public void setTab(Tab tab) {
+    this.tab = tab;
+  }
+
+  public boolean getHasFieldsWithReadOnlyIf() {
+    for (OBViewFieldDefinition viewField : getFields()) {
+      if (viewField.getReadOnlyIf() != null && viewField.getReadOnlyIf().trim().length() > 0) {
+        return true;
+      }
+    }
+    return false;
+  }
+
+  public List<OBViewFieldDefinition> getFields() {
+
+    if (fields != null) {
+      return fields;
+    }
+
+    fields = new ArrayList<OBViewFieldDefinition>();
+    final List<Field> adFields = new ArrayList<Field>(tab.getADFieldList());
+    Collections.sort(adFields, new FormFieldComparator());
+
+    final List<Field> fieldsInDynamicExpression = new ArrayList<Field>();
+    final Map<Field, String> displayLogicMap = new HashMap<Field, String>();
+    final Map<Field, String> readOnlyLogicMap = new HashMap<Field, String>();
+
+    // Processing dynamic expressions (display logic)
+    for (Field f : adFields) {
+      if (f.getDisplayLogic() == null || f.getDisplayLogic().equals("") || !f.isActive()
+          || !(f.isDisplayed() || f.isShowInGridView())) {
+        continue;
+      }
+
+      // are added separately
+      if (f.isShownInStatusBar()) {
+        continue;
+      }
+
+      final DynamicExpressionParser parser = new DynamicExpressionParser(f.getDisplayLogic(), tab);
+      displayLogicMap.put(f, parser.getJSExpression());
+
+      log.debug(f.getTab().getId() + " - " + f.getName() + " >>> " + parser.getJSExpression());
+
+      for (Field fieldExpression : parser.getFields()) {
+        if (!fieldsInDynamicExpression.contains(fieldExpression)) {
+          fieldsInDynamicExpression.add(fieldExpression);
+        }
+      }
+    }
+
+    // Processing dynamic expression (read-only logic)
+    for (Field f : adFields) {
+      if (f.getColumn().getReadOnlyLogic() == null || f.getColumn().getReadOnlyLogic().equals("")
+          || !f.isActive() || !f.getColumn().isActive()) {
+        continue;
+      }
+
+      final DynamicExpressionParser parser = new DynamicExpressionParser(f.getColumn()
+          .getReadOnlyLogic(), tab);
+      readOnlyLogicMap.put(f, parser.getJSExpression());
+
+      log.debug(f.getTab().getId() + " - " + f.getName() + " >>> " + parser.getJSExpression());
+
+      for (Field fieldExpression : parser.getFields()) {
+        if (!fieldsInDynamicExpression.contains(fieldExpression)) {
+          fieldsInDynamicExpression.add(fieldExpression);
+        }
+      }
+    }
+
+    // Processing audit fields: if there's field for audit, don't put it in the "more info" section
+    boolean hasCreatedField = false, hasCreatedByField = false, hasUpdatedField = false, hasUpdatedByField = false;
+    for (Field f : adFields) {
+      String dbColName = f.getColumn().getDBColumnName().toLowerCase();
+      if (!dbColName.startsWith("created") && !dbColName.startsWith("updated")) {
+        continue;
+      }
+      if (f.isActive() && f.getColumn().isActive() && (f.isDisplayed() || f.isShownInStatusBar())) {
+        if ("created".equals(dbColName)) {
+          hasCreatedField = true;
+        } else if ("createdby".equals(dbColName)) {
+          hasCreatedByField = true;
+        } else if ("updated".equals(dbColName)) {
+          hasUpdatedField = true;
+        } else if ("updatedby".equals(dbColName)) {
+          hasUpdatedByField = true;
+        }
+      }
+    }
+    List<OBViewFieldDefinition> auditFields = new ArrayList<OBViewFieldDefinition>();
+
+    if (!hasCreatedField) {
+      OBViewFieldAudit audit = new OBViewFieldAudit("creationDate", OBViewUtil.createdElement);
+      auditFields.add(audit);
+    }
+    if (!hasCreatedByField) {
+      OBViewFieldAudit audit = new OBViewFieldAudit("createdBy", OBViewUtil.createdByElement);
+      auditFields.add(audit);
+    }
+    if (!hasUpdatedField) {
+      OBViewFieldAudit audit = new OBViewFieldAudit("updated", OBViewUtil.updatedElement);
+      auditFields.add(audit);
+    }
+    if (!hasUpdatedByField) {
+      OBViewFieldAudit audit = new OBViewFieldAudit("updatedBy", OBViewUtil.updatedByElement);
+      auditFields.add(audit);
+    }
+
+    OBViewFieldGroup currentFieldGroup = null;
+    FieldGroup currentADFieldGroup = null;
+    int colNum = 1;
+    for (Field field : adFields) {
+
+      if (field.getColumn() == null || !field.isActive()
+          || !(field.isDisplayed() || field.isShowInGridView())
+          || ApplicationUtils.isUIButton(field)) {
+        ignoredFields.add(field);
+        continue;
+      }
+
+      // are added separately
+      if (field.isShownInStatusBar()) {
+        continue;
+      }
+
+      final Property property = KernelUtils.getInstance().getPropertyFromColumn(field.getColumn(),
+          false);
+
+      final OBViewField viewField = new OBViewField();
+      viewField.setField(field);
+      viewField.setProperty(property);
+      viewField.setRedrawOnChange(fieldsInDynamicExpression.contains(field));
+      viewField.setShowIf(displayLogicMap.get(field) != null ? displayLogicMap.get(field) : "");
+      viewField.setReadOnlyIf(readOnlyLogicMap.get(field) != null ? readOnlyLogicMap.get(field)
+          : "");
+      // Positioning some fields in odd-columns
+      if (colNum % 2 == 0 && (field.isStartinoddcolumn() || viewField.getColSpan() == 2)) {
+        final OBViewFieldSpacer spacer = new OBViewFieldSpacer();
+        fields.add(spacer);
+        colNum++;
+        if (colNum > 4) {
+          colNum = 1;
+        }
+      }
+
+      // change in fieldgroup
+      if (field.getFieldGroup() != null && field.getFieldGroup() != currentADFieldGroup) {
+        // start of a fieldgroup use it
+        final OBViewFieldGroup viewFieldGroup = new OBViewFieldGroup();
+        fields.add(viewFieldGroup);
+        viewFieldGroup.setFieldGroup(field.getFieldGroup());
+
+        currentFieldGroup = viewFieldGroup;
+        currentADFieldGroup = field.getFieldGroup();
+        colNum = 1;
+      }
+
+      fields.add(viewField);
+
+      if (currentFieldGroup != null) {
+        currentFieldGroup.addChild(viewField);
+      }
+
+      colNum += viewField.getColSpan();
+      if (colNum > 4) {
+        colNum = 1;
+      }
+    }
+
+    // Add audit info
+    if (!auditFields.isEmpty()) {
+      final OBViewFieldGroup viewFieldGroup = new OBViewFieldGroup();
+      viewFieldGroup.setType("OBAuditSectionItem");
+      viewFieldGroup.setPersonalizable(false);
+      fields.add(viewFieldGroup);
+      viewFieldGroup.addChildren(auditFields);
+      viewFieldGroup.setFieldGroup(OBDal.getInstance().get(FieldGroup.class, AUDIT_GROUP_ID));
+      // itemIds are hardcoded in the field type
+      // viewFieldGroup.addChildren(auditFields);
+      fields.addAll(auditFields);
+    }
+
+    // add the notes part
+    final OBViewFieldDefinition notesCanvasFieldDefinition = new NotesCanvasField();
+    final NotesField notesField = new NotesField();
+    // itemIds are hardcoded in the field type
+    // notesField.setChildField(notesCanvasFieldDefinition);
+    fields.add(notesField);
+    fields.add(notesCanvasFieldDefinition);
+
+    // add the linked items part
+    final OBViewFieldDefinition linkedItemsCanvasFieldDefinition = new LinkedItemsCanvasField();
+    final LinkedItemsField linkedItemsField = new LinkedItemsField();
+    // itemIds are hardcoded in the field type
+    // linkedItemsField.setChildField(linkedItemsCanvasFieldDefinition);
+    fields.add(linkedItemsField);
+    fields.add(linkedItemsCanvasFieldDefinition);
+
+    // add the attachments part
+    final AttachmentsCanvasField attachmentsCanvas = new AttachmentsCanvasField();
+    final AttachmentsField attachmentDefinition = new AttachmentsField();
+    // itemIds are hardcoded in the field type
+    // attachmentDefinition.setChildField(attachmentsCanvas);
+    fields.add(attachmentDefinition);
+    fields.add(attachmentsCanvas);
+
+    // add status bar fields
+    processStatusBarFields(fields, adFields);
+
+    // determine the grid sort order
+    List<OBViewFieldDefinition> gridFields = new ArrayList<OBViewFieldDefinition>(fields);
+    Collections.sort(gridFields, new GridFieldComparator());
+    int sort = 1;
+    for (OBViewFieldDefinition viewDef : gridFields) {
+      if (viewDef instanceof OBViewField && viewDef.getIsGridProperty()) {
+        ((OBViewField) viewDef).setGridSort(sort++);
+      }
+    }
+
+    return fields;
+  }
+
+  public boolean getHasStatusBarFields() {
+    return !statusBarFields.isEmpty();
+  }
+
+  public List<String> getStatusBarFields() {
+    if (statusBarFields == null) {
+      log.warn("Calling getStatusBarFields without initializing fields cache");
+      return Collections.emptyList();
+    }
+    return statusBarFields;
+  }
+
+  private void processStatusBarFields(List<OBViewFieldDefinition> viewFields, List<Field> adFields) {
+    if (statusBarFields != null) {
+      return;
+    }
+    statusBarFields = new ArrayList<String>();
+    for (Field field : adFields) {
+
+      if (field.isShownInStatusBar() == null || !field.isShownInStatusBar()) {
+        continue;
+      }
+
+      final Property property = KernelUtils.getInstance().getPropertyFromColumn(field.getColumn(),
+          false);
+
+      statusBarFields.add(property.getName());
+
+      if (field.isDisplayed()) {
+        continue;
+      }
+
+      final OBViewField viewField = new OBViewField();
+      viewField.setField(field);
+      viewField.setProperty(property);
+      viewField.setRedrawOnChange(false);
+      viewField.setShowIf("");
+      viewField.setReadOnlyIf("");
+
+      viewFields.add(viewField);
+    }
+  }
+
+  interface OBViewFieldDefinition {
+    public int getGridSort();
+
+    public String getOnChangeFunction();
+
+    public boolean getShowColSpan();
+
+    public boolean getShowStartRow();
+
+    public boolean getShowEndRow();
+
+    public boolean getHasChildren();
+
+    public Long getGridPosition();
+
+    public Long getSequenceNumber();
+
+    public Integer getLength();
+
+    public boolean getAutoExpand();
+
+    public String getCellAlign();
+
+    public String getLabel();
+
+    public String getName();
+
+    public String getType();
+
+    public boolean getIsAuditField();
+
+    public boolean getIsGridProperty();
+
+    public boolean getSessionProperty();
+
+    public boolean getStandardField();
+
+    public boolean getPersonalizable();
+
+    public String getFieldProperties();
+
+    public String getInpColumnName();
+
+    public String getReferencedKeyColumnName();
+
+    public String getTargetEntity();
+
+    public boolean getStartRow();
+
+    public boolean getEndRow();
+
+    public long getColSpan();
+
+    public long getRowSpan();
+
+    public boolean getReadOnly();
+
+    public boolean getRequired();
+
+    public boolean getUpdatable();
+
+    public boolean getParentProperty();
+
+    public boolean getRedrawOnChange();
+
+    public String getShowIf();
+
+    public String getReadOnlyIf();
+
+    public boolean isDisplayed();
+
+    public boolean getHasDefaultValue();
+  }
+
+  public class OBViewFieldAudit implements OBViewFieldDefinition {
+    private String name;
+    private String refType;
+    private String refEntity;
+    private Element element;
+
+    public String getOnChangeFunction() {
+      return null;
+    }
+
+    public boolean getShowColSpan() {
+      return getColSpan() != 1;
+    }
+
+    public boolean getShowStartRow() {
+      return getStartRow();
+    }
+
+    public boolean getShowEndRow() {
+      return getEndRow();
+    }
+
+    public boolean getHasChildren() {
+      return false;
+    }
+
+    public int getGridSort() {
+      // put them at the back somewhere
+      return 990;
+    }
+
+    public Long getGridPosition() {
+      return null;
+    }
+
+    public Long getSequenceNumber() {
+      return null;
+    }
+
+    public OBViewFieldAudit(String type, Element element) {
+      name = type;
+      this.element = element;
+
+      if (type.endsWith("By")) {
+        // User search
+        refType = "30";
+        refEntity = "User";
+      } else {
+        // Date time
+        refType = "16";
+        refEntity = "";
+      }
+    }
+
+    public String getGridFieldProperties() {
+      return "";
+    }
+
+    public Integer getLength() {
+      return null;
+    }
+
+    public String getFilterEditorProperties() {
+      return "";
+    }
+
+    public String getGridEditorFieldProperties() {
+      return "";
+    }
+
+    public String getCellAlign() {
+      return "left";
+    }
+
+    public boolean getAutoExpand() {
+      return false;
+    }
+
+    public boolean getIsAuditField() {
+      return true;
+    }
+
+    public boolean getIsGridProperty() {
+      return true;
+    }
+
+    @Override
+    public String getLabel() {
+      return OBViewUtil.getLabel(element, element.getADElementTrlList());
+    }
+
+    public boolean getSessionProperty() {
+      return false;
+    }
+
+    @Override
+    public String getName() {
+      return name;
+    }
+
+    @Override
+    public String getType() {
+      return "_id_" + refType;
+    }
+
+    @Override
+    public boolean getStandardField() {
+      return true;
+    }
+
+    public boolean isShowInitiallyInGrid() {
+      return false;
+    }
+
+    @Override
+    public String getFieldProperties() {
+      return "";
+    }
+
+    @Override
+    public String getInpColumnName() {
+      return "";
+    }
+
+    @Override
+    public String getReferencedKeyColumnName() {
+      return "";
+    }
+
+    public boolean getHasDefaultValue() {
+      return false;
+    }
+
+    @Override
+    public String getTargetEntity() {
+      return refEntity;
+    }
+
+    @Override
+    public boolean getStartRow() {
+      return false;
+    }
+
+    @Override
+    public boolean getEndRow() {
+      return false;
+    }
+
+    @Override
+    public long getColSpan() {
+      return 1;
+    }
+
+    @Override
+    public long getRowSpan() {
+      return 1;
+    }
+
+    @Override
+    public boolean getReadOnly() {
+      return true;
+    }
+
+    @Override
+    public boolean getUpdatable() {
+      return false;
+    }
+
+    public boolean getPersonalizable() {
+      return false;
+    }
+
+    @Override
+    public boolean getParentProperty() {
+      return false;
+    }
+
+    @Override
+    public boolean getRedrawOnChange() {
+      return false;
+    }
+
+    @Override
+    public String getShowIf() {
+      return "";
+    }
+
+    @Override
+    public String getReadOnlyIf() {
+      return "";
+    }
+
+    public boolean getRequired() {
+      return false;
+    }
+
+    public String getColumnName() {
+      return "";
+    }
+
+    public boolean isFirstFocusedField() {
+      return false;
+    }
+
+    public boolean isSearchField() {
+      return !refEntity.isEmpty();
+    }
+
+    public boolean isDisplayed() {
+      return true;
+    }
+
+  }
+
+  public class OBViewField implements OBViewFieldDefinition {
+    private Field field;
+    private Property property;
+    private String label;
+    private UIDefinition uiDefinition;
+    private Boolean isParentProperty = null;
+    private boolean redrawOnChange = false;
+    private String showIf = "";
+    private String readOnlyIf = "";
+    private int gridSort = 0;
+
+    public String getOnChangeFunction() {
+      return field.getOnChangeFunction();
+    }
+
+    public boolean getShowColSpan() {
+      return getColSpan() != 1;
+    }
+
+    public boolean getShowStartRow() {
+      return getStartRow();
+    }
+
+    public boolean getShowEndRow() {
+      return getEndRow();
+    }
+
+    public boolean getHasChildren() {
+      return false;
+    }
+
+    public Long getGridPosition() {
+      return field.getGridPosition();
+    }
+
+    public Long getSequenceNumber() {
+      return field.getSequenceNumber();
+    }
+
+    public String getCellAlign() {
+      return uiDefinition.getCellAlign();
+    }
+
+    public boolean getAutoExpand() {
+      return (!property.getName().equalsIgnoreCase("documentno") && (uiDefinition instanceof StringUIDefinition || !property
+          .isPrimitive()));
+    }
+
+    public boolean getIsAuditField() {
+      return false;
+    }
+
+    public String getGridFieldProperties() {
+      return uiDefinition.getGridFieldProperties(field);
+    }
+
+    public String getFilterEditorProperties() {
+      return uiDefinition.getFilterEditorProperties(field);
+    }
+
+    public String getGridEditorFieldProperties() {
+      String props = uiDefinition.getGridEditorFieldProperties(field).trim();
+      if (props.startsWith("{")) {
+        props = props.substring(1, props.length() - 1);
+      }
+      if (props.trim().endsWith(",")) {
+        return props.trim().substring(0, props.trim().length() - 1);
+      }
+      if (props.trim().length() == 0) {
+        return "";
+      }
+      return props.trim();
+    }
+
+    /**
+     * @deprecated use {@link #setRedrawOnChange(boolean)}
+     */
+    @Deprecated
+    public void setReadrawOnChange(boolean value) {
+      this.setRedrawOnChange(value);
+    }
+
+    public boolean getIsGridProperty() {
+
+      if (!field.isActive()) {
+        return false;
+      }
+      final Property prop = KernelUtils.getInstance().getPropertyFromColumn(field.getColumn());
+      if (prop.isParent() && getWindowEntities().contains(prop.getTargetEntity().getName())) {
+        return false;
+      }
+      if (prop.isId()) {
+        return false;
+      }
+      if (ApplicationUtils.isUIButton(field)) {
+        return false;
+      }
+      return true;
+    }
+
+    public boolean getSessionProperty() {
+      return property.isStoredInSession();
+    }
+
+    public boolean getReadOnly() {
+      return getParentProperty() || field.isReadOnly();
+    }
+
+    public boolean getUpdatable() {
+      return property.isUpdatable();
+    }
+
+    public boolean getPersonalizable() {
+      return true;
+    }
+
+    public boolean getParentProperty() {
+      if (isParentProperty == null) {
+        if (OBViewFieldHandler.this.getParentProperty() == null) {
+          isParentProperty = false;
+        } else {
+          isParentProperty = OBViewFieldHandler.this.getParentProperty().equals(property.getName());
+        }
+      }
+      return isParentProperty;
+    }
+
+    public boolean isSearchField() {
+      return uiDefinition instanceof FKSearchUIDefinition;
+    }
+
+    public boolean isFirstFocusedField() {
+      Boolean focused = field.isFirstFocusedField();
+      Boolean displayed = field.isDisplayed();
+      return focused != null && focused && displayed != null && displayed;
+    }
+
+    public String getType() {
+      return getUIDefinition().getName();
+    }
+
+    public boolean getHasDefaultValue() {
+      return field.getColumn().getDefaultValue() != null;
+    }
+
+    public String getFieldProperties() {
+
+      String jsonString = getUIDefinition().getFieldProperties(field).trim();
+      if (jsonString == null || jsonString.trim().length() == 0) {
+        return "";
+      }
+      // strip the first and last { }
+      if (jsonString.startsWith("{") && jsonString.endsWith("}")) {
+        // note -2 is done because the first substring takes of 1 already
+        return jsonString.substring(1).substring(0, jsonString.length() - 2) + ",";
+      } else if (jsonString.equals("{}")) {
+        return "";
+      }
+      // be lenient just return the string as it is...
+      return jsonString + (jsonString.trim().endsWith(",") ? "" : ",");
+    }
+
+    private UIDefinition getUIDefinition() {
+      if (uiDefinition != null) {
+        return uiDefinition;
+      }
+      uiDefinition = UIDefinitionController.getInstance().getUIDefinition(property.getColumnId());
+      return uiDefinition;
+    }
+
+    public String getName() {
+      return property.getName();
+    }
+
+    public String getColumnName() {
+      return property.getColumnName();
+    }
+
+    public String getInpColumnName() {
+      return "inp" + Sqlc.TransformaNombreColumna(property.getColumnName());
+    }
+
+    public String getReferencedKeyColumnName() {
+      if (property.isOneToMany() || property.isPrimitive()) {
+        return "";
+      }
+      Property prop;
+      if (property.getReferencedProperty() == null) {
+        prop = property.getTargetEntity().getIdProperties().get(0);
+      } else {
+        prop = property.getReferencedProperty();
+      }
+      return prop.getColumnName();
+    }
+
+    public String getTargetEntity() {
+      if (property.isOneToMany() || property.isPrimitive()) {
+        return "";
+      }
+      return property.getTargetEntity().getName();
+    }
+
+    public String getLabel() {
+      // compute the label
+      if (label == null) {
+        label = OBViewUtil.getLabel(field);
+      }
+      return label;
+    }
+
+    public void setLabel(String label) {
+      this.label = label;
+    }
+
+    public Field getField() {
+      return field;
+    }
+
+    public void setField(Field field) {
+      this.field = field;
+    }
+
+    public boolean getStandardField() {
+      return true;
+    }
+
+    public Property getProperty() {
+      return property;
+    }
+
+    public void setProperty(Property property) {
+      this.property = property;
+    }
+
+    public boolean getRequired() {
+      // booleans are never required as their input only allows 2 values
+      if (property.isBoolean()) {
+        return false;
+      }
+
+      if (!getUpdatable()) {
+        return false;
+      }
+
+      if (field.getColumn() != null) {
+        // Taking value from AD definition, mandatoriness of a column can be different in AD and in
+        // memory model, because memory model sets mandatoriness regarding physical DB definition.
+        return field.getColumn().isMandatory();
+      } else {
+        return property.isMandatory();
+      }
+    }
+
+    public Integer getLength() {
+      return property.getFieldLength();
+    }
+
+    public boolean getForeignKeyField() {
+      return property.getDomainType() instanceof ForeignKeyDomainType;
+    }
+
+    public String getDataSourceId() {
+      return property.getTargetEntity().getName();
+    }
+
+    public long getColSpan() {
+      if (field.getObuiappColspan() != null) {
+        return field.getObuiappColspan();
+      }
+      return field.getDisplayedLength() > ONE_COLUMN_MAX_LENGTH
+          || (getRowSpan() == 2 && !property.getDomainType().getReference().getId()
+              .equals(IMAGEBLOB_AD_REFERENCE_ID)) ? 2 : 1;
+    }
+
+    public boolean getEndRow() {
+      return false;
+    }
+
+    public long getRowSpan() {
+      if (field.getObuiappRowspan() != null) {
+        return field.getObuiappRowspan();
+      }
+      if (property.getDomainType().getReference().getId().equals(TEXT_AD_REFERENCE_ID)) {
+        return 2;
+      }
+      if (property.getDomainType().getReference().getId().equals(IMAGEBLOB_AD_REFERENCE_ID)) {
+        return 2;
+      }
+      return 1;
+    }
+
+    public boolean getStartRow() {
+      return field.isStartnewline();
+    }
+
+    public void setRedrawOnChange(boolean redrawOnChange) {
+      this.redrawOnChange = redrawOnChange;
+    }
+
+    public boolean getRedrawOnChange() {
+      return redrawOnChange;
+    }
+
+    public void setShowIf(String showIf) {
+      this.showIf = showIf;
+    }
+
+    public String getShowIf() {
+      return showIf;
+    }
+
+    public void setReadOnlyIf(String readOnlyExpression) {
+      this.readOnlyIf = readOnlyExpression;
+    }
+
+    public String getReadOnlyIf() {
+      return readOnlyIf;
+    }
+
+    public boolean isDisplayed() {
+      return field.isDisplayed() != null && field.isDisplayed();
+    }
+
+    public boolean isShowInitiallyInGrid() {
+      return field.isShowInGridView();
+    }
+
+    public int getGridSort() {
+      return gridSort;
+    }
+
+    public void setGridSort(int gridSort) {
+      this.gridSort = gridSort;
+    }
+  }
+
+  public class DefaultVirtualField implements OBViewFieldDefinition {
+
+    public String getOnChangeFunction() {
+      return null;
+    }
+
+    public boolean getShowColSpan() {
+      return getColSpan() != 4;
+    }
+
+    public boolean getShowStartRow() {
+      return !getStartRow();
+    }
+
+    public boolean getShowEndRow() {
+      return !getEndRow();
+    }
+
+    public boolean getHasChildren() {
+      return false;
+    }
+
+    public int getGridSort() {
+      return -1;
+    }
+
+    public Long getGridPosition() {
+      return null;
+    }
+
+    public Long getSequenceNumber() {
+      return null;
+    }
+
+    public Integer getLength() {
+      return 0;
+    }
+
+    public String getCellAlign() {
+      return null;
+    }
+
+    public boolean getAutoExpand() {
+      return false;
+    }
+
+    public boolean getIsAuditField() {
+      return false;
+    }
+
+    public boolean getIsGridProperty() {
+      return false;
+    }
+
+    public boolean getRequired() {
+      return false;
+    }
+
+    public boolean getSessionProperty() {
+      return false;
+    }
+
+    public String getFieldProperties() {
+      return "";
+    }
+
+    public boolean getHasDefaultValue() {
+      return false;
+    }
+
+    public boolean getReadOnly() {
+      return false;
+    }
+
+    public boolean getUpdatable() {
+      return true;
+    }
+
+    public boolean getParentProperty() {
+      return false;
+    }
+
+    public boolean getPersonalizable() {
+      return false;
+    }
+
+    public String getInpColumnName() {
+      return "";
+    }
+
+    public String getReferencedKeyColumnName() {
+      return "";
+    }
+
+    public String getTargetEntity() {
+      return "";
+    }
+
+    public long getColSpan() {
+      return 4;
+    }
+
+    public boolean getEndRow() {
+      return true;
+    }
+
+    public long getRowSpan() {
+      return 1;
+    }
+
+    public boolean getStartRow() {
+      return true;
+    }
+
+    public boolean getStandardField() {
+      return false;
+    }
+
+    public String getLabel() {
+      return "";
+    }
+
+    public String getName() {
+      return "";
+    }
+
+    public String getType() {
+      return "";
+    }
+
+    public boolean getRedrawOnChange() {
+      return false;
+    }
+
+    public String getShowIf() {
+      return "";
+    }
+
+    public String getReadOnlyIf() {
+      return "";
+    }
+
+    public boolean isDisplayed() {
+      return true;
+    }
+  }
+
+  public class OBViewFieldGroup extends DefaultVirtualField {
+
+    private boolean expanded = true;
+    private String type;
+    private FieldGroup fieldGroup;
+    private String label;
+    private List<OBViewFieldDefinition> children = new ArrayList<OBViewFieldDefinition>();
+    private boolean personalizable = true;
+
+    public OBViewFieldGroup() {
+      type = "OBSectionItem";
+    }
+
+    public boolean getPersonalizable() {
+      return personalizable;
+    }
+
+    public String getLabel() {
+      // compute the label
+      if (label == null) {
+        label = OBViewUtil.getLabel(fieldGroup, fieldGroup.getADFieldGroupTrlList());
+      }
+      return label;
+    }
+
+    public void setLabel(String label) {
+      this.label = label;
+    }
+
+    public FieldGroup getFieldGroup() {
+      return fieldGroup;
+    }
+
+    public void setFieldGroup(FieldGroup fieldGroup) {
+      if (AUDIT_GROUP_ID.equals(fieldGroup.getId())
+          || MORE_INFO_GROUP_ID.equals(fieldGroup.getId())) {
+        expanded = false;
+      }
+
+      this.fieldGroup = fieldGroup;
+    }
+
+    public void addChild(OBViewFieldDefinition viewFieldDefinition) {
+      children.add(viewFieldDefinition);
+    }
+
+    public void addChildren(List<OBViewFieldDefinition> viewFieldDefinitions) {
+      children.addAll(viewFieldDefinitions);
+    }
+
+    public boolean getHasChildren() {
+      return !getChildren().isEmpty();
+    }
+
+    public List<OBViewFieldDefinition> getChildren() {
+      return children;
+    }
+
+    public String getType() {
+      return type;
+    }
+
+    public void setType(String type) {
+      this.type = type;
+    }
+
+    public String getName() {
+      return fieldGroup.getId();
+    }
+
+    public boolean getExpanded() {
+      return expanded;
+    }
+
+    public void setExpanded(boolean expanded) {
+      this.expanded = expanded;
+    }
+
+    public boolean isDisplayed() {
+      for (OBViewFieldDefinition child : children) {
+        if (child.isDisplayed()) {
+          return true;
+        }
+      }
+      return false;
+    }
+
+    public void setPersonalizable(boolean personalizable) {
+      this.personalizable = personalizable;
+    }
+  }
+
+  public class AttachmentsCanvasField extends DefaultVirtualField {
+
+    public String getName() {
+      return "_attachments_Canvas";
+    }
+
+    public String getType() {
+      return "OBAttachmentCanvasItem";
+    }
+  }
+
+  public class AttachmentsField extends DefaultVirtualField {
+
+    private OBViewFieldDefinition childField;
+
+    public String getLabel() {
+      // is set at runtime
+      return "";
+    }
+
+    public boolean getEndRow() {
+      return true;
+    }
+
+    public List<OBViewFieldDefinition> getChildren() {
+      return Collections.singletonList(childField);
+    }
+
+    public String getType() {
+      return "OBAttachmentsSectionItem";
+    }
+
+    public boolean getStartRow() {
+      return true;
+    }
+
+    public boolean getRedrawOnChange() {
+      return false;
+    }
+
+    public String getName() {
+      return "_attachments_";
+    }
+
+    public OBViewFieldDefinition getChildField() {
+      return childField;
+    }
+
+    public void setChildField(OBViewFieldDefinition childField) {
+      this.childField = childField;
+    }
+
+    public boolean isExpanded() {
+      return false;
+    }
+  }
+
+  public class LinkedItemsField extends DefaultVirtualField {
+
+    private OBViewFieldDefinition childField;
+
+    public String getLabel() {
+      // is set at runtime
+      return "";
+    }
+
+    public boolean getEndRow() {
+      return true;
+    }
+
+    public List<OBViewFieldDefinition> getChildren() {
+      return Collections.singletonList(childField);
+    }
+
+    public String getType() {
+      return "OBLinkedItemSectionItem";
+    }
+
+    public boolean getStartRow() {
+      return true;
+    }
+
+    public boolean getRedrawOnChange() {
+      return false;
+    }
+
+    public String getName() {
+      return "_linkedItems_";
+    }
+
+    public OBViewFieldDefinition getChildField() {
+      return childField;
+    }
+
+    public void setChildField(OBViewFieldDefinition childField) {
+      this.childField = childField;
+    }
+
+    public boolean isExpanded() {
+      return false;
+    }
+  }
+
+  private class LinkedItemsCanvasField extends DefaultVirtualField {
+
+    public String getLabel() {
+      // is set at runtime
+      return "";
+    }
+
+    @SuppressWarnings("unused")
+    public List<OBViewFieldDefinition> getChildren() {
+      return Collections.emptyList();
+    }
+
+    public String getType() {
+      return "OBLinkedItemCanvasItem";
+    }
+
+    public String getName() {
+      return "_linkedItems_Canvas";
+    }
+  }
+
+  public class NotesField extends DefaultVirtualField {
+
+    private OBViewFieldDefinition childField;
+
+    public String getLabel() {
+      // is set at runtime
+      return "";
+    }
+
+    public boolean getEndRow() {
+      return true;
+    }
+
+    public List<OBViewFieldDefinition> getChildren() {
+      return Collections.singletonList(childField);
+    }
+
+    public String getType() {
+      return "OBNoteSectionItem";
+    }
+
+    public boolean getStartRow() {
+      return true;
+    }
+
+    public boolean getRedrawOnChange() {
+      return false;
+    }
+
+    public String getName() {
+      return "_notes_";
+    }
+
+    public OBViewFieldDefinition getChildField() {
+      return childField;
+    }
+
+    public void setChildField(OBViewFieldDefinition childField) {
+      this.childField = childField;
+    }
+
+    public boolean isExpanded() {
+      return false;
+    }
+  }
+
+  private class NotesCanvasField extends DefaultVirtualField {
+
+    public String getLabel() {
+      // is set at runtime
+      return "";
+    }
+
+    @SuppressWarnings("unused")
+    public List<OBViewFieldDefinition> getChildren() {
+      return Collections.emptyList();
+    }
+
+    public String getType() {
+      return "OBNoteCanvasItem";
+    }
+
+    public String getName() {
+      return "_notes_Canvas";
+    }
+
+  }
+
+  public class OBViewFieldSpacer implements OBViewFieldDefinition {
+    public String getOnChangeFunction() {
+      return null;
+    }
+
+    public boolean getHasChildren() {
+      return false;
+    }
+
+    public boolean getShowColSpan() {
+      return getColSpan() != 1;
+    }
+
+    public boolean getShowStartRow() {
+      return getStartRow();
+    }
+
+    public boolean getShowEndRow() {
+      return getEndRow();
+    }
+
+    public int getGridSort() {
+      return 990;
+    }
+
+    public Long getGridPosition() {
+      return null;
+    }
+
+    public Long getSequenceNumber() {
+      return null;
+    }
+
+    public Integer getLength() {
+      return 0;
+    }
+
+    public String getCellAlign() {
+      return null;
+    }
+
+    public boolean getAutoExpand() {
+      return false;
+    }
+
+    public boolean getIsAuditField() {
+      return false;
+    }
+
+    public boolean getIsGridProperty() {
+      return false;
+    }
+
+    public boolean getRequired() {
+      return false;
+    }
+
+    public boolean getSessionProperty() {
+      return false;
+    }
+
+    public boolean getPersonalizable() {
+      return false;
+    }
+
+    public boolean getHasDefaultValue() {
+      return false;
+    }
+
+    public long getColSpan() {
+      return 1;
+    }
+
+    public boolean getEndRow() {
+      return false;
+    }
+
+    public boolean getReadOnly() {
+      return false;
+    }
+
+    public boolean getUpdatable() {
+      return true;
+    }
+
+    public boolean getParentProperty() {
+      return false;
+    }
+
+    public String getFieldProperties() {
+      return "";
+    }
+
+    public String getInpColumnName() {
+      return "";
+    }
+
+    public String getLabel() {
+      return "";
+    }
+
+    public String getName() {
+      return "";
+    }
+
+    public String getReferencedKeyColumnName() {
+      return "";
+    }
+
+    public String getTargetEntity() {
+      return "";
+    }
+
+    public long getRowSpan() {
+      return 1;
+    }
+
+    public boolean getStandardField() {
+      return false;
+    }
+
+    public boolean getStartRow() {
+      return false;
+    }
+
+    public String getType() {
+      return "spacer";
+    }
+
+    public boolean getRedrawOnChange() {
+      return false;
+    }
+
+    public String getShowIf() {
+      return "";
+    }
+
+    public String getReadOnlyIf() {
+      return "";
+    }
+
+    public boolean isDisplayed() {
+      return true;
+    }
+
+  }
+
+  public static class FormFieldComparator implements Comparator<Field> {
+
+    /**
+     * Fields with null sequence number are in the bottom of the form. In case multiple null
+     * sequences, it is sorted by field UUID.
+     */
+    @Override
+    public int compare(Field arg0, Field arg1) {
+      Long arg0Position = arg0.getSequenceNumber();
+      Long arg1Position = arg1.getSequenceNumber();
+
+      if (arg0Position == null && arg1Position == null) {
+        return arg0.getId().compareTo(arg1.getId());
+      } else if (arg0Position == null) {
+        return 1;
+      } else if (arg1Position == null) {
+        return -1;
+      }
+
+      return (int) (arg0Position - arg1Position);
+    }
+
+  }
+
+  public String getParentProperty() {
+    return parentProperty;
+  }
+
+  public void setParentProperty(String parentProperty) {
+    this.parentProperty = parentProperty;
+  }
+
+  private class GridFieldComparator implements Comparator<OBViewFieldDefinition> {
+
+    @Override
+    public int compare(OBViewFieldDefinition arg0, OBViewFieldDefinition arg1) {
+      Long arg0Position = (arg0.getGridPosition() != null ? arg0.getGridPosition() : arg0
+          .getSequenceNumber());
+      Long arg1Position = (arg1.getGridPosition() != null ? arg1.getGridPosition() : arg1
+          .getSequenceNumber());
+
+      if (arg0Position == null && arg1Position == null) {
+        return 0;
+      } else if (arg0Position == null) {
+        return 1;
+      } else if (arg1Position == null) {
+        return -1;
+      }
+
+      return (int) (arg0Position - arg1Position);
+    }
+  }
+
+  private List<String> getWindowEntities() {
+    if (windowEntities == null) {
+      windowEntities = new ArrayList<String>();
+      for (Tab localTab : tab.getWindow().getADTabList()) {
+        windowEntities.add(localTab.getTable().getName());
+      }
+    }
+    return windowEntities;
+  }
+
+  public List<Field> getIgnoredFields() {
+    getFields(); // initializes stuff
+    return ignoredFields;
+  }
+}
--- a/modules/org.openbravo.client.application/src/org/openbravo/client/application/window/OBViewFormComponent.java	Thu Oct 13 18:24:25 2011 +0200
+++ b/modules/org.openbravo.client.application/src/org/openbravo/client/application/window/OBViewFormComponent.java	Thu Oct 20 13:09:18 2011 +0200
@@ -18,30 +18,9 @@
  */
 package org.openbravo.client.application.window;
 
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.Comparator;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-import org.apache.log4j.Logger;
-import org.openbravo.base.model.Property;
-import org.openbravo.base.model.domaintype.ForeignKeyDomainType;
-import org.openbravo.client.application.ApplicationUtils;
-import org.openbravo.client.application.DynamicExpressionParser;
 import org.openbravo.client.kernel.BaseTemplateComponent;
-import org.openbravo.client.kernel.KernelUtils;
 import org.openbravo.client.kernel.Template;
-import org.openbravo.client.kernel.reference.FKSearchUIDefinition;
-import org.openbravo.client.kernel.reference.UIDefinition;
-import org.openbravo.client.kernel.reference.UIDefinitionController;
 import org.openbravo.dal.service.OBDal;
-import org.openbravo.data.Sqlc;
-import org.openbravo.model.ad.ui.Element;
-import org.openbravo.model.ad.ui.Field;
-import org.openbravo.model.ad.ui.FieldGroup;
-import org.openbravo.model.ad.ui.Tab;
 
 /**
  * The backing bean for generating the OBViewForm client-side representation.
@@ -53,1150 +32,17 @@
 public class OBViewFormComponent extends BaseTemplateComponent {
 
   private static final String TEMPLATE_ID = "C1D176407A354A40815DC46D24D70EB8";
-  private static Logger log = Logger.getLogger(OBViewFormComponent.class);
 
   private String parentProperty;
 
-  private static final long ONE_COLUMN_MAX_LENGTH = 60;
-  private static final String TEXT_AD_REFERENCE_ID = "14";
-  private static final String IMAGEBLOB_AD_REFERENCE_ID = "4AA6C3BE9D3B4D84A3B80489505A23E5";
+  private String templateId = TEMPLATE_ID;
 
-  private static final String AUDIT_GROUP_ID = "1000100001";
-  private static final String MORE_INFO_GROUP_ID = "402880E72F1C15A5012F1C7AA98B00E8";
-
-  private Tab tab;
-  private List<String> statusBarFields = new ArrayList<String>();
-
-  private String templateId = TEMPLATE_ID;
+  private OBViewFieldHandler fieldHandler;
 
   protected Template getComponentTemplate() {
     return OBDal.getInstance().get(Template.class, templateId);
   }
 
-  public Tab getTab() {
-    return tab;
-  }
-
-  public void setTab(Tab tab) {
-    this.tab = tab;
-  }
-
-  public List<OBViewFieldDefinition> getFields() {
-
-    final List<OBViewFieldDefinition> fields = new ArrayList<OBViewFieldDefinition>();
-    final List<Field> adFields = new ArrayList<Field>(tab.getADFieldList());
-    Collections.sort(adFields, new FormFieldComparator());
-
-    final List<Field> fieldsInDynamicExpression = new ArrayList<Field>();
-    final Map<Field, String> displayLogicMap = new HashMap<Field, String>();
-    final Map<Field, String> readOnlyLogicMap = new HashMap<Field, String>();
-
-    // Processing dynamic expressions (display logic)
-    for (Field f : adFields) {
-      if (f.getDisplayLogic() == null || f.getDisplayLogic().equals("") || !f.isActive()
-          || !f.isDisplayed()) {
-        continue;
-      }
-
-      final DynamicExpressionParser parser = new DynamicExpressionParser(f.getDisplayLogic(), tab);
-      displayLogicMap.put(f, parser.getJSExpression());
-
-      log.debug(f.getTab().getId() + " - " + f.getName() + " >>> " + parser.getJSExpression());
-
-      for (Field fieldExpression : parser.getFields()) {
-        if (!fieldsInDynamicExpression.contains(fieldExpression)) {
-          fieldsInDynamicExpression.add(fieldExpression);
-        }
-      }
-    }
-
-    // Processing dynamic expression (read-only logic)
-    for (Field f : adFields) {
-      if (f.getColumn().getReadOnlyLogic() == null || f.getColumn().getReadOnlyLogic().equals("")
-          || !f.isActive() || !f.getColumn().isActive()) {
-        continue;
-      }
-
-      final DynamicExpressionParser parser = new DynamicExpressionParser(f.getColumn()
-          .getReadOnlyLogic(), tab);
-      readOnlyLogicMap.put(f, parser.getJSExpression());
-
-      log.debug(f.getTab().getId() + " - " + f.getName() + " >>> " + parser.getJSExpression());
-
-      for (Field fieldExpression : parser.getFields()) {
-        if (!fieldsInDynamicExpression.contains(fieldExpression)) {
-          fieldsInDynamicExpression.add(fieldExpression);
-        }
-      }
-    }
-
-    // Processing audit fields: if there's field for audit, don't put it in the "more info" section
-    boolean hasCreatedField = false, hasCreatedByField = false, hasUpdatedField = false, hasUpdatedByField = false;
-    for (Field f : adFields) {
-      String dbColName = f.getColumn().getDBColumnName().toLowerCase();
-      if (!dbColName.startsWith("created") && !dbColName.startsWith("updated")) {
-        continue;
-      }
-      if (f.isActive() && f.getColumn().isActive() && (f.isDisplayed() || f.isShownInStatusBar())) {
-        if ("created".equals(dbColName)) {
-          hasCreatedField = true;
-        } else if ("createdby".equals(dbColName)) {
-          hasCreatedByField = true;
-        } else if ("updated".equals(dbColName)) {
-          hasUpdatedField = true;
-        } else if ("updatedby".equals(dbColName)) {
-          hasUpdatedByField = true;
-        }
-      }
-    }
-    List<OBViewFieldDefinition> auditFields = new ArrayList<OBViewFieldDefinition>();
-
-    if (!hasCreatedField) {
-      OBViewFieldAudit audit = new OBViewFieldAudit("creationDate", OBViewUtil.createdElement);
-      auditFields.add(audit);
-    }
-    if (!hasCreatedByField) {
-      OBViewFieldAudit audit = new OBViewFieldAudit("createdBy", OBViewUtil.createdByElement);
-      auditFields.add(audit);
-    }
-    if (!hasUpdatedField) {
-      OBViewFieldAudit audit = new OBViewFieldAudit("updated", OBViewUtil.updatedElement);
-      auditFields.add(audit);
-    }
-    if (!hasUpdatedByField) {
-      OBViewFieldAudit audit = new OBViewFieldAudit("updatedBy", OBViewUtil.updatedByElement);
-      auditFields.add(audit);
-    }
-
-    OBViewFieldGroup currentFieldGroup = null;
-    FieldGroup currentADFieldGroup = null;
-    int colNum = 1;
-    for (Field field : adFields) {
-
-      if (field.getColumn() == null || !field.isActive() || !field.isDisplayed()
-          || ApplicationUtils.isUIButton(field)) {
-        continue;
-      }
-
-      final Property property = KernelUtils.getInstance().getPropertyFromColumn(field.getColumn(),
-          false);
-
-      final OBViewField viewField = new OBViewField();
-      viewField.setField(field);
-      viewField.setProperty(property);
-      viewField.setRedrawOnChange(fieldsInDynamicExpression.contains(field));
-      viewField.setShowIf(displayLogicMap.get(field) != null ? displayLogicMap.get(field) : "");
-      viewField.setReadOnlyIf(readOnlyLogicMap.get(field) != null ? readOnlyLogicMap.get(field)
-          : "");
-      // Positioning some fields in odd-columns
-      if (colNum % 2 == 0 && (field.isStartinoddcolumn() || viewField.getColSpan() == 2)) {
-        final OBViewFieldSpacer spacer = new OBViewFieldSpacer();
-        fields.add(spacer);
-        colNum++;
-        if (colNum > 4) {
-          colNum = 1;
-        }
-      }
-
-      // change in fieldgroup
-      if (field.getFieldGroup() != null && field.getFieldGroup() != currentADFieldGroup) {
-        // start of a fieldgroup use it
-        final OBViewFieldGroup viewFieldGroup = new OBViewFieldGroup();
-        fields.add(viewFieldGroup);
-        viewFieldGroup.setFieldGroup(field.getFieldGroup());
-
-        currentFieldGroup = viewFieldGroup;
-        currentADFieldGroup = field.getFieldGroup();
-        colNum = 1;
-      }
-
-      fields.add(viewField);
-
-      if (currentFieldGroup != null) {
-        currentFieldGroup.addChild(viewField);
-      }
-
-      colNum += viewField.getColSpan();
-      if (colNum > 4) {
-        colNum = 1;
-      }
-    }
-
-    // Add audit info
-    if (!auditFields.isEmpty()) {
-      final OBViewFieldGroup viewFieldGroup = new OBViewFieldGroup();
-      viewFieldGroup.setType("OBAuditSectionItem");
-      viewFieldGroup.setPersonalizable(false);
-      fields.add(viewFieldGroup);
-      viewFieldGroup.setFieldGroup(OBDal.getInstance().get(FieldGroup.class, AUDIT_GROUP_ID));
-      viewFieldGroup.addChildren(auditFields);
-      fields.addAll(auditFields);
-    }
-
-    // add the notes part
-    final OBViewFieldDefinition notesCanvasFieldDefinition = new NotesCanvasField();
-    final NotesField notesField = new NotesField();
-    notesField.setChildField(notesCanvasFieldDefinition);
-    fields.add(notesField);
-    fields.add(notesCanvasFieldDefinition);
-
-    // add the linked items part
-    final OBViewFieldDefinition linkedItemsCanvasFieldDefinition = new LinkedItemsCanvasField();
-    final LinkedItemsField linkedItemsField = new LinkedItemsField();
-    linkedItemsField.setChildField(linkedItemsCanvasFieldDefinition);
-    fields.add(linkedItemsField);
-    fields.add(linkedItemsCanvasFieldDefinition);
-
-    // add the attachments part
-    final AttachmentsCanvasField attachmentsCanvas = new AttachmentsCanvasField();
-    final AttachmentsField attachmentDefinition = new AttachmentsField();
-    attachmentDefinition.setChildField(attachmentsCanvas);
-    fields.add(attachmentDefinition);
-    fields.add(attachmentsCanvas);
-
-    // add status bar fields
-    processStatusBarFields(fields, adFields);
-
-    return fields;
-  }
-
-  public List<String> getStatusBarFields() {
-    if (statusBarFields == null) {
-      log.warn("Calling getStatusBarFields without initializing fields cache");
-      return Collections.emptyList();
-    }
-    return statusBarFields;
-  }
-
-  private void processStatusBarFields(List<OBViewFieldDefinition> fields, List<Field> adFields) {
-    for (Field field : adFields) {
-
-      if (field.isShownInStatusBar() == null || !field.isShownInStatusBar()) {
-        continue;
-      }
-
-      final Property property = KernelUtils.getInstance().getPropertyFromColumn(field.getColumn(),
-          false);
-
-      statusBarFields.add(property.getName());
-
-      if (field.isDisplayed()) {
-        continue;
-      }
-
-      final OBViewField viewField = new OBViewField();
-      viewField.setField(field);
-      viewField.setProperty(property);
-      viewField.setRedrawOnChange(false);
-      viewField.setShowIf("");
-      viewField.setReadOnlyIf("");
-
-      fields.add(viewField);
-    }
-  }
-
-  private interface OBViewFieldDefinition {
-    public String getLabel();
-
-    public String getName();
-
-    public String getType();
-
-    public boolean getStandardField();
-
-    public boolean isPersonalizable();
-
-    public String getFieldProperties();
-
-    public String getInpColumnName();
-
-    public String getReferencedKeyColumnName();
-
-    public String getTargetEntity();
-
-    public boolean getStartRow();
-
-    public boolean getEndRow();
-
-    public long getColSpan();
-
-    public long getRowSpan();
-
-    public boolean isReadOnly();
-
-    public boolean isUpdatable();
-
-    public boolean isParentProperty();
-
-    public boolean getRedrawOnChange();
-
-    public String getShowIf();
-
-    public String getReadOnlyIf();
-
-    public boolean isDisplayed();
-
-    public boolean getHasDefaultValue();
-  }
-
-  public class OBViewFieldAudit implements OBViewFieldDefinition {
-    private String name;
-    private String refType;
-    private String refEntity;
-    private Element element;
-
-    public OBViewFieldAudit(String type, Element element) {
-      name = type;
-      this.element = element;
-
-      if (type.endsWith("By")) {
-        // User search
-        refType = "30";
-        refEntity = "User";
-      } else {
-        // Date time
-        refType = "16";
-        refEntity = "";
-      }
-    }
-
-    @Override
-    public String getLabel() {
-      return OBViewUtil.getLabel(element, element.getADElementTrlList());
-    }
-
-    @Override
-    public String getName() {
-      return name;
-    }
-
-    @Override
-    public String getType() {
-      return "_id_" + refType;
-    }
-
-    @Override
-    public boolean getStandardField() {
-      return true;
-    }
-
-    @Override
-    public String getFieldProperties() {
-      return "'width': '*', ";
-    }
-
-    @Override
-    public String getInpColumnName() {
-      return "";
-    }
-
-    @Override
-    public String getReferencedKeyColumnName() {
-      return "";
-    }
-
-    public boolean getHasDefaultValue() {
-      return false;
-    }
-
-    @Override
-    public String getTargetEntity() {
-      return refEntity;
-    }
-
-    @Override
-    public boolean getStartRow() {
-      return false;
-    }
-
-    @Override
-    public boolean getEndRow() {
-      return false;
-    }
-
-    @Override
-    public long getColSpan() {
-      return 1;
-    }
-
-    @Override
-    public long getRowSpan() {
-      return 1;
-    }
-
-    @Override
-    public boolean isReadOnly() {
-      return true;
-    }
-
-    @Override
-    public boolean isUpdatable() {
-      return false;
-    }
-
-    public boolean isPersonalizable() {
-      return false;
-    }
-
-    @Override
-    public boolean isParentProperty() {
-      return false;
-    }
-
-    @Override
-    public boolean getRedrawOnChange() {
-      return false;
-    }
-
-    @Override
-    public String getShowIf() {
-      return "";
-    }
-
-    @Override
-    public String getReadOnlyIf() {
-      return "";
-    }
-
-    public boolean isRequired() {
-      return false;
-    }
-
-    public String getColumnName() {
-      return "";
-    }
-
-    public boolean isFirstFocusedField() {
-      return false;
-    }
-
-    public boolean isSearchField() {
-      return !refEntity.isEmpty();
-    }
-
-    public boolean isDisplayed() {
-      return true;
-    }
-  }
-
-  public class OBViewField implements OBViewFieldDefinition {
-    private Field field;
-    private Property property;
-    private String label;
-    private UIDefinition uiDefinition;
-    private Boolean isParentProperty = null;
-    private boolean redrawOnChange = false;
-    private String showIf = "";
-    private String readOnlyIf = "";
-
-    /**
-     * @deprecated use {@link #setRedrawOnChange(boolean)}
-     */
-    @Deprecated
-    public void setReadrawOnChange(boolean value) {
-      this.setRedrawOnChange(value);
-    }
-
-    public boolean isReadOnly() {
-      return isParentProperty() || field.isReadOnly();
-    }
-
-    public boolean isUpdatable() {
-      return property.isUpdatable();
-    }
-
-    public boolean isPersonalizable() {
-      return true;
-    }
-
-    public boolean isParentProperty() {
-      if (isParentProperty == null) {
-        if (OBViewFormComponent.this.getParentProperty() == null) {
-          isParentProperty = false;
-        } else {
-          isParentProperty = OBViewFormComponent.this.getParentProperty()
-              .equals(property.getName());
-        }
-      }
-      return isParentProperty;
-    }
-
-    public boolean isSearchField() {
-      return uiDefinition instanceof FKSearchUIDefinition;
-    }
-
-    public boolean isFirstFocusedField() {
-      Boolean focused = field.isFirstFocusedField();
-      Boolean displayed = field.isDisplayed();
-      return focused != null && focused && displayed != null && displayed;
-    }
-
-    public String getType() {
-      return getUIDefinition().getName();
-    }
-
-    public boolean getHasDefaultValue() {
-      return field.getColumn().getDefaultValue() != null;
-    }
-
-    public String getFieldProperties() {
-
-      String jsonString = getUIDefinition().getFieldProperties(field).trim();
-      if (jsonString == null || jsonString.trim().length() == 0) {
-        return "";
-      }
-      // strip the first and last { }
-      if (jsonString.startsWith("{") && jsonString.endsWith("}")) {
-        // note -2 is done because the first substring takes of 1 already
-        return jsonString.substring(1).substring(0, jsonString.length() - 2) + ",";
-      } else if (jsonString.equals("{}")) {
-        return "";
-      }
-      // be lenient just return the string as it is...
-      return jsonString + (jsonString.trim().endsWith(",") ? "" : ",");
-    }
-
-    private UIDefinition getUIDefinition() {
-      if (uiDefinition != null) {
-        return uiDefinition;
-      }
-      uiDefinition = UIDefinitionController.getInstance().getUIDefinition(property.getColumnId());
-      return uiDefinition;
-    }
-
-    public String getName() {
-      return property.getName();
-    }
-
-    public String getColumnName() {
-      return property.getColumnName();
-    }
-
-    public String getInpColumnName() {
-      return "inp" + Sqlc.TransformaNombreColumna(property.getColumnName());
-    }
-
-    public String getReferencedKeyColumnName() {
-      if (property.isOneToMany() || property.isPrimitive()) {
-        return "";
-      }
-      Property prop;
-      if (property.getReferencedProperty() == null) {
-        prop = property.getTargetEntity().getIdProperties().get(0);
-      } else {
-        prop = property.getReferencedProperty();
-      }
-      return prop.getColumnName();
-    }
-
-    public String getTargetEntity() {
-      if (property.isOneToMany() || property.isPrimitive()) {
-        return "";
-      }
-      return property.getTargetEntity().getName();
-    }
-
-    public String getLabel() {
-      // compute the label
-      if (label == null) {
-        label = OBViewUtil.getLabel(field);
-      }
-      return label;
-    }
-
-    public void setLabel(String label) {
-      this.label = label;
-    }
-
-    public Field getField() {
-      return field;
-    }
-
-    public void setField(Field field) {
-      this.field = field;
-    }
-
-    public boolean getStandardField() {
-      return true;
-    }
-
-    public Property getProperty() {
-      return property;
-    }
-
-    public void setProperty(Property property) {
-      this.property = property;
-    }
-
-    public boolean isRequired() {
-      // booleans are never required as their input only allows 2 values
-      if (property.isBoolean()) {
-        return false;
-      }
-
-      if (field.getColumn() != null) {
-        // Taking value from AD definition, mandatoriness of a column can be different in AD and in
-        // memory model, because memory model sets mandatoriness regarding physical DB definition.
-        return field.getColumn().isMandatory();
-      } else {
-        return property.isMandatory();
-      }
-    }
-
-    public int getLength() {
-      return property.getFieldLength();
-    }
-
-    public boolean getForeignKeyField() {
-      return property.getDomainType() instanceof ForeignKeyDomainType;
-    }
-
-    public String getDataSourceId() {
-      return property.getTargetEntity().getName();
-    }
-
-    public long getColSpan() {
-      if (field.getObuiappColspan() != null) {
-        return field.getObuiappColspan();
-      }
-      return field.getDisplayedLength() > ONE_COLUMN_MAX_LENGTH
-          || (getRowSpan() == 2 && !property.getDomainType().getReference().getId()
-              .equals(IMAGEBLOB_AD_REFERENCE_ID)) ? 2 : 1;
-    }
-
-    public boolean getEndRow() {
-      return false;
-    }
-
-    public long getRowSpan() {
-      if (field.getObuiappRowspan() != null) {
-        return field.getObuiappRowspan();
-      }
-      if (property.getDomainType().getReference().getId().equals(TEXT_AD_REFERENCE_ID)) {
-        return 2;
-      }
-      if (property.getDomainType().getReference().getId().equals(IMAGEBLOB_AD_REFERENCE_ID)) {
-        return 2;
-      }
-      return 1;
-    }
-
-    public boolean getStartRow() {
-      return field.isStartnewline();
-    }
-
-    public void setRedrawOnChange(boolean redrawOnChange) {
-      this.redrawOnChange = redrawOnChange;
-    }
-
-    public boolean getRedrawOnChange() {
-      return redrawOnChange;
-    }
-
-    public void setShowIf(String showIf) {
-      this.showIf = showIf;
-    }
-
-    public String getShowIf() {
-      return showIf;
-    }
-
-    public void setReadOnlyIf(String readOnlyExpression) {
-      this.readOnlyIf = readOnlyExpression;
-    }
-
-    public String getReadOnlyIf() {
-      return readOnlyIf;
-    }
-
-    public boolean isDisplayed() {
-      return field.isDisplayed() != null && field.isDisplayed();
-    }
-  }
-
-  public class DefaultVirtualField implements OBViewFieldDefinition {
-
-    public String getFieldProperties() {
-      return "";
-    }
-
-    public boolean getHasDefaultValue() {
-      return false;
-    }
-
-    public boolean isReadOnly() {
-      return false;
-    }
-
-    public boolean isUpdatable() {
-      return true;
-    }
-
-    public boolean isParentProperty() {
-      return false;
-    }
-
-    public boolean isPersonalizable() {
-      return false;
-    }
-
-    public String getInpColumnName() {
-      return "";
-    }
-
-    public String getReferencedKeyColumnName() {
-      return "";
-    }
-
-    public String getTargetEntity() {
-      return "";
-    }
-
-    public long getColSpan() {
-      return 4;
-    }
-
-    public boolean getEndRow() {
-      return true;
-    }
-
-    public long getRowSpan() {
-      return 1;
-    }
-
-    public boolean getStartRow() {
-      return true;
-    }
-
-    public boolean getStandardField() {
-      return false;
-    }
-
-    public String getLabel() {
-      return "";
-    }
-
-    public String getName() {
-      return "";
-    }
-
-    public String getType() {
-      return "";
-    }
-
-    public boolean getRedrawOnChange() {
-      return false;
-    }
-
-    public String getShowIf() {
-      return "";
-    }
-
-    public String getReadOnlyIf() {
-      return "";
-    }
-
-    public boolean isDisplayed() {
-      return true;
-    }
-  }
-
-  public class OBViewFieldGroup extends DefaultVirtualField {
-
-    private boolean expanded = true;
-    private String type;
-    private FieldGroup fieldGroup;
-    private String label;
-    private List<OBViewFieldDefinition> children = new ArrayList<OBViewFieldDefinition>();
-    private boolean personalizable = true;
-
-    public OBViewFieldGroup() {
-      type = "OBSectionItem";
-    }
-
-    public boolean isPersonalizable() {
-      return personalizable;
-    }
-
-    public String getLabel() {
-      // compute the label
-      if (label == null) {
-        label = OBViewUtil.getLabel(fieldGroup, fieldGroup.getADFieldGroupTrlList());
-      }
-      return label;
-    }
-
-    public void setLabel(String label) {
-      this.label = label;
-    }
-
-    public FieldGroup getFieldGroup() {
-      return fieldGroup;
-    }
-
-    public void setFieldGroup(FieldGroup fieldGroup) {
-      if (AUDIT_GROUP_ID.equals(fieldGroup.getId())
-          || MORE_INFO_GROUP_ID.equals(fieldGroup.getId())) {
-        expanded = false;
-      }
-
-      this.fieldGroup = fieldGroup;
-    }
-
-    public void addChild(OBViewFieldDefinition viewFieldDefinition) {
-      children.add(viewFieldDefinition);
-    }
-
-    public void addChildren(List<OBViewFieldDefinition> viewFieldDefinitions) {
-      children.addAll(viewFieldDefinitions);
-    }
-
-    public List<OBViewFieldDefinition> getChildren() {
-      return children;
-    }
-
-    public String getType() {
-      return type;
-    }
-
-    public void setType(String type) {
-      this.type = type;
-    }
-
-    public String getName() {
-      return fieldGroup.getId();
-    }
-
-    public boolean isExpanded() {
-      return expanded;
-    }
-
-    public void setExpanded(boolean expanded) {
-      this.expanded = expanded;
-    }
-
-    public boolean isDisplayed() {
-      for (OBViewFieldDefinition child : children) {
-        if (child.isDisplayed()) {
-          return true;
-        }
-      }
-      return false;
-    }
-
-    public void setPersonalizable(boolean personalizable) {
-      this.personalizable = personalizable;
-    }
-  }
-
-  public class AttachmentsCanvasField extends DefaultVirtualField {
-
-    public String getName() {
-      return "_attachments_Canvas";
-    }
-
-    public String getType() {
-      return "OBAttachmentCanvasItem";
-    }
-
-  }
-
-  public class AttachmentsField extends DefaultVirtualField {
-
-    private OBViewFieldDefinition childField;
-
-    public String getLabel() {
-      // is set at runtime
-      return "dummy";
-    }
-
-    public boolean getEndRow() {
-      return true;
-    }
-
-    public List<OBViewFieldDefinition> getChildren() {
-      return Collections.singletonList(childField);
-
-    }
-
-    public String getType() {
-      return "OBAttachmentsSectionItem";
-    }
-
-    public boolean getStartRow() {
-      return true;
-    }
-
-    public boolean getRedrawOnChange() {
-      return false;
-    }
-
-    public String getName() {
-      return "_attachments_";
-    }
-
-    public OBViewFieldDefinition getChildField() {
-      return childField;
-    }
-
-    public void setChildField(OBViewFieldDefinition childField) {
-      this.childField = childField;
-    }
-
-    public boolean isExpanded() {
-      return false;
-    }
-  }
-
-  public class LinkedItemsField extends DefaultVirtualField {
-
-    private OBViewFieldDefinition childField;
-
-    public String getLabel() {
-      // is set at runtime
-      return "dummy";
-    }
-
-    public boolean getEndRow() {
-      return true;
-    }
-
-    public List<OBViewFieldDefinition> getChildren() {
-      return Collections.singletonList(childField);
-
-    }
-
-    public String getType() {
-      return "OBLinkedItemSectionItem";
-    }
-
-    public boolean getStartRow() {
-      return true;
-    }
-
-    public boolean getRedrawOnChange() {
-      return false;
-    }
-
-    public String getName() {
-      return "_linkedItems_";
-    }
-
-    public OBViewFieldDefinition getChildField() {
-      return childField;
-    }
-
-    public void setChildField(OBViewFieldDefinition childField) {
-      this.childField = childField;
-    }
-
-    public boolean isExpanded() {
-      return false;
-    }
-  }
-
-  private class LinkedItemsCanvasField extends DefaultVirtualField {
-
-    public String getLabel() {
-      // is set at runtime
-      return "dummy";
-    }
-
-    @SuppressWarnings("unused")
-    public List<OBViewFieldDefinition> getChildren() {
-      return Collections.emptyList();
-    }
-
-    public String getType() {
-      return "OBLinkedItemCanvasItem";
-    }
-
-    public String getName() {
-      return "_linkedItems_Canvas";
-    }
-  }
-
-  public class NotesField extends DefaultVirtualField {
-
-    private OBViewFieldDefinition childField;
-
-    public String getLabel() {
-      // is set at runtime
-      return "dummy";
-    }
-
-    public boolean getEndRow() {
-      return true;
-    }
-
-    public List<OBViewFieldDefinition> getChildren() {
-      return Collections.singletonList(childField);
-
-    }
-
-    public String getType() {
-      return "OBNoteSectionItem";
-    }
-
-    public boolean getStartRow() {
-      return true;
-    }
-
-    public boolean getRedrawOnChange() {
-      return false;
-    }
-
-    public String getName() {
-      return "_notes_";
-    }
-
-    public OBViewFieldDefinition getChildField() {
-      return childField;
-    }
-
-    public void setChildField(OBViewFieldDefinition childField) {
-      this.childField = childField;
-    }
-
-    public boolean isExpanded() {
-      return false;
-    }
-  }
-
-  private class NotesCanvasField extends DefaultVirtualField {
-
-    public String getLabel() {
-      // is set at runtime
-      return "dummy";
-    }
-
-    @SuppressWarnings("unused")
-    public List<OBViewFieldDefinition> getChildren() {
-      return Collections.emptyList();
-    }
-
-    public String getType() {
-      return "OBNoteCanvasItem";
-    }
-
-    public String getName() {
-      return "_notes_Canvas";
-    }
-
-  }
-
-  public class OBViewFieldSpacer implements OBViewFieldDefinition {
-
-    public boolean isPersonalizable() {
-      return false;
-    }
-
-    public boolean getHasDefaultValue() {
-      return false;
-    }
-
-    public long getColSpan() {
-      return 1;
-    }
-
-    public boolean getEndRow() {
-      return false;
-    }
-
-    public boolean isReadOnly() {
-      return false;
-    }
-
-    public boolean isUpdatable() {
-      return true;
-    }
-
-    public boolean isParentProperty() {
-      return false;
-    }
-
-    public String getFieldProperties() {
-      return "";
-    }
-
-    public String getInpColumnName() {
-      return "";
-    }
-
-    public String getLabel() {
-      return "";
-    }
-
-    public String getName() {
-      return "";
-    }
-
-    public String getReferencedKeyColumnName() {
-      return "";
-    }
-
-    public String getTargetEntity() {
-      return "";
-    }
-
-    public long getRowSpan() {
-      return 1;
-    }
-
-    public boolean getStandardField() {
-      return false;
-    }
-
-    public boolean getStartRow() {
-      return false;
-    }
-
-    public String getType() {
-      return "spacer";
-    }
-
-    public boolean getRedrawOnChange() {
-      return false;
-    }
-
-    public String getShowIf() {
-      return "";
-    }
-
-    public String getReadOnlyIf() {
-      return "";
-    }
-
-    public boolean isDisplayed() {
-      return true;
-    }
-
-  }
-
-  public static class FormFieldComparator implements Comparator<Field> {
-
-    /**
-     * Fields with null sequence number are in the bottom of the form. In case multiple null
-     * sequences, it is sorted by field UUID.
-     */
-    @Override
-    public int compare(Field arg0, Field arg1) {
-      Long arg0Position = arg0.getSequenceNumber();
-      Long arg1Position = arg1.getSequenceNumber();
-
-      if (arg0Position == null && arg1Position == null) {
-        return arg0.getId().compareTo(arg1.getId());
-      } else if (arg0Position == null) {
-        return 1;
-      } else if (arg1Position == null) {
-        return -1;
-      }
-
-      return (int) (arg0Position - arg1Position);
-    }
-
-  }
-
   public String getParentProperty() {
     return parentProperty;
   }
@@ -1208,4 +54,12 @@
   public void setTemplateId(String templateId) {
     this.templateId = templateId;
   }
+
+  public OBViewFieldHandler getFieldHandler() {
+    return fieldHandler;
+  }
+
+  public void setFieldHandler(OBViewFieldHandler fieldHandler) {
+    this.fieldHandler = fieldHandler;
+  }
 }
--- a/modules/org.openbravo.client.application/src/org/openbravo/client/application/window/OBViewGridComponent.java	Thu Oct 13 18:24:25 2011 +0200
+++ b/modules/org.openbravo.client.application/src/org/openbravo/client/application/window/OBViewGridComponent.java	Thu Oct 20 13:09:18 2011 +0200
@@ -18,32 +18,17 @@
  */
 package org.openbravo.client.application.window;
 
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.Comparator;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
 import org.openbravo.base.model.Entity;
 import org.openbravo.base.model.ModelProvider;
-import org.openbravo.base.model.Property;
-import org.openbravo.client.application.ApplicationUtils;
-import org.openbravo.client.application.DynamicExpressionParser;
+import org.openbravo.client.application.window.OBViewFieldHandler.OBViewField;
+import org.openbravo.client.application.window.OBViewFieldHandler.OBViewFieldDefinition;
 import org.openbravo.client.kernel.BaseTemplateComponent;
-import org.openbravo.client.kernel.KernelUtils;
 import org.openbravo.client.kernel.RequestContext;
 import org.openbravo.client.kernel.Template;
-import org.openbravo.client.kernel.reference.StringUIDefinition;
-import org.openbravo.client.kernel.reference.UIDefinition;
-import org.openbravo.client.kernel.reference.UIDefinitionController;
 import org.openbravo.dal.core.DalUtil;
 import org.openbravo.dal.core.OBContext;
 import org.openbravo.dal.service.OBDal;
-import org.openbravo.data.Sqlc;
 import org.openbravo.erpCommon.utility.Utility;
-import org.openbravo.model.ad.ui.Element;
-import org.openbravo.model.ad.ui.Field;
 import org.openbravo.model.ad.ui.Tab;
 import org.openbravo.model.common.order.Order;
 import org.openbravo.model.common.order.OrderLine;
@@ -58,16 +43,12 @@
 public class OBViewGridComponent extends BaseTemplateComponent {
 
   private static final String TEMPLATE_ID = "91DD63545B674BE8801E1FA4F48FF4C6";
-  private static Long ZERO = new Long(0);
 
   private boolean applyTransactionalFilter = false;
   private Tab tab;
   private Entity entity;
-  private List<LocalField> fields = null;
 
-  private final List<Field> fieldsInDynamicExpression = new ArrayList<Field>();
-  private final Map<Field, String> displayLogicMap = new HashMap<Field, String>();
-  private final Map<Field, String> readOnlyLogicMap = new HashMap<Field, String>();
+  private OBViewTab viewTab;
 
   protected Template getComponentTemplate() {
     return OBDal.getInstance().get(Template.class, TEMPLATE_ID);
@@ -103,11 +84,16 @@
     }
 
     long lowestSortno = Long.MAX_VALUE;
-    LocalField sortByField = null;
-    for (LocalField localField : getFields()) {
-      final Long recordSortno = localField.getField().getRecordSortNo();
-      if (localField.isInitialShow() && recordSortno != null && recordSortno < lowestSortno) {
-        sortByField = localField;
+    OBViewField sortByField = null;
+    for (OBViewFieldDefinition localField : getViewTab().getFieldHandler().getFields()) {
+      if (!(localField instanceof OBViewField)) {
+        continue;
+      }
+      final OBViewField viewField = (OBViewField) localField;
+      final Long recordSortno = viewField.getField().getRecordSortNo();
+      if (viewField.getLength() < 2000 && viewField.isShowInitiallyInGrid() && recordSortno != null
+          && recordSortno < lowestSortno) {
+        sortByField = viewField;
       }
     }
     if (sortByField != null && sortByField.getProperty() != null) {
@@ -122,9 +108,13 @@
       return OrderLine.PROPERTY_LINENO;
     }
 
-    for (LocalField localField : getFields()) {
-      if (localField.getProperty() != null && localField.getProperty().isIdentifier()) {
-        return localField.getProperty().getName();
+    for (OBViewFieldDefinition localField : getViewTab().getFieldHandler().getFields()) {
+      if (!(localField instanceof OBViewField)) {
+        continue;
+      }
+      final OBViewField viewField = (OBViewField) localField;
+      if (viewField.getProperty() != null && viewField.getProperty().isIdentifier()) {
+        return viewField.getProperty().getName();
       }
     }
     return "";
@@ -192,458 +182,6 @@
     return tab.getUIPattern();
   }
 
-  public List<String> getForeignKeyFields() {
-    final List<String> fkFields = new ArrayList<String>();
-    for (LocalField field : getFields()) {
-      if (!field.getProperty().isPrimitive()) {
-        fkFields.add(field.getProperty().getName());
-      }
-    }
-    return fkFields;
-  }
-
-  public List<String> getAutoExpandFields() {
-    List<LocalField> autoExpandFields = new ArrayList<LocalField>();
-    for (LocalField field : getFields()) {
-      if (new Boolean(field.getAutoExpand())) {
-        autoExpandFields.add(field);
-      }
-    }
-    Collections.sort(autoExpandFields, new LengthComparator());
-    List<String> autoExpandFieldsStr = new ArrayList<String>();
-    for (LocalField field : autoExpandFields) {
-      autoExpandFieldsStr.add(field.getProperty().getName());
-    }
-    return autoExpandFieldsStr;
-  }
-
-  private class LengthComparator implements Comparator<LocalField> {
-    @Override
-    public int compare(LocalField o1, LocalField o2) {
-      return o2.getLength().compareTo(o1.getLength());
-    }
-  }
-
-  public List<LocalField> getFields() {
-    if (fields != null) {
-      return fields;
-    }
-    fields = new ArrayList<LocalField>();
-    final List<String> windowEntities = getWindowEntities();
-    final List<Field> sortedFields = new ArrayList<Field>(tab.getADFieldList());
-    Collections.sort(sortedFields, new GridFieldComparator());
-
-    // Processing dynamic expressions (display logic)
-    for (Field f : sortedFields) {
-      if (f.getDisplayLogic() == null || f.getDisplayLogic().equals("") || !f.isActive()
-          || !f.isDisplayed()) {
-        continue;
-      }
-
-      final DynamicExpressionParser parser = new DynamicExpressionParser(f.getDisplayLogic(), tab);
-      displayLogicMap.put(f, parser.getJSExpression());
-
-      for (Field fieldExpression : parser.getFields()) {
-        if (!fieldsInDynamicExpression.contains(fieldExpression)) {
-          fieldsInDynamicExpression.add(fieldExpression);
-        }
-      }
-    }
-
-    // first add the grid fields
-    for (Field fld : sortedFields) {
-      if (fld.isActive() && fld.isShowInGridView()) {
-        final Property prop = KernelUtils.getInstance().getPropertyFromColumn(fld.getColumn());
-        if (prop.isParent() && windowEntities.contains(prop.getTargetEntity().getName())) {
-          continue;
-        }
-        if (prop.isId()) {
-          continue;
-        }
-        if (ApplicationUtils.isUIButton(fld)) {
-          continue;
-        }
-        // these are currently also ignored
-        if (fld.getGridPosition() == null && fld.getSequenceNumber() == null) {
-          continue;
-        }
-
-        fields.add(createLocalField(fld, prop, true));
-      }
-    }
-
-    // Processing dynamic expression (read-only logic)
-    for (Field f : sortedFields) {
-      if (f.getColumn().getReadOnlyLogic() == null || f.getColumn().getReadOnlyLogic().equals("")
-          || !f.isActive() || !f.getColumn().isActive()) {
-        continue;
-      }
-
-      final DynamicExpressionParser parser = new DynamicExpressionParser(f.getColumn()
-          .getReadOnlyLogic(), tab);
-      readOnlyLogicMap.put(f, parser.getJSExpression());
-
-      for (Field fieldExpression : parser.getFields()) {
-        if (!fieldsInDynamicExpression.contains(fieldExpression)) {
-          fieldsInDynamicExpression.add(fieldExpression);
-        }
-      }
-    }
-
-    // and add the non grid fields
-    for (Field fld : sortedFields) {
-      if (fld.isActive() && !fld.isShowInGridView()) {
-        final Property prop = KernelUtils.getInstance().getPropertyFromColumn(fld.getColumn());
-        if (prop.isParent() && windowEntities.contains(prop.getTargetEntity().getName())) {
-          continue;
-        }
-        if (prop.isId()) {
-          continue;
-        }
-        if (ApplicationUtils.isUIButton(fld)) {
-          continue;
-        }
-        fields.add(createLocalField(fld, prop, false));
-      }
-    }
-
-    return fields;
-  }
-
-  public List<AuditLocalField> getAuditFields() {
-    boolean hasCreatedField = false, hasCreatedByField = false, hasUpdatedField = false, hasUpdatedByField = false;
-    for (Field f : tab.getADFieldList()) {
-      String dbColName = f.getColumn().getDBColumnName().toLowerCase();
-      if (!dbColName.startsWith("created") && !dbColName.startsWith("updated")) {
-        continue;
-      }
-      if (f.isActive() && f.getColumn().isActive() && (f.isDisplayed() || f.isShownInStatusBar())) {
-        if ("created".equals(dbColName)) {
-          hasCreatedField = true;
-        } else if ("createdby".equals(dbColName)) {
-          hasCreatedByField = true;
-        } else if ("updated".equals(dbColName)) {
-          hasUpdatedField = true;
-        } else if ("updatedby".equals(dbColName)) {
-          hasUpdatedByField = true;
-        }
-      }
-    }
-
-    List<AuditLocalField> auditFields = new ArrayList<OBViewGridComponent.AuditLocalField>();
-
-    if (!hasCreatedField) {
-      AuditLocalField created = new AuditLocalField("creationDate", OBViewUtil.createdElement);
-      auditFields.add(created);
-    }
-
-    if (!hasCreatedByField) {
-      AuditLocalField createdBy = new AuditLocalField("createdBy", OBViewUtil.createdByElement);
-      auditFields.add(createdBy);
-    }
-
-    if (!hasUpdatedField) {
-      AuditLocalField updated = new AuditLocalField("updated", OBViewUtil.updatedElement);
-      auditFields.add(updated);
-    }
-
-    if (!hasUpdatedByField) {
-      AuditLocalField updatedBy = new AuditLocalField("updatedBy", OBViewUtil.updatedByElement);
-      auditFields.add(updatedBy);
-    }
-    return auditFields;
-  }
-
-  private LocalField createLocalField(Field fld, Property prop, boolean showInitially) {
-    final LocalField localField = new LocalField();
-    localField.setField(fld);
-    localField.setProperty(prop);
-    localField.setUIDefinition(UIDefinitionController.getInstance().getUIDefinition(
-        prop.getColumnId()));
-    if (!prop.isPrimitive()) {
-      localField.setName(prop.getName() + "." + JsonConstants.IDENTIFIER);
-    } else {
-      localField.setName(prop.getName());
-    }
-    localField.setTitle(OBViewUtil.getLabel(fld));
-    localField.setInitialShow(showInitially);
-    localField.setRedrawOnChange(fieldsInDynamicExpression.contains(fld));
-    localField.setShowIf(displayLogicMap.get(fld) != null ? displayLogicMap.get(fld) : "");
-
-    return localField;
-  }
-
-  public class LocalField {
-    private String name;
-    private Field field;
-    private String title;
-    private Property property;
-    private UIDefinition uiDefinition;
-    private boolean initialShow;
-    private String showIf;
-    private boolean redrawOnChange;
-
-    public boolean isFirstFocusedField() {
-      Boolean focused = field.isFirstFocusedField();
-      Boolean displayed = field.isDisplayed();
-      return focused != null && focused && displayed != null && displayed;
-    }
-
-    public String getColumnName() {
-      return property.getColumnName();
-    }
-
-    public boolean isRequired() {
-      // booleans are never required as their input only allows 2 values
-      if (property.isBoolean()) {
-        return false;
-      }
-      return property.isMandatory();
-    }
-
-    public boolean isReadOnly() {
-      return field.isReadOnly();
-    }
-
-    public boolean isUpdatable() {
-      return property.isUpdatable();
-    }
-
-    public String getInpColumnName() {
-      return "inp" + Sqlc.TransformaNombreColumna(property.getColumnName());
-    }
-
-    public String getReferencedKeyColumnName() {
-      if (property.isOneToMany() || property.isPrimitive()) {
-        return "";
-      }
-      Property prop;
-      if (property.getReferencedProperty() == null) {
-        prop = property.getTargetEntity().getIdProperties().get(0);
-      } else {
-        prop = property.getReferencedProperty();
-      }
-      return prop.getColumnName();
-    }
-
-    /**
-     * @deprecated use {@link #getGridFieldProperties()}
-     */
-    @Deprecated
-    public String getFieldProperties() {
-      return getGridFieldProperties();
-    }
-
-    public String getGridFieldProperties() {
-      return uiDefinition.getGridFieldProperties(field);
-    }
-
-    public String getTargetEntity() {
-      if (property.getTargetEntity() == null) {
-        return "";
-      }
-      return property.getTargetEntity().getName();
-    }
-
-    public String getGridEditorFieldProperties() {
-      String props = uiDefinition.getGridEditorFieldProperties(field).trim();
-      if (props.startsWith("{")) {
-        props = props.substring(1, props.length() - 1);
-      }
-      if (props.trim().endsWith(",")) {
-        return props.trim().substring(0, props.trim().length() - 1);
-      }
-      if (props.trim().length() == 0) {
-        // return at least a dummy property
-        return "_d: ''";
-      }
-      return props.trim();
-    }
-
-    public String getFilterEditorProperties() {
-      return uiDefinition.getFilterEditorProperties(field);
-    }
-
-    // can the column be auto expanded to fill any remaining space
-    public String getAutoExpand() {
-      return (Boolean.toString(!name.equalsIgnoreCase("documentno")
-          && (uiDefinition instanceof StringUIDefinition || !property.isPrimitive())));
-    }
-
-    public String getName() {
-      return name;
-    }
-
-    public void setName(String name) {
-      this.name = name;
-    }
-
-    public String getTitle() {
-      return title;
-    }
-
-    public void setTitle(String title) {
-      this.title = title;
-    }
-
-    public UIDefinition getUIDefinition() {
-      return uiDefinition;
-    }
-
-    public void setUIDefinition(UIDefinition typeDefinition) {
-      this.uiDefinition = typeDefinition;
-    }
-
-    public String getType() {
-      return uiDefinition.getName();
-    }
-
-    public Field getField() {
-      return field;
-    }
-
-    public void setField(Field field) {
-      this.field = field;
-    }
-
-    public Property getProperty() {
-      return property;
-    }
-
-    public void setProperty(Property property) {
-      this.property = property;
-    }
-
-    public boolean isInitialShow() {
-      return initialShow;
-    }
-
-    public void setInitialShow(boolean initialShow) {
-      this.initialShow = initialShow;
-    }
-
-    public String getShowIf() {
-      return showIf;
-    }
-
-    public void setShowIf(String showIf) {
-      this.showIf = showIf;
-    }
-
-    public boolean isRedrawOnChange() {
-      return redrawOnChange;
-    }
-
-    public void setRedrawOnChange(boolean redrawOnChange) {
-      this.redrawOnChange = redrawOnChange;
-    }
-
-    public Long getLength() {
-      return field.getDisplayedLength();
-    }
-
-    public String getCellAlign() {
-      return uiDefinition.getCellAlign();
-    }
-  }
-
-  public class AuditLocalField extends LocalField {
-
-    private String refType;
-    private String refEntity;
-    private String name;
-    private Element element;
-
-    public AuditLocalField(String type, Element element) {
-      name = type;
-      this.element = element;
-      if (type.endsWith("By")) {
-        // User search
-        refType = "30";
-        refEntity = "User";
-      } else {
-        // Date time
-        refType = "16";
-        refEntity = "";
-      }
-    }
-
-    @Override
-    public String getColumnName() {
-      return name;
-    }
-
-    @Override
-    public String getTargetEntity() {
-      return refEntity;
-    }
-
-    @Override
-    public String getTitle() {
-      return OBViewUtil.getLabel(element, element.getADElementTrlList());
-    }
-
-    @Override
-    public String getType() {
-      return "_id_" + refType;
-    }
-
-    public String getEditorType() {
-      if ("30".equals(refType)) {
-        return "OBSearchItem";
-      } else {
-        return "OBDateItem";
-      }
-    }
-
-    public String getFilterEditorType() {
-      if ("30".equals(refType)) {
-        return "OBFKFilterTextItem";
-      } else {
-        return "OBMiniDateRangeItem";
-      }
-    }
-
-    public String getDisplayFieldJS() {
-      if ("30".equals(refType)) {
-        return "displayField: '" + name + "._identifier',valueField: '" + name + "',";
-      } else {
-        return "";
-      }
-    }
-
-  }
-
-  private class GridFieldComparator implements Comparator<Field> {
-
-    @Override
-    public int compare(Field arg0, Field arg1) {
-      Long arg0Position = (arg0.getGridPosition() != null ? arg0.getGridPosition() : arg0
-          .getSequenceNumber());
-      Long arg1Position = (arg1.getGridPosition() != null ? arg1.getGridPosition() : arg1
-          .getSequenceNumber());
-
-      if (arg0Position == null && arg1Position == null) {
-        return arg0.getId().compareTo(arg1.getId());
-      } else if (arg0Position == null) {
-        return 1;
-      } else if (arg1Position == null) {
-        return -1;
-      }
-
-      return (int) (arg0Position - arg1Position);
-    }
-
-  }
-
-  private List<String> getWindowEntities() {
-    final List<String> windowEntities = new ArrayList<String>();
-    for (Tab localTab : tab.getWindow().getADTabList()) {
-      windowEntities.add(localTab.getTable().getName());
-    }
-    return windowEntities;
-  }
-
   public boolean isApplyTransactionalFilter() {
     return applyTransactionalFilter;
   }
@@ -652,4 +190,12 @@
     this.applyTransactionalFilter = applyTransactionalFilter;
   }
 
+  public OBViewTab getViewTab() {
+    return viewTab;
+  }
+
+  public void setViewTab(OBViewTab viewTab) {
+    this.viewTab = viewTab;
+  }
+
 }
--- a/modules/org.openbravo.client.application/src/org/openbravo/client/application/window/OBViewTab.java	Thu Oct 13 18:24:25 2011 +0200
+++ b/modules/org.openbravo.client.application/src/org/openbravo/client/application/window/OBViewTab.java	Thu Oct 20 13:09:18 2011 +0200
@@ -21,6 +21,7 @@
 import java.util.ArrayList;
 import java.util.Collection;
 import java.util.Collections;
+import java.util.Comparator;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
@@ -29,9 +30,9 @@
 
 import org.openbravo.base.model.Entity;
 import org.openbravo.base.model.ModelProvider;
+import org.openbravo.base.model.Property;
 import org.openbravo.client.application.ApplicationUtils;
 import org.openbravo.client.application.DynamicExpressionParser;
-import org.openbravo.client.application.window.OBViewFormComponent.FormFieldComparator;
 import org.openbravo.client.kernel.BaseTemplateComponent;
 import org.openbravo.client.kernel.Component;
 import org.openbravo.client.kernel.ComponentProvider;
@@ -64,6 +65,7 @@
 
   private static final String TEMPLATE_ID = "B5124C0A450D4D3A867AEAC7DF64D6F0";
 
+  private Entity entity;
   private Tab tab;
   private String tabTitle;
   private List<OBViewTab> childTabs = new ArrayList<OBViewTab>();
@@ -71,12 +73,13 @@
   private String parentProperty = null;
   private List<ButtonField> buttonFields = null;
   private List<IconButton> iconButtons = null;
-  private Field keyField;
-  private Column keyColumn;
   private boolean buttonSessionLogic;
   private boolean isRootTab;
 
   @Inject
+  private OBViewFieldHandler fieldHandler;
+
+  @Inject
   @ComponentProvider.Qualifier(DataSourceConstants.DS_COMPONENT_TYPE)
   private ComponentProvider componentProvider;
 
@@ -85,6 +88,7 @@
     final Map<String, Object> dsParameters = new HashMap<String, Object>(getParameters());
     dsParameters.put(DataSourceConstants.DS_ONLY_GENERATE_CREATESTATEMENT, true);
     dsParameters.put(DataSourceConstants.DS_CLASS_NAME, "OBViewDataSource");
+    dsParameters.put(DataSourceConstants.MINIMAL_PROPERTY_OUTPUT, true);
     final Component component = componentProvider.getComponent(dsId, dsParameters);
     return component.generate();
   }
@@ -93,13 +97,25 @@
     return OBDal.getInstance().get(Template.class, TEMPLATE_ID);
   }
 
+  public OBViewFieldHandler getFieldHandler() {
+    return fieldHandler;
+  }
+
+  public List<OtherField> getOtherFields() {
+    final List<OtherField> otherFields = new ArrayList<OBViewTab.OtherField>();
+    for (Field fld : fieldHandler.getIgnoredFields()) {
+      otherFields.add(new OtherField(fld.getColumn()));
+    }
+    return otherFields;
+  }
+
   public void addChildTabComponent(OBViewTab childTabComponent) {
     childTabComponent.setParentTabComponent(this);
     childTabs.add(childTabComponent);
   }
 
-  public String getDefaultEditMode() {
-    return tab.isDefaultEditMode() == null ? "false" : Boolean.toString(tab.isDefaultEditMode());
+  public boolean getDefaultEditMode() {
+    return tab.isDefaultEditMode() == null ? false : tab.isDefaultEditMode();
   }
 
   public String getMapping250() {
@@ -189,8 +205,7 @@
       return parentProperty;
     }
     if (tab.getTable().getId().equals(parentTabComponent.getTab().getTable().getId())) {
-      final Entity entity = ModelProvider.getInstance().getEntity(tab.getTable().getName());
-      parentProperty = entity.getIdProperties().get(0).getName();
+      parentProperty = getEntity().getIdProperties().get(0).getName();
     } else {
       parentProperty = ApplicationUtils.getParentProperty(tab, parentTabComponent.getTab());
     }
@@ -198,17 +213,24 @@
   }
 
   public String getViewForm() {
+    // force a load all the columns of the table
+    getTab().getTable().getADColumnList().size();
+
     final OBViewFormComponent viewFormComponent = createComponent(OBViewFormComponent.class);
     viewFormComponent.setParameters(getParameters());
-    viewFormComponent.setTab(tab);
     viewFormComponent.setParentProperty(getParentProperty());
+    viewFormComponent.setFieldHandler(fieldHandler);
     return viewFormComponent.generate();
   }
 
   public String getViewGrid() {
+    // force a load all the columns of the table
+    getTab().getTable().getADColumnList().size();
+
     final OBViewGridComponent viewGridComponent = createComponent(OBViewGridComponent.class);
     viewGridComponent.setParameters(getParameters());
     viewGridComponent.setTab(tab);
+    viewGridComponent.setViewTab(this);
     viewGridComponent.setApplyTransactionalFilter(isRootTab()
         && this.tab.getWindow().getWindowType().equals("T"));
     return viewGridComponent.generate();
@@ -232,6 +254,7 @@
 
   public void setTab(Tab tab) {
     this.tab = tab;
+    fieldHandler.setTab(tab);
   }
 
   public boolean isTabSet() {
@@ -246,8 +269,15 @@
     return tab.getModule().getId();
   }
 
+  private Entity getEntity() {
+    if (entity == null) {
+      entity = ModelProvider.getInstance().getEntity(tab.getTable().getName());
+    }
+    return entity;
+  }
+
   public String getEntityName() {
-    return tab.getTable().getName();
+    return getEntity().getName();
   }
 
   public String getTabTitle() {
@@ -274,67 +304,38 @@
     this.tabTitle = tabTitle;
   }
 
-  public boolean isAcctTab() {
+  public boolean getAcctTab() {
     return tab.isAccountingTab();
   }
 
-  public boolean isTrlTab() {
+  public boolean getTrlTab() {
     return tab.isTranslationTab();
   }
 
-  public List<FieldProperty> getAllFields() {
-    List<FieldProperty> fields = new ArrayList<FieldProperty>();
-    for (Field field : tab.getADFieldList()) {
-      if (field.getColumn().isKeyColumn()) {
-        keyField = field;
-      }
-      FieldProperty fp = new FieldProperty(field);
-
-      fields.add(fp);
-    }
-
-    // Additional key column, set in session with db column name
-    if (getKeyColumn() != null) {
-      FieldProperty fp = new FieldProperty(keyColumn);
-      fp.columnName = keyColumn.getDBColumnName();
-      fp.session = true;
-      fields.add(fp);
-    }
-
-    return fields;
-  }
-
-  private Column getKeyColumn() {
-    if (keyColumn != null) {
-      return keyColumn;
-    }
-
-    if (keyField != null) {
-      keyColumn = keyField.getColumn();
-    }
-
-    if (keyColumn == null) {
-      for (Column col : tab.getTable().getADColumnList()) {
-        if (col.isKeyColumn()) {
-          keyColumn = col;
-          break;
-        }
-      }
-    }
-
-    return keyColumn;
-  }
-
   public String getTableId() {
     return tab.getTable().getId();
   }
 
-  public String getKeyColumnId() {
-    return getKeyColumn().getDBColumnName();
+  public Property getKeyProperty() {
+    for (Property prop : getEntity().getProperties()) {
+      if (prop.isId()) {
+        return prop;
+      }
+    }
+    throw new IllegalStateException("Entity " + getEntityName() + " does not have an id property");
   }
 
-  public String getKeyName() {
-    return "inp" + Sqlc.TransformaNombreColumna(getKeyColumn().getDBColumnName());
+  public String getKeyPropertyType() {
+    return UIDefinitionController.getInstance().getUIDefinition(getKeyProperty().getColumnId())
+        .getName();
+  }
+
+  public String getKeyColumnName() {
+    return getKeyProperty().getColumnName();
+  }
+
+  public String getKeyInpName() {
+    return "inp" + Sqlc.TransformaNombreColumna(getKeyProperty().getColumnName());
   }
 
   public String getWindowId() {
@@ -350,61 +351,6 @@
     return buttonSessionLogic;
   }
 
-  public class FieldProperty {
-    private String columnName;
-    private String dbColumnName;
-    private String propertyName;
-    private boolean session;
-    private String typeName;
-
-    public FieldProperty() {
-      session = false;
-      propertyName = "";
-      columnName = "";
-      dbColumnName = "";
-    }
-
-    public FieldProperty(Column col) {
-      columnName = "inp" + Sqlc.TransformaNombreColumna(col.getDBColumnName());
-      dbColumnName = col.getDBColumnName();
-      propertyName = KernelUtils.getInstance().getPropertyFromColumn(col, false).getName();
-      session = col.isStoredInSession();
-      typeName = UIDefinitionController.getInstance().getUIDefinition(col.getId()).getName();
-    }
-
-    public FieldProperty(Field field) {
-      this(field.getColumn());
-    }
-
-    public String getColumnName() {
-      return columnName;
-    }
-
-    public String getPropertyName() {
-      return propertyName;
-    }
-
-    public String getSession() {
-      return session ? "true" : "false";
-    }
-
-    public String getDbColumnName() {
-      return dbColumnName;
-    }
-
-    public void setDbColumnName(String dbColumnName) {
-      this.dbColumnName = dbColumnName;
-    }
-
-    public String getTypeName() {
-      return typeName;
-    }
-
-    public void setTypeName(String typeName) {
-      this.typeName = typeName;
-    }
-  }
-
   public class ButtonField {
     private String id;
     private String label;
@@ -500,6 +446,10 @@
       return propertyName;
     }
 
+    public boolean getHasLabelValues() {
+      return !labelValues.isEmpty();
+    }
+
     public List<Value> getLabelValues() {
       return labelValues;
     }
@@ -638,4 +588,55 @@
     return tab.isShowParentsButtons();
   }
 
+  private class FormFieldComparator implements Comparator<Field> {
+
+    /**
+     * Fields with null sequence number are in the bottom of the form. In case multiple null
+     * sequences, it is sorted by field UUID.
+     */
+    @Override
+    public int compare(Field arg0, Field arg1) {
+      Long arg0Position = arg0.getSequenceNumber();
+      Long arg1Position = arg1.getSequenceNumber();
+
+      if (arg0Position == null && arg1Position == null) {
+        return arg0.getId().compareTo(arg1.getId());
+      } else if (arg0Position == null) {
+        return 1;
+      } else if (arg1Position == null) {
+        return -1;
+      }
+
+      return (int) (arg0Position - arg1Position);
+    }
+
+  }
+
+  public class OtherField {
+    private Property property;
+
+    private OtherField(Column col) {
+      this.property = KernelUtils.getInstance().getPropertyFromColumn(col, false);
+    }
+
+    public String getPropertyName() {
+      return property.getName();
+    }
+
+    public String getInpColumnName() {
+      return "inp" + Sqlc.TransformaNombreColumna(property.getColumnName());
+    }
+
+    public String getDbColumnName() {
+      return property.getColumnName();
+    }
+
+    public String getType() {
+      return UIDefinitionController.getInstance().getUIDefinition(property.getColumnId()).getName();
+    }
+
+    public boolean getSession() {
+      return property.isStoredInSession();
+    }
+  }
 }
--- a/modules/org.openbravo.client.application/src/org/openbravo/client/application/window/servlet/CalloutServletConfig.java	Thu Oct 13 18:24:25 2011 +0200
+++ b/modules/org.openbravo.client.application/src/org/openbravo/client/application/window/servlet/CalloutServletConfig.java	Thu Oct 20 13:09:18 2011 +0200
@@ -20,7 +20,7 @@
     return context.getInitParameter(name);
   }
 
-  @SuppressWarnings("unchecked")
+  @SuppressWarnings({ "rawtypes" })
   @Override
   public Enumeration getInitParameterNames() {
     return context.getInitParameterNames();
--- a/modules/org.openbravo.client.application/web/org.openbravo.client.application/js/alert-management/ob-alert-grid.js	Thu Oct 13 18:24:25 2011 +0200
+++ b/modules/org.openbravo.client.application/web/org.openbravo.client.application/js/alert-management/ob-alert-grid.js	Thu Oct 20 13:09:18 2011 +0200
@@ -206,8 +206,9 @@
   },
   
   cellClick: function (record, rowNum, colNum) {
-    var i, tabId, field = this.getField(colNum);
-    for (i = 0; i < OB.AlertManagement.alertRules.length; i++) {
+    var i, tabId, field = this.getField(colNum),
+      length = OB.AlertManagement.alertRules.length;
+    for (i = 0; i < length; i++) {
       if (OB.AlertManagement.alertRules[i].alertRuleId === record.alertRule) {
         tabId = OB.AlertManagement.alertRules[i].tabId;
       }
--- a/modules/org.openbravo.client.application/web/org.openbravo.client.application/js/alert-management/ob-alert-manager.js	Thu Oct 13 18:24:25 2011 +0200
+++ b/modules/org.openbravo.client.application/web/org.openbravo.client.application/js/alert-management/ob-alert-manager.js	Thu Oct 20 13:09:18 2011 +0200
@@ -70,12 +70,12 @@
     },
 
     _notify : function(rpcResponse, data, rpcRequest) {
-      var i;
+      var i, length = OB.AlertManager.listeners.length;
       // store info for new listeners
       OB.AlertManager.lastResponse = rpcResponse;
       OB.AlertManager.lastData = data;
       OB.AlertManager.lastRequest = rpcRequest;
-      for (i = 0; i < OB.AlertManager.listeners.length; i++) {
+      for (i = 0; i < length; i++) {
         OB.AlertManager.listeners[i](rpcResponse, data, rpcRequest);
       }
       isc.Timer.setTimeout(OB.AlertManager.call, OB.AlertManager.delay);
--- a/modules/org.openbravo.client.application/web/org.openbravo.client.application/js/classic/ob-classic-compatibility.js	Thu Oct 13 18:24:25 2011 +0200
+++ b/modules/org.openbravo.client.application/web/org.openbravo.client.application/js/classic/ob-classic-compatibility.js	Thu Oct 20 13:09:18 2011 +0200
@@ -153,12 +153,12 @@
       // parameters to communicate with the classic OB class
       //
       function getXHRParamsObj(/* String */action, /* Object */ formObject){
-        var paramsObj = {}, i;
+        var paramsObj = {}, i, length = formObject.elements.length;
 
         paramsObj.Command = action;
         paramsObj.IsAjaxCall = '1';
 
-        for (i = 0; i < formObject.elements.length; i++) {
+        for (i = 0; i < length; i++) {
           if (formObject.elements[i].type) {
           var param =  inputValueForms(formObject.elements[i].name, formObject.elements[i]);
 
@@ -233,9 +233,10 @@
       getMDIKS: function(){
         var key, auxKey, action, funcParam, keyMap,
             ClassicKeyJSON = [],
-            LKS = O.KeyboardManager.Shortcuts, i;
+            LKS = O.KeyboardManager.Shortcuts, i,
+            length = LKS.list.length;
 
-        for (i = 0; i < LKS.list.length; i++) {
+        for (i = 0; i < length; i++) {
           auxKey = '';
           if (LKS.list[i].isGlobal) {
             if (LKS.list[i].keyComb.ctrl === true) {
@@ -592,3 +593,11 @@
   // Initialize ClassicOBCompatibility object
   cobcomp = L.ClassicOBCompatibility = new ClassicOBCompatibility();
 }(OB, isc));
+
+isc.ClassFactory.defineClass('OBUIAPP_RegistrationView', isc.Layout).addProperties({
+  initWidget : function() {
+    OB.Layout.ClassicOBCompatibility.Popup.openRegistration();
+
+    this.Super('initWidget', arguments);
+  }
+});
--- a/modules/org.openbravo.client.application/web/org.openbravo.client.application/js/form/formitem/ob-formitem-date.js	Thu Oct 13 18:24:25 2011 +0200
+++ b/modules/org.openbravo.client.application/web/org.openbravo.client.application/js/form/formitem/ob-formitem-date.js	Thu Oct 20 13:09:18 2011 +0200
@@ -52,11 +52,15 @@
   dateParts : [],
 
   doInit: function() {
-    var i, dateFormatUpper, index = 0, currentTime;
+    var i, dateFormatUpper, index = 0, 
+      length, currentTime;
+    
     dateFormatUpper = this.dateFormat.toUpperCase();
+    length = dateFormatUpper.length;
     this.dateSeparator = this.dateFormat.toUpperCase().replace(/D/g, '')
         .replace(/M/g, '').replace(/Y/g, '').substr(0, 1);
-    for (i = 0; i < dateFormatUpper.length; i++) {
+    
+    for (i = 0; i < length; i++) {
       if (this.isSeparator(dateFormatUpper, i)) {
         index++;
       } else {
@@ -87,11 +91,13 @@
   },
   
   parseValue: function() {
-    var i, str = this.blurValue(), parts = [ '', '', '' ], partIndex = 0, result;
+    var i, str = this.blurValue(), 
+      length = str.length, 
+      parts = [ '', '', '' ], partIndex = 0, result;
     if (!str || isc.isA.Date(str)) {
       return str;
     }
-    for (i = 0; i < str.length; i++) {
+    for (i = 0; i < length; i++) {
       if (this.isNumber(str, i)) {
         if (this.reachedLength(parts[partIndex], partIndex)) {
           partIndex++;
--- a/modules/org.openbravo.client.application/web/org.openbravo.client.application/js/form/formitem/ob-formitem-fk-filter.js	Thu Oct 13 18:24:25 2011 +0200
+++ b/modules/org.openbravo.client.application/web/org.openbravo.client.application/js/form/formitem/ob-formitem-fk-filter.js	Thu Oct 20 13:09:18 2011 +0200
@@ -26,7 +26,7 @@
   allowExpressions: true,
   validateOnExit: false,
   validateOnChange: false,
-
+  
   // solve a small bug in the value expressions
   buildValueExpressions: function() {
     var ret = this.Super('buildValueExpressions', arguments);
@@ -35,4 +35,4 @@
     }
     return ret;
   }
-});
\ No newline at end of file
+});
--- a/modules/org.openbravo.client.application/web/org.openbravo.client.application/js/form/formitem/ob-formitem-linktitle.js	Thu Oct 13 18:24:25 2011 +0200
+++ b/modules/org.openbravo.client.application/web/org.openbravo.client.application/js/form/formitem/ob-formitem-linktitle.js	Thu Oct 20 13:09:18 2011 +0200
@@ -28,6 +28,6 @@
   
   linkButtonClick: function(){
     var sourceWindow = this.form.view.standardWindow.windowId;
-    OB.Utilities.openDirectView(sourceWindow, this.referencedKeyColumnName, this.targetEntity, this.getValue());
+    OB.Utilities.openDirectView(sourceWindow, this.refColumnName, this.targetEntity, this.getValue());
   }
 });
--- a/modules/org.openbravo.client.application/web/org.openbravo.client.application/js/form/formitem/ob-formitem-list-filter.js	Thu Oct 13 18:24:25 2011 +0200
+++ b/modules/org.openbravo.client.application/web/org.openbravo.client.application/js/form/formitem/ob-formitem-list-filter.js	Thu Oct 20 13:09:18 2011 +0200
@@ -22,10 +22,13 @@
 isc.ClassFactory.defineClass('OBListFilterItem', OBListItem);
 
 isc.OBListFilterItem.addProperties({
+  allowExpressions: false,
   moveFocusOnPickValue: false,
   operator: 'equals',
   validateOnExit: false,
   validateOnChange: false,
+  filterOnKeypress: false,
+  addUnknownValues: false,
   
   // note: can't override changed as it is used by the filter editor 
   // itself, see the RecordEditor source code and the changed event
--- a/modules/org.openbravo.client.application/web/org.openbravo.client.application/js/form/formitem/ob-formitem-list.js	Thu Oct 13 18:24:25 2011 +0200
+++ b/modules/org.openbravo.client.application/web/org.openbravo.client.application/js/form/formitem/ob-formitem-list.js	Thu Oct 20 13:09:18 2011 +0200
@@ -95,9 +95,10 @@
   },
 
   setEntries: function(entries) {
-    var valueField = this.getValueFieldName(), valueMap = {};
+    var length = entries.length,
+      valueField = this.getValueFieldName(), valueMap = {};
     this.entries = [];
-    for (i = 0; i < entries.length; i++) {
+    for (i = 0; i < length; i++) {
       id = entries[i][OB.Constants.ID] || '';
       identifier = entries[i][OB.Constants.IDENTIFIER] || '';
       valueMap[id] = identifier;
@@ -109,8 +110,8 @@
 
   setEntry: function(id, identifier) {
     var i, entries = this.entries || [], entry = {}, valueField = this
-        .getValueFieldName();
-    for (i = 0; i < entries.length; i++) {
+        .getValueFieldName(), length = entries.length;
+    for (i = 0; i < length; i++) {
       if (entries[i][valueField] === id) {
         return;
       }
--- a/modules/org.openbravo.client.application/web/org.openbravo.client.application/js/form/formitem/ob-formitem-minidaterange.js	Thu Oct 13 18:24:25 2011 +0200
+++ b/modules/org.openbravo.client.application/web/org.openbravo.client.application/js/form/formitem/ob-formitem-minidaterange.js	Thu Oct 20 13:09:18 2011 +0200
@@ -219,6 +219,10 @@
       return;
     }
     
+    if (newValue === oldValue) {
+      return false;
+    }
+    
     if (this.singleDateMode) {
       dateValue = OB.Utilities.Date.OBToJS(newValue, this.dateFormat);
       if (isc.isA.Date(dateValue)) {
@@ -315,14 +319,15 @@
   },
   
   updateStoredDates: function() {
-    var value = this.rangeItemValue, i;
+    var value = this.rangeItemValue, i, newValue, length;
     
     if (value) {
       if (isc.DataSource.isAdvancedCriteria(value)) {
         // value has come back as an AdvancedCriteria!
-        var newValue = {};
-
-        for (i = 0; i < value.criteria.length; i++) {
+        newValue = {};
+        length = value.criteria.length;
+          
+        for (i = 0; i < length; i++) {
           var criterion = value.criteria[i];
           if (criterion.operator === 'greaterThan'
               || criterion.operator === 'greaterOrEqual') {
@@ -441,13 +446,9 @@
     }
     return true;
   },
-  
-  formatDate: function(dt) {
-    return OB.Utilities.Date.JSToOB(dt, OB.Format.date);
-  },
-  
-  // TODO: the destroy and clear can be removed 
-  // after upgrading to a SC release after mid-august 2011
+   
+  // Explicit destroy of the rangedialog as formitems don't have 
+  // an auto delete of autochilds
   destroy: function() {
     this.destroying = true;
     if (this.rangeDialog) {
@@ -466,5 +467,9 @@
       return;
     }
     this.Super('clear', arguments);
+  },
+  
+  formatDate: function(dt) {
+    return OB.Utilities.Date.JSToOB(dt, OB.Format.date);
   }
 });
\ No newline at end of file
--- a/modules/org.openbravo.client.application/web/org.openbravo.client.application/js/form/formitem/ob-formitem-number.js	Thu Oct 13 18:24:25 2011 +0200
+++ b/modules/org.openbravo.client.application/web/org.openbravo.client.application/js/form/formitem/ob-formitem-number.js	Thu Oct 20 13:09:18 2011 +0200
@@ -38,18 +38,6 @@
   init: function(){
     this.setKeyPressFilter(this.keyPressFilterNumeric);
     this.typeInstance = SimpleType.getType(this.type);
-    var newValidators = [], i;
-    // get rid of the isFloat validators, as we have 
-    // specific validation based on the format definition
-    for (i = 0; i < this.validators.length; i++) {
-      if (this.validators[i].type !== 'isFloat') {
-        newValidators.push(this.validators[i]);
-      }
-      if (this.validators[i].type === 'custom') {
-        this.valueValidator = this.validators[i];
-      }
-    }
-    this.validators = newValidators;
     return this.Super('init', arguments);
   },
   
@@ -440,24 +428,10 @@
   
   blur: function(){
     if (this.doBlurLogic) {
-      var value = this.getElementValue().toString();
-      var expressionValue;
-      var obj = this;
-      if (this.allowMath && value.indexOf('=') === 0) {
-        expressionValue = this.evalMathExpression(value);
-        if (expressionValue !== 'error') {
-          expressionValue = parseFloat(expressionValue, 10);
-        } else {
-          setTimeout(function() {
-            obj.setElementValue(value);
-          }, 50);
-          return this.Super('blur', arguments);
-        }
-        this.setValue(expressionValue);
-        this.validate();
-      }
-  
+      this.validate();  
+
       value = this.getValue();
+      
       // first check if the number is valid
       if (!isc.isA.String(value)) {
         // format the value displayed
@@ -465,33 +439,54 @@
       }
     }
     return this.Super('blur', arguments);
-  },
+  }
+});
+
+// Use our custom validator for float and integers
+isc.OBNumberItem.validateCondition = function(item, validator, value){
+  var undef, ret, type;
   
-  validators: [{
-    type: 'custom',
-    condition: function(item, validator, value){
-      if (!item.typeInstance) {
-        // this happens when data is validated which is returned from the system
-        // and added to the grid
-        return true;
+  if (!item.typeInstance) {
+    // this happens when data is validated which is returned from the system
+    // and added to the grid
+    return true;
+  }
+  
+  if (value === null || value === undef) {
+    return true;
+  }
+  
+  if (item.allowMath && isc.isA.String(value) && value.indexOf('=') === 0) {
+    value = String('') + item.evalMathExpression(value);
+  }
+  
+  type = item.typeInstance;
+  validator.resultingValue = null;
+
+  // return a formatted value, if it was valid
+  if (isc.isA.String(value)) {
+    if (OB.Utilities.Number.IsValidValueString(type, value)) {
+      validator.resultingValue = OB.Utilities.Number.OBMaskedToJS(value, type.decSeparator, type.groupSeparator);
+      item.storeValue(validator.resultingValue);
+      if (item.form && item.form.setTextualValue) {
+        item.form.setTextualValue(item.name, value, item.typeInstance);
       }
-      var type = item.typeInstance;
-      this.resultingValue = null;
-      
-      
-      // return a formatted value, if it was valid
-      if (isc.isA.String(value)) {
-        if (OB.Utilities.Number.IsValidValueString(type, value)) {
-          this.resultingValue = OB.Utilities.Number.OBMaskedToJS(value, type.decSeparator, type.groupSeparator);
-          return true;
-        } else {
-          return false;
-        }
-      }
-      return OB.Utilities.Number.IsValidValueString(type, item.getElementValue());
+      return true;
+    } else {
+      // don't loose illegal values
+      validator.resultingValue = item.getElementValue();
+      return false;
     }
-  }]
-});
+  } else if (isc.isA.Number(value)) {
+    return true;
+  }
+  // don't loose illegal values
+  validator.resultingValue = item.getElementValue();
+  return false;
+};
+
+Validator.addValidator('isFloat', isc.OBNumberItem.validateCondition);
+Validator.addValidator('isInteger', isc.OBNumberItem.validateCondition);
 
 isc.ClassFactory.defineClass('OBNumberFilterItem', OBNumberItem);
 
@@ -499,14 +494,14 @@
   allowExpressions: true,
   validateOnExit: false,
   validateOnChange: false,
-  keyPressFilterNumeric: '[0-9.,-=<>!#]',
+  keyPressFilterNumeric: '[0-9.,-=<>!#orand ]',
   doBlurLogic: false,
   operator: 'equals',
   validOperators: ['equals', 'lessThan', 'greaterThan',
                    'lessThan', 'lessThanOrEqual', 'greaterThanOrEqual',
                    'between', 'betweenInclusive', 'isNull', 'isNotNull'
                    ],
-
+  
   // prevent handling of equal symbol in filteritem
   keyDownAction: function(item, form, keyName){
     var keyCode = isc.EventHandler.lastEvent.nativeKeyCode;
@@ -531,10 +526,11 @@
   },
   
   buildValueExpressions: function(criterion) {
-    var i = 0, criteria;
+    var i = 0, criteria, length;
     if (criterion && criterion.criteria) {
       criterion = isc.clone(criterion);
-      for (i = 0; i < criterion.criteria.length; i++) {
+      length = criterion.criteria.length;
+      for (i = 0; i < length; i++) {
         criteria = criterion.criteria[i];
         if (criteria.start) {
           criteria.start = this.convertToStringValue(criteria.start);
--- a/modules/org.openbravo.client.application/web/org.openbravo.client.application/js/form/formitem/ob-formitem-section-audit.js	Thu Oct 13 18:24:25 2011 +0200
+++ b/modules/org.openbravo.client.application/web/org.openbravo.client.application/js/form/formitem/ob-formitem-section-audit.js	Thu Oct 20 13:09:18 2011 +0200
@@ -22,5 +22,12 @@
 
 isc.OBAuditSectionItem.addProperties({
   // this field group does not participate in formbuilding
-  personalizable: false
+  personalizable: false,
+  
+  itemIds: [
+            'creationDate',
+            'createdBy',
+            'updated',
+            'updatedBy'
+            ]
 });
--- a/modules/org.openbravo.client.application/web/org.openbravo.client.application/js/form/formitem/ob-formitem-section.js	Thu Oct 13 18:24:25 2011 +0200
+++ b/modules/org.openbravo.client.application/web/org.openbravo.client.application/js/form/formitem/ob-formitem-section.js	Thu Oct 20 13:09:18 2011 +0200
@@ -23,17 +23,25 @@
 isc.ClassFactory.defineClass('OBSectionItem', SectionItem);
 
 isc.OBSectionItem.addProperties({
+  sectionExpanded: false,
+  
   // revisit when/if we allow disabling of section items
   // visual state of disabled or non-disabled stays the same now
   showDisabled: false,
 
+  // some defaults, note if this changes then also the 
+  // field generation logic needs to be checked
+  colSpan: 4, 
+  startRow: true, 
+  endRow: true,
+  
   canTabToHeader: true,
   
   alwaysTakeSpace: false,
 
   setSectionItemInContent: function(form) {
-    var i = 0;
-    for (i = 0; i < this.itemIds.length; i++) {
+    var i = 0, length = this.itemIds.length;
+    for (i = 0; i < length; i++) {
       if (form.getItem(this.itemIds[i])) {
         form.getItem(this.itemIds[i]).section = this;
       }
@@ -48,9 +56,9 @@
   // Update the property alwaysTakeSpace when collapsing/expanding a section
   // Note: The hidden fields are not updated, they always have alwaysTakeSpace to false
   updateAlwaysTakeSpace: function(flag) {
-    var i, f = this.form, item;
+    var i, f = this.form, item, length = this.itemIds.length;
 
-    for(i = 0; i < this.itemIds.length; i++) {
+    for(i = 0; i < length; i++) {
       item = f.getItem(this.itemIds[i]);
       if (item) {
         // note different cases can occur, these properties may be set, maybe
@@ -107,8 +115,8 @@
   },
 
   setNewFocusItemExpanding: function(){
-    var newFocusItem = null, i;
-    for (i = 0; i < this.itemIds.length; i++) {
+    var newFocusItem = null, i, length = this.itemIds.length;
+    for (i = 0; i < length; i++) {
       var itemName = this.itemIds[i], item = this.form.getItem(itemName);
       // isFocusable is a method added in ob-smartclient.js
       if (item.isFocusable()) {
@@ -126,13 +134,15 @@
   },
 
   showIf: function(item, value, form, values) {
-    var i, field;
+    var i, field, length;
 
     if(!this.itemIds) {
       return false;
     }
-
-    for (i = 0; i < this.itemIds.length; i++) {
+    
+    length = this.itemIds.length;
+    
+    for (i = 0; i < length; i++) {
       field = form.getItem(this.itemIds[i]);
 
       if(!field || (item.visible === false || item.displayed === false || item.hiddenInForm === true)) {
--- a/modules/org.openbravo.client.application/web/org.openbravo.client.application/js/form/formitem/ob-formitem-textarea.js	Thu Oct 13 18:24:25 2011 +0200
+++ b/modules/org.openbravo.client.application/web/org.openbravo.client.application/js/form/formitem/ob-formitem-textarea.js	Thu Oct 20 13:09:18 2011 +0200
@@ -27,6 +27,10 @@
   validateOnExit: true,
 
   selectOnFocus: false,
+  
+  isDisabled: function() {
+    this.Super('isDisabled', arguments);
+  },
 
   itemHoverHTML: function(item, form) {
     if (this.isDisabled()) {
@@ -47,5 +51,10 @@
 // hack until this gets answered:
 // http://forums.smartclient.com/showthread.php?p=61621#post61621
 // to solve this: https://issues.openbravo.com/view.php?id=16327
-isc.ListGrid.getPrototype().$309.OBPopUpTextAreaItem = true;
+if (isc.ListGrid.getPrototype()._popUpTextAreaEditorTypes) {
+  // handle case when loading source code
+  isc.ListGrid.getPrototype()._popUpTextAreaEditorTypes.OBPopUpTextAreaItem = true;
+} else if (isc.ListGrid.getPrototype().$309) {
+  isc.ListGrid.getPrototype().$309.OBPopUpTextAreaItem = true;  
+}
 
--- a/modules/org.openbravo.client.application/web/org.openbravo.client.application/js/form/formitem/ob-formitem-yesno.js	Thu Oct 13 18:24:25 2011 +0200
+++ b/modules/org.openbravo.client.application/web/org.openbravo.client.application/js/form/formitem/ob-formitem-yesno.js	Thu Oct 20 13:09:18 2011 +0200
@@ -18,11 +18,38 @@
  */
 
 // == OBYesNoItem ==
-// Extends SelectItem with preset yes and no values.
-isc.ClassFactory.defineClass('OBYesNoItem', SelectItem);
+// Extends ComboBoxItem with preset yes and no values.
+isc.ClassFactory.defineClass('OBYesNoItem', ComboBoxItem);
 
 isc.OBYesNoItem.addProperties({
   operator: 'equals',
+  addUnknownValues: false,
+  
+  // solves:
+  // https://issues.openbravo.com/view.php?id=18592
+  setValue: function(value) {
+    if (value === 'true') {
+      this.Super('setValue', [true]);
+    } else if (value === 'false') {
+      this.Super('setValue', [false]);
+    } else {
+      this.Super('setValue', arguments);
+    }
+  },
+  
+  // is needed because addUnknownValues is false
+  isUnknownValue: function(enteredValue) {
+    var i, vm = this.getValueMap();
+    if (vm !== null) {
+      for (i = 0; i < vm.length; i++) {
+        if (enteredValue === this.mapValueToDisplay(vm[i])) {
+          return false;
+        }
+      }
+    }
+    return this.Super('isUnknownValue', arguments);
+  },
+  
   mapValueToDisplay: function(value, a, b, c){
     return OB.Utilities.getYesNoDisplayValue(value);
   },
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/modules/org.openbravo.client.application/web/org.openbravo.client.application/js/form/ob-onchange-registry.js	Thu Oct 20 13:09:18 2011 +0200
@@ -0,0 +1,98 @@
+/*
+ *************************************************************************
+ * 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) 2011 Openbravo SLU
+ * All Rights Reserved.
+ * Contributor(s):  ______________________________________.
+ ************************************************************************
+ */
+
+// == OB.CalloutRegistry ==
+// A registry which can be used to register callouts for a certain
+// tab and field combination. Multiple callouts can be registered
+// for one field.
+OB.OnChangeRegistry = {
+    registry: [],
+    
+    register: function(tabId, field, callback, id) {
+      var tabEntry, fieldEntry, i, overwritten = false;
+      
+      if (!this.registry[tabId]) {
+        this.registry[tabId] = {};
+      }
+      
+      tabEntry = this.registry[tabId];
+      if (!tabEntry[field]) {
+        tabEntry[field] = [];
+      }
+      
+      if (id && !callback.id) {
+        callback.id = id;
+      }
+      
+      // just set a default sort if not defined
+      if (callback.sort !== 0 && !callback.sort) {
+        callback.sort = 100;
+      }
+      
+      // check if there is one with the same name
+      for (i = 0; i < tabEntry[field].length; i++) {
+        if (tabEntry[field][i] && tabEntry[field][i].id === callback.id) {
+          tabEntry[field][i] = callback;
+          overwritten = true;
+          break;
+        }
+      }
+      
+      // add
+      if (!overwritten) {
+        tabEntry[field].push(callback);        
+      }
+      
+      // and sort according to the sort property
+      tabEntry[field].sortByProperty('sort', true);
+    },
+    
+    hasOnChange: function(tabId, item) {
+      return this.getFieldEntry(tabId, item);
+    },
+    
+    getFieldEntry: function(tabId, item) {
+      var tabEntry, field = item.name;
+      if (!this.registry[tabId]) {
+        return;
+      }
+      tabEntry = this.registry[tabId];
+      return tabEntry[field];  
+    },
+    
+    call: function(tabId, item, view, form, grid) {
+      var callResult, fieldEntry = this.getFieldEntry(tabId, item), i; 
+
+      if (!fieldEntry) {
+        return;
+      }
+      for (i = 0; i < fieldEntry.length; i++) {
+        if (fieldEntry[i]) {
+          callResult = fieldEntry[i](item, view, form, grid);
+          if (callResult === false) {
+            return;
+          }
+        }
+      }
+    }
+};
+
+OB.OnChangeRegistry.TestFunction = function(item) {
+  alert('You changed ' + item.name);
+};
\ No newline at end of file
--- a/modules/org.openbravo.client.application/web/org.openbravo.client.application/js/form/ob-statusbar.js	Thu Oct 13 18:24:25 2011 +0200
+++ b/modules/org.openbravo.client.application/web/org.openbravo.client.application/js/form/ob-statusbar.js	Thu Oct 20 13:09:18 2011 +0200
@@ -75,7 +75,7 @@
   },
 
   doAction : function() {
-    var rowNum, newRowNum, newRecord, theButtonBar, i;
+    var rowNum, newRowNum, newRecord, theButtonBar, i, length;
     if (this.buttonType === 'previous') {
       this.view.editNextPreviousRecord(false);
     } else if (this.buttonType === 'maximize') {
@@ -96,7 +96,8 @@
     } else if (this.buttonType === 'maximizeRestore') {
       theButtonBar = this.view.statusBar.buttonBar;
       if (theButtonBar.members) {
-        for (i = 0; i < theButtonBar.members.length; i++) {
+        length = theButtonBar.members.length;
+        for (i = 0; i < length; i++) {
           if (theButtonBar.members[i].buttonType === 'maximize' && !theButtonBar.members[i].isDisabled() && theButtonBar.members[i].isVisible()) {
             theButtonBar.members[i].action();
             break;
@@ -189,6 +190,9 @@
   },
   
   addCreateButtons: function() {
+    var buttonSpacer = isc.HLayout.create( {
+        width : this.iconButtonGroupSpacerWidth
+      }), i, length;
 
     this.previousButton = isc.OBStatusBarIconButton.create( {
       view : this.view,
@@ -196,29 +200,34 @@
       keyboardShortcutId : 'StatusBar_Previous',
       prompt : OB.I18N.getLabel('OBUIAPP_PREVIOUSBUTTON')
     });
+    
     this.nextButton = isc.OBStatusBarIconButton.create( {
       view : this.view,
       buttonType : 'next',
       keyboardShortcutId : 'StatusBar_Next',
       prompt : OB.I18N.getLabel('OBUIAPP_NEXTBUTTON')
     });
+    
     this.closeButton = isc.OBStatusBarIconButton.create( {
       view : this.view,
       buttonType : 'close',
       keyboardShortcutId : 'StatusBar_Close',
       prompt : OB.I18N.getLabel('OBUIAPP_CLOSEBUTTON')
     });
+    
     this.maximizeButton = isc.OBStatusBarIconButton.create( {
       view : this.view,
       buttonType : 'maximize',
       prompt : OB.I18N.getLabel('OBUIAPP_MAXIMIZEBUTTON')
     });
+    
     this.restoreButton = isc.OBStatusBarIconButton.create( {
       visibility : 'hidden',
       view : this.view,
       buttonType : 'restore',
       prompt : OB.I18N.getLabel('OBUIAPP_RESTOREBUTTON')
     });
+    
     this.maximizeRestoreButton = isc.OBStatusBarIconButton.create( { // Only for implement 'StatusBar_Maximize-Restore' keyboard shortcut
       visibility : 'hidden',
       view : this.view,
@@ -227,13 +236,10 @@
       keyboardShortcutId : 'StatusBar_Maximize-Restore'
     });
 
-    var buttonSpacer = isc.HLayout.create( {
-      width : this.iconButtonGroupSpacerWidth
-    }), i;
-
     this.buttonBar.addMembers( [ this.previousButton, this.nextButton, buttonSpacer,
         this.maximizeButton, this.restoreButton, this.closeButton, this.maximizeRestoreButton ]);
-    for (i = 0; i < this.buttonBar.members.length; i++) {
+    length = this.buttonBar.members.length;
+    for (i = 0; i < length; i++) {
       if (this.buttonBar.members[i].buttonType) {
         OB.TestRegistry.register(
             'org.openbravo.client.application.statusbar.button.' + this.buttonBar.members[i].buttonType + '.' + this.view.tabId,
@@ -277,8 +283,10 @@
   },
 
   disableShortcuts: function(){
+    var length;
     if (this.buttonBar.members) {
-      for (i = 0; i < this.buttonBar.members.length; i++) {
+      length = this.buttonBar.members.length;
+      for (i = 0; i < length; i++) {
         if (this.buttonBar.members[i].disableShortcut) {
           this.buttonBar.members[i].disableShortcut();
         }
@@ -321,13 +329,14 @@
   },
 
   updateContentTitle: function(arrayTitleField, message) {
-    var msg = '', i;
+    var msg = '', i, length;
     if (!isc.Page.isRTL()) { // LTR mode
       if (this.statusCode) {
         msg += '<span class="' + (this.statusLabelStyle?this.statusLabelStyle:'') + '">' + OB.I18N.getLabel(this.statusCode) + '</span>';
       }
       if (arrayTitleField) {
-        for (i = 0; i < arrayTitleField[0].length; i++) {
+        length = arrayTitleField[0].length;
+        for (i = 0; i < length; i++) {
           if (i !== 0 || this.statusCode) {
             msg += '<span class="' + (this.separatorLabelStyle?this.separatorLabelStyle:'') + '">' + '&nbsp;&nbsp;|&nbsp;&nbsp;' + '</span>';
           }
--- a/modules/org.openbravo.client.application/web/org.openbravo.client.application/js/form/ob-view-form-attachments.js	Thu Oct 13 18:24:25 2011 +0200
+++ b/modules/org.openbravo.client.application/web/org.openbravo.client.application/js/form/ob-view-form-attachments.js	Thu Oct 20 13:09:18 2011 +0200
@@ -46,6 +46,8 @@
   
   visible: false,
   
+  itemIds: ['_attachments_Canvas'],
+  
   // note formitems don't have an initWidget but an init method
   init: function(){
     // override the one passed in
@@ -97,6 +99,12 @@
 
 isc.OBAttachmentCanvasItem.addProperties({
 
+  // some defaults, note if this changes then also the 
+  // field generation logic needs to be checked
+  colSpan: 4, 
+  startRow: true, 
+  endRow: true,
+
   canFocus: true,
   
   // setting width/height makes the canvasitem to be hidden after a few
@@ -206,12 +214,15 @@
   },
   
   fileExists: function(fileName, attachments){
-	var i;
+    var i, length;
+   
     if(!attachments || attachments.length === 0){
       return false;
     }
-    for(i=0; i < attachments.length; i++){
-      if(attachments[i].name === fileName){
+    
+    length = attachments.length;
+    for( i = 0; i < length; i++){
+      if (attachments[i].name === fileName) {
         return true;
       }
     }
@@ -219,6 +230,7 @@
   },
   
   fillAttachments: function(attachments){
+	var id;
     this.savedAttachments = attachments;
     this.destroyAndRemoveMembers(this.getMembers());
     var hLayout = isc.HLayout.create();
@@ -314,7 +326,12 @@
     }
     this.getForm().view.attachmentExists = true;
     this.getForm().view.toolBar.updateButtonState();
-    isc_OBAttachmentsSectionItem_0.setValue(OB.I18N.getLabel('OBUIAPP_AttachmentTitle')+" ("+attachments.length+")");
+    var fields = this.getForm().getFields();
+    for(id = 0;id<fields.length;id++){
+      if(fields[id].type==='OBAttachmentsSectionItem'){
+        fields[id].setValue(OB.I18N.getLabel('OBUIAPP_AttachmentTitle')+" ("+attachments.length+")");
+      }
+    }
     var downloadAllButton = isc.OBLinkButtonItem.create({
       title: '[ '+OB.I18N.getLabel('OBUIAPP_AttachmentDownloadAll')+' ]',
       width: '30px',
@@ -366,64 +383,64 @@
     };
     
     var removeActions = function(){
-      var i;
-      var d = {
-        Command: 'DELETE',
-        tabId: this.canvas.tabId,
-        buttonId: this.canvas.ID,
-        recordIds: this.canvas.recordId,
-        attachId: this.attachmentId
+      var i, length, d = {
+          Command: 'DELETE',
+          tabId: this.canvas.tabId,
+          buttonId: this.canvas.ID,
+          recordIds: this.canvas.recordId,
+          attachId: this.attachmentId
+        }, canvas = this.canvas;
+
+      isc.confirm(OB.I18N.getLabel('OBUIAPP_ConfirmRemove'), function(clickedOK){
+          if(clickedOK){
+            OB.RemoteCallManager.call('org.openbravo.client.application.window.AttachmentsAH', {}, d, function(response, data, request){
+              canvas.fillAttachments(data.attachments);
+            });
+          }
+        },{title: OB.I18N.getLabel('OBUIAPP_ConfirmRemoveTitle')});
       };
-      var canvas = this.canvas;
-      isc.confirm(OB.I18N.getLabel('OBUIAPP_ConfirmRemove'), function(clickedOK){
-        if(clickedOK){
-          OB.RemoteCallManager.call('org.openbravo.client.application.window.AttachmentsAH', {}, d, function(response, data, request){
-              canvas.fillAttachments(data.attachments);
-          });
-        }
-      },{title: OB.I18N.getLabel('OBUIAPP_ConfirmRemoveTitle')});
-    };
     
-    for(i=0; i < attachments.length; i++){
-      var attachment = attachments[i];
-      var buttonLayout = isc.HLayout.create();
-      var attachmentLabel = isc.Label.create({
-        contents: attachment.name,
-        className: 'OBNoteListGrid',
-        width: '200px',
-        height: 20,
-        wrap: false
-      });
-      var creationDate = OB.Utilities.getTimePassedInterval(attachment.age);
-      var attachmentBy = isc.Label.create({
-        height:  1,
-        className: 'OBNoteListGridAuthor',
-        width: '200px',
-        contents: creationDate+" "+OB.I18N.getLabel('OBUIAPP_AttachmentBy')+" "+attachment.updatedby
-      });
-      var downloadAttachment = isc.OBLinkButtonItem.create({
-        title: '[ '+OB.I18N.getLabel('OBUIAPP_AttachmentDownload')+' ]',
-        width: '30px',
-        attachmentName: attachment.name,
-        attachId: attachment.id,
-        action: downloadActions
-      });
-      downloadAttachment.height=0;
-      var removeAttachment = isc.OBLinkButtonItem.create({
-        title: '[ '+OB.I18N.getLabel('OBUIAPP_AttachmentRemove')+' ]',
-        width: '30px',
-        attachmentName: attachment.name,
-        attachmentId: attachment.id,
-        canvas: this,
-        action: removeActions
-      });
-      buttonLayout.addMember(attachmentLabel);
-      buttonLayout.addMember(attachmentBy);
-      buttonLayout.addMember(downloadAttachment);
-      buttonLayout.addMember(removeAttachment);
-      this.addMember(buttonLayout);
-    }
-  },
+      length = attachments.length;
+      for(i=0; i < attachments.length; i++){
+        var attachment = attachments[i];
+        var buttonLayout = isc.HLayout.create();
+        var attachmentLabel = isc.Label.create({
+          contents: attachment.name,
+          className: 'OBNoteListGrid',
+          width: '200px',
+          height: 20,
+          wrap: false
+        });
+        var creationDate = OB.Utilities.getTimePassedInterval(attachment.age);
+        var attachmentBy = isc.Label.create({
+          height:  1,
+          className: 'OBNoteListGridAuthor',
+          width: '200px',
+          contents: creationDate+" "+OB.I18N.getLabel('OBUIAPP_AttachmentBy')+" "+attachment.updatedby
+        });
+        var downloadAttachment = isc.OBLinkButtonItem.create({
+          title: '[ '+OB.I18N.getLabel('OBUIAPP_AttachmentDownload')+' ]',
+          width: '30px',
+          attachmentName: attachment.name,
+          attachId: attachment.id,
+          action: downloadActions
+        });
+        downloadAttachment.height=0;
+        var removeAttachment = isc.OBLinkButtonItem.create({
+          title: '[ '+OB.I18N.getLabel('OBUIAPP_AttachmentRemove')+' ]',
+          width: '30px',
+          attachmentName: attachment.name,
+          attachmentId: attachment.id,
+          canvas: this,
+          action: removeActions
+        });
+        buttonLayout.addMember(attachmentLabel);
+        buttonLayout.addMember(attachmentBy);
+        buttonLayout.addMember(downloadAttachment);
+        buttonLayout.addMember(removeAttachment);
+        this.addMember(buttonLayout);
+      }
+    },
   
   // ensure that the view gets activated
   focusChanged: function(){
--- a/modules/org.openbravo.client.application/web/org.openbravo.client.application/js/form/ob-view-form-linked-items.js	Thu Oct 13 18:24:25 2011 +0200
+++ b/modules/org.openbravo.client.application/web/org.openbravo.client.application/js/form/ob-view-form-linked-items.js	Thu Oct 20 13:09:18 2011 +0200
@@ -48,6 +48,8 @@
   
   visible: false,
   
+  itemIds: ['_linkedItems_Canvas'],
+  
   // note formitems don't have an initWidget but an init method
   init: function(){
     // override the one passed in
@@ -391,6 +393,12 @@
 
 isc.OBLinkedItemCanvasItem.addProperties({
 
+  // some defaults, note if this changes then also the 
+  // field generation logic needs to be checked
+  colSpan: 4, 
+  startRow: true, 
+  endRow: true,
+
   canFocus: true,
   
   // setting width/height makes the canvasitem to be hidden after a few
--- a/modules/org.openbravo.client.application/web/org.openbravo.client.application/js/form/ob-view-form-notes.js	Thu Oct 13 18:24:25 2011 +0200
+++ b/modules/org.openbravo.client.application/web/org.openbravo.client.application/js/form/ob-view-form-notes.js	Thu Oct 20 13:09:18 2011 +0200
@@ -31,6 +31,12 @@
 
   overflow : 'hidden',
 
+  // some defaults, note if this changes then also the 
+  // field generation logic needs to be checked
+  colSpan: 4, 
+  startRow: true, 
+  endRow: true,
+
   canFocus : true,
 
   prompt : OB.I18N.getLabel('OBUIAPP_NotesPrompt'),
@@ -43,7 +49,9 @@
  
   // this field group does not participate in personalization
   personalizable: false,
-
+  
+  itemIds: ['_notes_Canvas'],
+            
   // note formitems don't have an initWidget but an init method
   init : function() {
     // override the one passed in
@@ -354,6 +362,12 @@
 
 isc.OBNoteCanvasItem.addProperties({
 
+  // some defaults, note if this changes then also the 
+  // field generation logic needs to be checked
+  colSpan: 4, 
+  startRow: true, 
+  endRow: true,
+
   canFocus : true,
 
   // setting width/height makes the canvasitem to be hidden after a few
--- a/modules/org.openbravo.client.application/web/org.openbravo.client.application/js/form/ob-view-form.js	Thu Oct 13 18:24:25 2011 +0200
+++ b/modules/org.openbravo.client.application/web/org.openbravo.client.application/js/form/ob-view-form.js	Thu Oct 20 13:09:18 2011 +0200
@@ -81,40 +81,32 @@
   // is set in the OBAttachmentsSectionItem.initWidget
   attachmentsSection: null,
 
+  selectOnFocus: true,
+  
   initWidget: function() {
     this._preventFocusChanges = true;
-    var length, i, item;
+
     // add the obFormProperties to ourselves, the obFormProperties
     // are re-used for inline grid editing
     isc.addProperties(this, this.obFormProperties);
-
-    // is used to keep track of the original simple objects
-    // used to create fields
-    // note fields can be in fields or theFields
-    this._originalFields = isc.shallowClone(this.fields || this.theFields);
     
     this.Super('initWidget', arguments);
 
-    length = this.getItems().length;
-
-    for(i = 0; i < length; i++) {
-      item = this.getItem(i);
-      if(item && item.firstFocusedField) {
-        this.firstFocusedField = item.name;
-        break;
-      }
-    }
-
     delete this._preventFocusChanges;
   },
-
+  
   getStatusBarFields: function() {
-    var statusBarFields = [[],[]], i, item, value, tmpValue;
-    for(i = 0; i < this.statusBarFields.length; i++) {
+    var statusBarFields = [[],[]], i, item, value, tmpValue,
+      length = this.statusBarFields.length;
+    for(i = 0; i < length; i++) {
       item = this.getItem(this.statusBarFields[i]);
-      value = item.getDisplayValue();
-      if(item && value !== null && value !== '') {
-
+      value = item.getValue();
+      if(value !== null && value !== '') {
+        
+        if (item.getDisplayValue()) {
+          value = item.getDisplayValue();
+        }
+        
         if(value === item.getTitle() && typeof item.getValue() === 'boolean') { // Checkbox items return the title as display value
           if (item.getValue()) {
             value = OB.I18N.getLabel('OBUIAPP_Yes');
@@ -126,8 +118,8 @@
         // if there is a display field or an identifier field accompanying the
         // status bar field and it has a value then always use that
         // one
-        if (item.displayField && getValue(item.displayField)) {
-          value = getValue(item.displayField);
+        if (item.displayField && this.getValue(item.displayField)) {
+          value = this.getValue(item.displayField);
         } else if (this.getValue(item.name + '._identifier')) {
           value = this.getValue(item.name + '._identifier');
         }
@@ -178,21 +170,12 @@
   },
   
   doEditRecordActions: function(preventFocus, isNew){
+    delete this.contextInfo;
+
     this.initializing = true;
     
     delete this.validateAfterFicReturn;
     
-    // only compute a new focus item if the form is active
-    if (this.view.isActiveView()) {
-      this.computeFocusItem();
-    }
-    
-    // if the focus item is not really enabled
-    // then find a new one, even if the form is not active
-    if (this.getFocusItem() && !this.getFocusItem().isFocusable(true)) {
-      this.computeFocusItem(this.getFocusItem());
-    }
-
     // sometimes if an error occured we stay disabled
     // prevent this
     this.setDisabled(false);
@@ -200,17 +183,20 @@
     this.setHasChanged(false);
 
     this.setNewState(isNew);
-    
+
+    // errors are cleared anyway
+    delete this.validateAfterFicReturn;
+
     // focus is done automatically, prevent the focus event if needed
     // the focus event will set the active view
-    this.clearErrors();
     if (!isNew) {
-      this.validateAfterFicReturn = true;
       // If editing a document set to recent documents
       this.view.setRecentDocument(this.getValues());
     }
     
     this.ignoreFirstFocusEvent = preventFocus;
+    
+    // retrieveinitialvalues does focus and clear of errors
     this.retrieveInitialValues(isNew);
     
     if (isNew) {
@@ -308,7 +294,6 @@
   setNewState: function(isNew){
     // showing the sections will change the focus item
     // restore that
-    this.storeFocusItem();
     this.isNew = isNew;
     this.view.statusBar.setNewState(isNew);
     this.view.updateTabTitle();
@@ -317,9 +302,6 @@
     this.enableLinkedItemSection(!isNew);
     this.enableAttachmentsSection(!isNew);
     
-    // and restore
-    this.restoreFocusItem();
-    
     if (isNew) {
       this.view.statusBar.newIcon.prompt = OB.I18N.getLabel('OBUIAPP_NewIconPrompt');
     } else {
@@ -420,21 +402,40 @@
     if (focusItem && focusItem.isFocusable()) {
       focusItem.focusInItem();
       this.view.lastFocusedItem = focusItem;
+      this.selectFocusItemValue(true);
     } else {      
       // find a new one
       this.computeFocusItem(focusItem);
       if (this.getFocusItem() !== focusItem && this.getFocusItem()) {
         focusItem.focusInItem();
+        this.selectFocusItemValue(true);
         this.view.lastFocusedItem = focusItem;
       }
     }
   },
   
+  selectFocusItemValue: function(delayCall) {
+    if (!this.getFocusItem() || !this.view.isActiveView()) {
+      return;
+    }
+    // if not explicitly set to false, select its value
+    // or if do initial select on focus
+    if (this.getFocusItem().selectOnFocus !== false || this.getFocusItem().doInitialSelectOnFocus) {
+      if (delayCall || isc.Browser.isIE) {
+        this.getFocusItem().delayCall('selectValue', [], 100);
+      } else {
+        this.getFocusItem().selectValue();
+      }
+    }    
+  },
+  
   getFieldFromInpColumnName: function(inpColumnName) {
-    var i;
+    var i, length;
+    
     if (!this.fieldsByInpColumnName) {
       var localResult = [], fields = this.getFields();
-      for (i = 0; i < fields.length; i++) {
+      length = fields.length;
+      for (i = 0; i < length; i++) {
         if (fields[i].inpColumnName) {
           localResult[fields[i].inpColumnName.toLowerCase()] = fields[i];
         }
@@ -445,9 +446,12 @@
   },
   
   getFieldFromColumnName: function(columnName) {
-    var i;
+    var i, length;
     if (!this.fieldsByColumnName) {
       var localResult = [], fields = this.getFields();
+      
+      length = fields.length;
+
       for (i = 0; i < fields.length; i++) {
         if (fields[i].columnName) {
           localResult[fields[i].columnName.toLowerCase()] = fields[i];
@@ -459,7 +463,7 @@
   },
   
   setFields: function(){
-    var i, item;
+    var i, item, length;
     
     // is used in various places, prevent focus and scroll events
     this._preventFocusChanges = true;
@@ -468,7 +472,8 @@
     this.fieldsByInpColumnName = null;
     this.fieldsByColumnName = null;
 
-    for (i = 0; i < this.getItems().length; i++) {
+    length = this.getItems().length;
+    for (i = 0; i < length; i++) {
       item = this.getItem(i);
       if(item && item.setSectionItemInContent) {
         item.setSectionItemInContent(this);
@@ -478,12 +483,15 @@
   },
   
   retrieveInitialValues: function(isNew){
+    var parentId = this.view.getParentId(), i, fldNames = [], 
+      requestParams, allProperties, parentColumn, me = this, 
+      mode, length = this.getFields().length;
+    
     this.setParentDisplayInfo();
     
-    var parentId = this.view.getParentId(), i, fldNames = [], requestParams, parentColumn, me = this, mode;
-    // note also in this case initial vvalues are passed in as in case of grid
+    // note also in this case initial values are passed in as in case of grid
     // editing the unsaved/error values from a previous edit session are maintained
-    var allProperties = this.view.getContextInfo(false, true, false, true);
+    allProperties = this.view.getContextInfo(false, true, false, true);
     
     if (isNew) {
       mode = 'NEW';
@@ -497,14 +505,16 @@
       TAB_ID: this.view.tabId,
       ROW_ID: this.getValue(OB.Constants.ID)
     };
+    
     if (parentId && isNew && this.view.parentProperty) {
       parentColumn = this.view.getPropertyDefinition(this.view.parentProperty).inpColumn;
       requestParams[parentColumn] = parentId;
     }
+    
     allProperties._entityName = this.view.entity;
     
     // only put the visible field names in the call
-    for (i = 0; i < this.getFields().length; i++) {
+    for (i = 0; i < length; i++) {
       if (this.getFields()[i].inpColumnName) {
         fldNames.push(this.getFields()[i].inpColumnName);
       }
@@ -541,22 +551,37 @@
         me.rememberValues();
       }
       me.initializing = false;
+
+      // do here because during initial form drawing
+      // fields get blurred and will show an error
+      me.clearErrors(true);
       
+      // only compute a new focus item if the form is active
+      if (me.view.isActiveView()) {
+        me.computeFocusItem();
+      }
+      
+      // if the focus item is not really enabled
+      // then find a new one, even if the form is not active
+      if (me.getFocusItem() && !me.getFocusItem().isFocusable(true)) {
+        me.computeFocusItem(me.getFocusItem());
+      }
+      // note the focus is set in the field when the FIC call
+      // returns
+
       // at this point select the focused value      
       if (me.getFocusItem()) {
         me.setFocusInForm();
-        me.selectFocusItemValue();
       }
-
     });
   },
   
   rememberValues: function() {
-    var i, flds = this.getFields();
+    var i, flds = this.getFields(), length = flds.length;
     this.Super('rememberValues', arguments);
     
     // also remember the valuemaps
-    for (i = 0; i < flds.length; i++) {
+    for (i = 0; i < length; i++) {
       if (flds[i].valueMap) {
         flds[i]._rememberedValueMap = flds[i].valueMap;
       }
@@ -566,14 +591,17 @@
   // used in grid editing, when an edit is discarded then the canFocus needs to be
   // reset
   resetCanFocus: function() {
-    var i;
-    for (i = 0; i < this.getItems().length; i++) {
+    var i, length = this.getItems().length;
+    for (i = 0; i < length; i++) {
       delete this.getItems()[i].canFocus;
     }
   },
   
   processFICReturn: function(response, data, request, editValues, editRow){
-    var modeIsNew = request.params.MODE === 'NEW', noErrors, errorSolved;
+    var length, modeIsNew = request.params.MODE === 'NEW', 
+      noErrors, errorSolved;
+
+    delete this.contextInfo;
 
     // needs to be recomputed as for grid editing the fields
     // are reset for every edit session
@@ -645,9 +673,9 @@
     }
 
     // apparently sometimes an empty string is returned
-    if (calloutMessages && calloutMessages.length > 0 && calloutMessages[0].text !== '') {
+    if (calloutMessages && calloutMessages.length > 0 && calloutMessages[calloutMessages.length-1].text !== '') {
       // TODO: check as what type should call out messages be displayed
-      this.view.messageBar.setMessage(isc.OBMessageBar[calloutMessages[0].severity], null, calloutMessages[0].text);
+      this.view.messageBar.setMessage(isc.OBMessageBar[calloutMessages[calloutMessages.length-1].severity], null, calloutMessages[calloutMessages.length-1].text);
     }
     if (auxInputs) {
       for (prop in auxInputs) {
@@ -687,12 +715,15 @@
     // on field changed may have made the focused item non-editable
     // this is handled in setdisabled restore focus item's call
     this.setDisabled(false);
+    
+    length = this.getFields().length;
 
     if (this.validateAfterFicReturn) {
       delete this.validateAfterFicReturn;
       // only validate the fields which have errors or which have changed
       noErrors = true;
-      for (i = 0; i < this.getFields().length; i++) {
+      
+      for (i = 0; i < length; i++) {
         if (this.getFields()[i]._changedByFic || this.hasFieldErrors(this.getFields()[i].name)) {
           errorSolved = this.getFields()[i].validate();
           noErrors = noErrors && errorSolved;
@@ -707,12 +738,12 @@
       }
     }
 
-    for (i = 0; i < this.getFields().length; i++) {
+    for (i = 0; i < length; i++) {
       delete this.getFields()[i]._changedByFic;
     }
 
     // refresh WidgetInForm fields if present (as they might depend on data of current record) 
-    for (i = 0; i < this.getFields().length; i++) {
+    for (i = 0; i < length; i++) {
       var locField  = this.getFields()[i];
       if (locField.hasOwnProperty("widgetClassId")) {
         locField.refresh();
@@ -742,20 +773,21 @@
     }
 
     if(data.jscode) {
-      for(i = 0; i < data.jscode.length; i++) {
+      length = data.jscode.length;
+      for(i = 0; i < length; i++) {
         eval(data.jscode[i]);
       }
     }
   },
   
   setDisabled: function(state) {
-    var previousAllItemsDisabled = this.allItemsDisabled || false, i;
+    var previousAllItemsDisabled = this.allItemsDisabled || false, 
+      i, length;
     this.allItemsDisabled = state;
 
     if (previousAllItemsDisabled !== this.allItemsDisabled) {
       if (this.getFocusItem()) {
         if (this.allItemsDisabled) {
-          this.storeFocusItem();
           if (this.getFocusItem() && !this.initializing) {
             this.getFocusItem().blurItem();
           }
@@ -765,20 +797,13 @@
           this.setHandleDisabled(state);
           this.view.viewGrid.refreshEditRow();
           // reset the canfocus
-          for (i = 0; i < this.getFields().length; i++) {
+          length = this.getFields().length;
+          for (i = 0; i < length; i++) {
             delete this.getFields()[i].canFocus;
           }
-          
-          // do restore focus in a delayed manner for ie
-          if (isc.Browser.isIE) {
-            this.delayCall('restoreFocusItem', [true], 100);
-          } else {
-            this.restoreFocusItem();
-          }
           delete this.ignoreFirstFocusEvent;
         }
       } else {
-        this.redraw();
         this.view.viewGrid.refreshEditRow();
       }
     }
@@ -798,15 +823,19 @@
     var assignClassicValue;
     var isDate, i, valueMap = {}, oldValue, field = this.getFieldFromColumnName(columnName), entries = columnValue.entries;
     // not a field on the form, probably a datasource field
-    var prop = this.view.getPropertyFromDBColumnName(columnName);
+    var propDef = this.view.getPropertyDefinitionFromDbColumnName(columnName);
+    var prop = propDef ? propDef.property : null;
     var id, identifier;
     if (!field) {
-      if (!prop) {
+      if (!propDef) {
         return;
       }
       field = this.getDataSource().getField(prop);
       if (!field) {
-        return;
+        field = {
+            name: propDef.property,
+            type: propDef.type
+        };
       }
     }
     
@@ -847,9 +876,9 @@
       (isc.SimpleType.getType(field.type).inheritsFrom === 'date' ||
       isc.SimpleType.getType(field.type).inheritsFrom === 'datetime');
       if (isDate) {
-        this.setValue(field.name, isc.Date.parseSchemaDate(columnValue.value));
+        this.setItemValue(field.name, isc.Date.parseSchemaDate(columnValue.value));
       } else if(columnValue.hasDateDefault){
-        this.setValue(field.name, columnValue.classicValue);
+        this.setItemValue(field.name, columnValue.classicValue);
       } else {
         
         // set the identifier/display field if the identifier is passed also
@@ -873,21 +902,21 @@
             // datasource and the field displayfield contains a dot, otherwise 
             // it is a direct field
             if (field.displayField && field.displayField.contains('.') && !this.getField(field.displayField) && !field.optionDataSource && !field.getDataSource()) {
-              field.form.setValue(field.displayField, identifier);
+              field.form.setItemValue(field.displayField, identifier);
             } else if (!field.displayField) {
-              field.form.setValue(field.name + '.' + OB.Constants.IDENTIFIER, identifier);
+              field.form.setItemValue(field.name + '.' + OB.Constants.IDENTIFIER, identifier);
             }
           }
         }
         
-        this.setValue(field.name, assignValue);
+        this.setItemValue(field.name, assignValue);
       }
     } else {
       // note: do not use clearvalue as this removes the value from the form
       // which results it to not be sent to the server anymore
       this.setValue(field.name, null);
       if (this.getValue(field.name + '.' + OB.Constants.IDENTIFIER)) {
-        this.setValue(field.name + '.' + OB.Constants.IDENTIFIER, null);
+        this.setItemValue(field.name + '.' + OB.Constants.IDENTIFIER, null);
       }
     }
     
@@ -904,13 +933,13 @@
   
   setColumnValuesInEditValues: function(columnName, columnValue, editValues){
     // Modifications in this method should go also in processColumnValue because both almost do the same
-    var assignClassicValue;
-    var typeInstance;
+    var assignClassicValue, typeInstance, length;
 
     // no editvalues even anymore, go away
     if (!editValues) {
       return;
     }
+    
     var id, identifier, field = this.getFieldFromColumnName(columnName), i, valueMap = {}, 
       entries = columnValue.entries;
     var prop = this.view.getPropertyFromDBColumnName(columnName);
@@ -921,7 +950,8 @@
     }
     
     if (entries) {
-      for (i = 0; i < entries.length; i++) {
+      length = entries.length;
+      for (i = 0; i < length; i++) {
         id = entries[i][OB.Constants.ID] || '';
         identifier = entries[i][OB.Constants.IDENTIFIER] || '';
         valueMap[id] = identifier;
@@ -960,8 +990,6 @@
       editValues[prop] = null;
     }
     
-
-
     // store the textualvalue so that it is correctly send back to the server
     if (field) {
       // Adjust to formatting if exists value and classicValue.
@@ -991,30 +1019,80 @@
     this.setValue(fldName + '_textualValue', textValue);
   },
   
+  // calls setValue and the onchange handling
+  setItemValue: function(item, value) {
+    var currentValue;
+
+    if (isc.isA.String(item)) {
+       
+      // not an item, set and bail
+      if (!this.getField(item)) {
+        this.setValue(item, value);
+        return;
+      }
+      item = this.getField(item);
+    }
+    currentValue = item.getValue();
+    
+    // no change go away
+    if (item.compareValues(value, currentValue)) {
+      return;
+    }
+    this.setValue(item, value);
+
+    // fire any new callouts
+    if (this.view) {
+      view = this.view;
+    } else if (this.grid && this.grid.view){
+      view = this.grid.view;
+    }
+
+    if (view && OB.OnChangeRegistry.hasOnChange(view.tabId, item)) {
+      OB.OnChangeRegistry.call(view.tabId, item, view, view.viewForm, view.viewGrid);
+    }
+  },
+  
   // called explicitly onblur and when non-editable fields change
   handleItemChange: function(item){
+    var i, length, tabId, view;
+    
     // is used to prevent infinite loops during save
     delete this.saveFocusItemChanged;
 
+    delete this.contextInfo;
+    
     if (item._hasChanged) {
       this.itemChangeActions();
 
       this.onFieldChanged(item.form, item, item.getValue());
+      
+      if (this.view) {
+        view = this.view;
+      } else if (this.grid && this.grid.view){
+        view = this.grid.view;
+      }
 
-      var i;
-      for (i = 0; i < this.dynamicCols.length; i++) {
-        if (this.dynamicCols[i] === item.inpColumnName) {
-          item._hasChanged = false;
-          this.inFicCall = true;
-          this.doChangeFICCall(item);
-          return true;
+      if (view && OB.OnChangeRegistry.hasOnChange(view.tabId, item)) {
+        OB.OnChangeRegistry.call(view.tabId, item, view, view.viewForm, view.viewGrid);
+      } else {
+        // call the classic callout if there
+        length = this.dynamicCols.length;
+        for (i = 0; i < length; i++) {
+          if (this.dynamicCols[i] === item.inpColumnName) {
+            item._hasChanged = false;
+            this.inFicCall = true;
+            this.doChangeFICCall(item);
+            return true;
+          }
         }
       }
+
       if (this.getFocusItem() && !this.getFocusItem().isFocusable(true)) {
         this.computeFocusItem(this.getFocusItem());
         this.setFocusInForm();
       }
     }
+    
     item._hasChanged = false;
   },
   
@@ -1060,6 +1138,14 @@
       }
 
       me.processFICReturn(response, data, request, editValues, editRow);
+
+      // don't set the focus in this case, this happens
+      // when moving to a new row in grid editing
+      if (!me.forceFocusedField) {
+        if (me.getFocusItem()) {
+          me.setFocusInForm();
+        }
+      }
     });
     this.view.toolBar.updateButtonState(true);
   },
@@ -1094,15 +1180,15 @@
   
   resetForm: function(){
     this.resetValues();
-    this.clearErrors();
+    this.clearErrors(true);
     this.setHasChanged(false);
   },
   
   undo: function(){
-    var i, flds = this.getFields();
+    var i, flds = this.getFields(), length = flds.length;
     
     // also restore the valuemaps
-    for (i = 0; i < flds.length; i++) {
+    for (i = 0; i < length; i++) {
       if (flds[i]._rememberedValueMap) {
         flds[i].valueMap = flds[i]._rememberedValueMap;
       }
@@ -1140,12 +1226,9 @@
   saveRow: function(){
     var savingNewRecord = this.isNew;
     
-    this.storeFocusItem();
-    
     // store the value of the current focus item
     if (this.getFocusItem() && this.saveFocusItemChanged !== this.getFocusItem()) {
-      this.getFocusItem().updateValue();
-      this.handleItemChange(this.getFocusItem());
+      this.getFocusItem().blur(this, this.getFocusItem());
       // prevent infinite loops
       this.saveFocusItemChanged = this.getFocusItem();
     } else {
@@ -1230,6 +1313,11 @@
         // success invoke the action, if any there
         view.standardWindow.autoSaveDone(view, true);
 
+        // stop here if the window was getting closed anyway
+        if (view.standardWindow.closing) {
+          return;
+        }
+        
         // do this after doing autoSave as the setHasChanged will clean
         // the autosave info
         form.setHasChanged(false);
@@ -1258,7 +1346,6 @@
 
       form.isSaving = false;
       view.toolBar.updateButtonState(true);
-      this.restoreFocusItem();
       return false;
     };