Fixes issue 21596, 21613: Changed behaviour of processing of
authorDavid Miguelez <david.miguelez@openbravo.com>
Tue, 11 Sep 2012 18:33:05 +0200
changeset 17940 32b2e7f42f70
parent 17939 3e0e98fb9275
child 17941 163c8afae1d7
Fixes issue 21596, 21613: Changed behaviour of processing of
Pick and Execute Windows. Added where clause in view definition.
modules/org.openbravo.advpaymentmngt/src/org/openbravo/advpaymentmngt/actionHandler/PaymentProposalPickEditLines.java
src-db/database/model/views/M_RM_RECEIPT_PICK_EDIT.xml
src-db/database/model/views/M_RM_SHIPMENT_PICK_EDIT.xml
src-db/database/sourcedata/AD_COLUMN.xml
src-db/database/sourcedata/AD_FIELD.xml
src/org/openbravo/common/actionhandler/RMInOutPickEditLines.java
src/org/openbravo/common/actionhandler/RMShipmentPickEditLines.java
--- a/modules/org.openbravo.advpaymentmngt/src/org/openbravo/advpaymentmngt/actionHandler/PaymentProposalPickEditLines.java	Tue Sep 11 18:23:54 2012 +0200
+++ b/modules/org.openbravo.advpaymentmngt/src/org/openbravo/advpaymentmngt/actionHandler/PaymentProposalPickEditLines.java	Tue Sep 11 18:33:05 2012 +0200
@@ -21,6 +21,7 @@
 
 import java.math.BigDecimal;
 import java.util.HashMap;
+import java.util.List;
 import java.util.Map;
 
 import org.apache.log4j.Logger;
@@ -34,6 +35,7 @@
 import org.openbravo.client.kernel.RequestContext;
 import org.openbravo.dal.core.OBContext;
 import org.openbravo.dal.service.OBDal;
+import org.openbravo.dal.service.OBDao;
 import org.openbravo.erpCommon.utility.OBMessageUtils;
 import org.openbravo.model.financialmgmt.payment.FIN_PaymentMethod;
 import org.openbravo.model.financialmgmt.payment.FIN_PaymentPropDetail;
@@ -63,20 +65,19 @@
       FIN_PaymentMethod paymentMethod = OBDal.getInstance().get(FIN_PaymentMethod.class,
           strPaymentMethodId);
 
-      if (cleanPaymentProposalDetails(paymentProposal)) {
-        HashMap<String, String> map = createPaymentProposalDetails(jsonRequest, paymentMethod);
-        jsonRequest = new JSONObject();
+      List<String> idList = OBDao.getIDListFromOBObject(paymentProposal
+          .getFINPaymentPropDetailList());
+      HashMap<String, String> map = createPaymentProposalDetails(jsonRequest, paymentMethod, idList);
+      jsonRequest = new JSONObject();
 
-        JSONObject errorMessage = new JSONObject();
-        errorMessage.put("severity", "success");
-        errorMessage.put("text", OBMessageUtils.messageBD("Success"));
-        if (map.get("DifferentPaymentMethod").equals("true")) {
-          errorMessage.put("severity", "warning");
-          errorMessage.put("text",
-              OBMessageUtils.messageBD("APRM_Different_PaymentMethod_Selected"));
-        }
-        jsonRequest.put("message", errorMessage);
+      JSONObject errorMessage = new JSONObject();
+      errorMessage.put("severity", "success");
+      errorMessage.put("text", OBMessageUtils.messageBD("Success"));
+      if (map.get("DifferentPaymentMethod").equals("true")) {
+        errorMessage.put("severity", "warning");
+        errorMessage.put("text", OBMessageUtils.messageBD("APRM_Different_PaymentMethod_Selected"));
       }
+      jsonRequest.put("message", errorMessage);
 
     } catch (Exception e) {
       OBDal.getInstance().rollbackAndClose();
@@ -100,40 +101,21 @@
     return jsonRequest;
   }
 
-  private boolean cleanPaymentProposalDetails(FIN_PaymentProposal paymentProposal) {
-    if (paymentProposal == null) {
-      return false;
-    } else if (paymentProposal.getFINPaymentPropDetailList().isEmpty()) {
-      // nothing to delete.
-      return true;
-    }
-    try {
-      paymentProposal.getFINPaymentPropDetailList().clear();
-      paymentProposal.setAmount(BigDecimal.ZERO);
-      paymentProposal.setWriteoffAmount(BigDecimal.ZERO);
-      OBDal.getInstance().save(paymentProposal);
-      OBDal.getInstance().flush();
-    } catch (Exception e) {
-      log.error(e.getMessage(), e);
-      return false;
-    }
-    return true;
-  }
-
   private HashMap<String, String> createPaymentProposalDetails(JSONObject jsonRequest,
-      FIN_PaymentMethod paymentMethod) throws JSONException, OBException {
+      FIN_PaymentMethod paymentMethod, List<String> idList) throws JSONException, OBException {
 
     HashMap<String, String> map = new HashMap<String, String>();
     map.put("DifferentPaymentMethod", "false");
     map.put("Count", "0");
     JSONArray selectedLines = jsonRequest.getJSONArray("_selection");
-    // if no lines selected don't do anything.
-    if (selectedLines.length() == 0) {
-      return map;
-    }
     final String strPaymentProposalId = jsonRequest.getString("Fin_Payment_Proposal_ID");
     FIN_PaymentProposal paymentProposal = OBDal.getInstance().get(FIN_PaymentProposal.class,
         strPaymentProposalId);
+    // if no lines selected don't do anything.
+    if (selectedLines.length() == 0) {
+      removeNonSelectedLines(idList, paymentProposal);
+      return map;
+    }
     BigDecimal totalAmount = BigDecimal.ZERO, totalWriteOff = BigDecimal.ZERO;
     int cont = 0;
     String differentPaymentMethod = "false";
@@ -148,7 +130,17 @@
         if (!paymentMethod.equals(linePaymentMethod)) {
           differentPaymentMethod = "true";
         }
-        FIN_PaymentPropDetail newPPD = OBProvider.getInstance().get(FIN_PaymentPropDetail.class);
+
+        FIN_PaymentPropDetail newPPD = null;
+        String strPpdId = selectedLine.getString("id");
+        boolean notExistsPayPropLine = idList.contains(strPpdId);
+        if (notExistsPayPropLine) {
+          newPPD = OBDal.getInstance().get(FIN_PaymentPropDetail.class, strPpdId);
+          idList.remove(strPpdId);
+        } else {
+          newPPD = OBProvider.getInstance().get(FIN_PaymentPropDetail.class);
+        }
+
         newPPD.setOrganization(paymentProposal.getOrganization());
         newPPD.setClient(paymentProposal.getClient());
         newPPD.setCreatedBy(paymentProposal.getCreatedBy());
@@ -172,6 +164,8 @@
       }
     }
 
+    removeNonSelectedLines(idList, paymentProposal);
+
     paymentProposal.setAmount(totalAmount);
     paymentProposal.setWriteoffAmount(totalWriteOff);
     OBDal.getInstance().save(paymentProposal);
@@ -179,4 +173,16 @@
     map.put("Count", Integer.toString(cont));
     return map;
   }
+
+  private void removeNonSelectedLines(List<String> idList, FIN_PaymentProposal paymentProposal) {
+    if (idList.size() > 0) {
+      for (String id : idList) {
+        FIN_PaymentPropDetail ppd = OBDal.getInstance().get(FIN_PaymentPropDetail.class, id);
+        paymentProposal.getFINPaymentPropDetailList().remove(ppd);
+        OBDal.getInstance().remove(ppd);
+      }
+      OBDal.getInstance().save(paymentProposal);
+      OBDal.getInstance().flush();
+    }
+  }
 }
--- a/src-db/database/model/views/M_RM_RECEIPT_PICK_EDIT.xml	Tue Sep 11 18:23:54 2012 +0200
+++ b/src-db/database/model/views/M_RM_RECEIPT_PICK_EDIT.xml	Tue Sep 11 18:33:05 2012 +0200
@@ -4,7 +4,7 @@
 CASE
 WHEN iol.m_inoutline_id IS NOT NULL THEN 'Y'
 ELSE 'N'
-END AS ob_selected, ol.c_orderline_id, ol.m_product_id, ol.c_uom_id, ol.m_attributesetinstance_id, (-1) * ol.qtyordered AS returned, (-1) * (ol.qtyordered - ol.qtydelivered) AS pendingqty, (-1) * iol.movementqty AS receivingqty, iol.m_condition_goods_id, iol.m_locator_id, o.documentno AS returnorderno, o.issotrx, ol.line
+END AS ob_selected, ol.c_orderline_id, ol.m_product_id, ol.c_uom_id, ol.m_attributesetinstance_id, (-1) * ol.qtyordered AS returned, (-1) * (ol.qtyordered - ol.qtydelivered) AS pendingqty, (-1) * iol.movementqty AS receivingqty, iol.m_condition_goods_id, iol.m_locator_id, o.documentno AS returnorderno, o.issotrx, ol.line, iol.m_inoutline_id
 FROM c_orderline ol
 JOIN c_order o ON o.c_order_id = ol.c_order_id
 JOIN m_product p ON ol.m_product_id = p.m_product_id
@@ -12,5 +12,5 @@
 LEFT JOIN (SELECT il2.m_inoutline_id, il2.ad_client_id, il2.ad_org_id, il2.isactive, il2.created, il2.createdby, il2.updated, il2.updatedby, il2.line, il2.description, il2.m_inout_id, il2.c_orderline_id, il2.m_locator_id, il2.m_product_id, il2.c_uom_id, il2.movementqty, il2.isinvoiced, il2.m_attributesetinstance_id, il2.isdescription, il2.quantityorder, il2.m_product_uom_id, il2.m_condition_goods_id
 FROM m_inoutline il2
 JOIN m_inout i2 ON il2.m_inout_id = i2.m_inout_id AND i2.processed = 'N') iol ON iol.c_orderline_id = ol.c_orderline_id
-WHERE (ol.qtyordered - ol.qtydelivered) <> 0]]></view>
+WHERE (ol.qtyordered - ol.qtydelivered) <> 0 AND o.docstatus = 'CO']]></view>
   </database>
--- a/src-db/database/model/views/M_RM_SHIPMENT_PICK_EDIT.xml	Tue Sep 11 18:23:54 2012 +0200
+++ b/src-db/database/model/views/M_RM_SHIPMENT_PICK_EDIT.xml	Tue Sep 11 18:33:05 2012 +0200
@@ -7,7 +7,7 @@
 CASE
 WHEN iol.m_inout_id IS NOT NULL THEN 'Y'
 ELSE 'N'
-END AS ob_selected, ol.c_orderline_id, ol.line
+END AS ob_selected, ol.c_orderline_id, ol.line, iol.m_inoutline_id
 FROM c_orderline ol
 JOIN c_order o ON o.c_order_id = ol.c_order_id AND o.processed = 'Y' AND o.issotrx = 'N'
 LEFT JOIN m_storage_detail sd ON sd.m_product_id = ol.m_product_id AND COALESCE(sd.m_attributesetinstance_id, '0') = COALESCE(ol.m_attributesetinstance_id, '0') AND sd.qtyonhand > 0
@@ -15,5 +15,6 @@
 JOIN c_doctype dt ON o.c_doctypetarget_id = dt.c_doctype_id AND dt.isreturn = 'Y'
 LEFT JOIN (SELECT iol2.m_inoutline_id, iol2.m_inout_id, iol2.movementqty, iol2.c_orderline_id, iol2.ad_org_id, iol2.m_locator_id
 FROM m_inoutline iol2
-JOIN m_inout io2 ON iol2.m_inout_id = io2.m_inout_id AND io2.processed = 'N') iol ON iol.c_orderline_id = ol.c_orderline_id AND iol.m_locator_id = sd.m_locator_id]]></view>
+JOIN m_inout io2 ON iol2.m_inout_id = io2.m_inout_id AND io2.processed = 'N') iol ON iol.c_orderline_id = ol.c_orderline_id AND iol.m_locator_id = sd.m_locator_id
+WHERE o.docstatus = 'CO']]></view>
   </database>
--- a/src-db/database/sourcedata/AD_COLUMN.xml	Tue Sep 11 18:23:54 2012 +0200
+++ b/src-db/database/sourcedata/AD_COLUMN.xml	Tue Sep 11 18:33:05 2012 +0200
@@ -286424,6 +286424,41 @@
 <!--B9336FB7C2B0400EB495358FAB55E17F-->  <ISUSEDSEQUENCE><![CDATA[N]]></ISUSEDSEQUENCE>
 <!--B9336FB7C2B0400EB495358FAB55E17F--></AD_COLUMN>
 
+<!--B934D981294447DAB74A7F341C846537--><AD_COLUMN>
+<!--B934D981294447DAB74A7F341C846537-->  <AD_COLUMN_ID><![CDATA[B934D981294447DAB74A7F341C846537]]></AD_COLUMN_ID>
+<!--B934D981294447DAB74A7F341C846537-->  <AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID>
+<!--B934D981294447DAB74A7F341C846537-->  <AD_ORG_ID><![CDATA[0]]></AD_ORG_ID>
+<!--B934D981294447DAB74A7F341C846537-->  <ISACTIVE><![CDATA[Y]]></ISACTIVE>
+<!--B934D981294447DAB74A7F341C846537-->  <NAME><![CDATA[Goods Shipment Line]]></NAME>
+<!--B934D981294447DAB74A7F341C846537-->  <DESCRIPTION><![CDATA[A statement displaying one item, charge, or movement in a shipment.]]></DESCRIPTION>
+<!--B934D981294447DAB74A7F341C846537-->  <HELP><![CDATA[The Goods Shipment Line indicates a unique line in a Shipment document]]></HELP>
+<!--B934D981294447DAB74A7F341C846537-->  <COLUMNNAME><![CDATA[M_Inoutline_ID]]></COLUMNNAME>
+<!--B934D981294447DAB74A7F341C846537-->  <AD_TABLE_ID><![CDATA[347B0AA5C3CD4D18910D2FE4990B790E]]></AD_TABLE_ID>
+<!--B934D981294447DAB74A7F341C846537-->  <AD_REFERENCE_ID><![CDATA[19]]></AD_REFERENCE_ID>
+<!--B934D981294447DAB74A7F341C846537-->  <FIELDLENGTH><![CDATA[32]]></FIELDLENGTH>
+<!--B934D981294447DAB74A7F341C846537-->  <ISKEY><![CDATA[N]]></ISKEY>
+<!--B934D981294447DAB74A7F341C846537-->  <ISPARENT><![CDATA[N]]></ISPARENT>
+<!--B934D981294447DAB74A7F341C846537-->  <ISMANDATORY><![CDATA[N]]></ISMANDATORY>
+<!--B934D981294447DAB74A7F341C846537-->  <ISUPDATEABLE><![CDATA[Y]]></ISUPDATEABLE>
+<!--B934D981294447DAB74A7F341C846537-->  <ISIDENTIFIER><![CDATA[N]]></ISIDENTIFIER>
+<!--B934D981294447DAB74A7F341C846537-->  <SEQNO><![CDATA[220]]></SEQNO>
+<!--B934D981294447DAB74A7F341C846537-->  <ISTRANSLATED><![CDATA[N]]></ISTRANSLATED>
+<!--B934D981294447DAB74A7F341C846537-->  <ISENCRYPTED><![CDATA[N]]></ISENCRYPTED>
+<!--B934D981294447DAB74A7F341C846537-->  <ISSELECTIONCOLUMN><![CDATA[N]]></ISSELECTIONCOLUMN>
+<!--B934D981294447DAB74A7F341C846537-->  <AD_ELEMENT_ID><![CDATA[1026]]></AD_ELEMENT_ID>
+<!--B934D981294447DAB74A7F341C846537-->  <ISSESSIONATTR><![CDATA[N]]></ISSESSIONATTR>
+<!--B934D981294447DAB74A7F341C846537-->  <ISSECONDARYKEY><![CDATA[N]]></ISSECONDARYKEY>
+<!--B934D981294447DAB74A7F341C846537-->  <ISDESENCRYPTABLE><![CDATA[N]]></ISDESENCRYPTABLE>
+<!--B934D981294447DAB74A7F341C846537-->  <DEVELOPMENTSTATUS><![CDATA[RE]]></DEVELOPMENTSTATUS>
+<!--B934D981294447DAB74A7F341C846537-->  <AD_MODULE_ID><![CDATA[0]]></AD_MODULE_ID>
+<!--B934D981294447DAB74A7F341C846537-->  <POSITION><![CDATA[22]]></POSITION>
+<!--B934D981294447DAB74A7F341C846537-->  <ISTRANSIENT><![CDATA[N]]></ISTRANSIENT>
+<!--B934D981294447DAB74A7F341C846537-->  <ISAUTOSAVE><![CDATA[Y]]></ISAUTOSAVE>
+<!--B934D981294447DAB74A7F341C846537-->  <VALIDATEONNEW><![CDATA[Y]]></VALIDATEONNEW>
+<!--B934D981294447DAB74A7F341C846537-->  <IMAGESIZEVALUESACTION><![CDATA[N]]></IMAGESIZEVALUESACTION>
+<!--B934D981294447DAB74A7F341C846537-->  <ISUSEDSEQUENCE><![CDATA[N]]></ISUSEDSEQUENCE>
+<!--B934D981294447DAB74A7F341C846537--></AD_COLUMN>
+
 <!--B956EBF22FD411DE9A5F001D09C4A2FE--><AD_COLUMN>
 <!--B956EBF22FD411DE9A5F001D09C4A2FE-->  <AD_COLUMN_ID><![CDATA[B956EBF22FD411DE9A5F001D09C4A2FE]]></AD_COLUMN_ID>
 <!--B956EBF22FD411DE9A5F001D09C4A2FE-->  <AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID>
@@ -290026,6 +290061,41 @@
 <!--D36D4B0065004AFEB99191A531E976D3-->  <ISUSEDSEQUENCE><![CDATA[N]]></ISUSEDSEQUENCE>
 <!--D36D4B0065004AFEB99191A531E976D3--></AD_COLUMN>
 
+<!--D3C7655590C54ECEBA9A7C27A2D7B57D--><AD_COLUMN>
+<!--D3C7655590C54ECEBA9A7C27A2D7B57D-->  <AD_COLUMN_ID><![CDATA[D3C7655590C54ECEBA9A7C27A2D7B57D]]></AD_COLUMN_ID>
+<!--D3C7655590C54ECEBA9A7C27A2D7B57D-->  <AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID>
+<!--D3C7655590C54ECEBA9A7C27A2D7B57D-->  <AD_ORG_ID><![CDATA[0]]></AD_ORG_ID>
+<!--D3C7655590C54ECEBA9A7C27A2D7B57D-->  <ISACTIVE><![CDATA[Y]]></ISACTIVE>
+<!--D3C7655590C54ECEBA9A7C27A2D7B57D-->  <NAME><![CDATA[Goods Shipment Line]]></NAME>
+<!--D3C7655590C54ECEBA9A7C27A2D7B57D-->  <DESCRIPTION><![CDATA[A statement displaying one item, charge, or movement in a shipment.]]></DESCRIPTION>
+<!--D3C7655590C54ECEBA9A7C27A2D7B57D-->  <HELP><![CDATA[The Goods Shipment Line indicates a unique line in a Shipment document]]></HELP>
+<!--D3C7655590C54ECEBA9A7C27A2D7B57D-->  <COLUMNNAME><![CDATA[M_Inoutline_ID]]></COLUMNNAME>
+<!--D3C7655590C54ECEBA9A7C27A2D7B57D-->  <AD_TABLE_ID><![CDATA[09C5EA393D0D41CEBB522DEC67534574]]></AD_TABLE_ID>
+<!--D3C7655590C54ECEBA9A7C27A2D7B57D-->  <AD_REFERENCE_ID><![CDATA[19]]></AD_REFERENCE_ID>
+<!--D3C7655590C54ECEBA9A7C27A2D7B57D-->  <FIELDLENGTH><![CDATA[32]]></FIELDLENGTH>
+<!--D3C7655590C54ECEBA9A7C27A2D7B57D-->  <ISKEY><![CDATA[N]]></ISKEY>
+<!--D3C7655590C54ECEBA9A7C27A2D7B57D-->  <ISPARENT><![CDATA[N]]></ISPARENT>
+<!--D3C7655590C54ECEBA9A7C27A2D7B57D-->  <ISMANDATORY><![CDATA[N]]></ISMANDATORY>
+<!--D3C7655590C54ECEBA9A7C27A2D7B57D-->  <ISUPDATEABLE><![CDATA[Y]]></ISUPDATEABLE>
+<!--D3C7655590C54ECEBA9A7C27A2D7B57D-->  <ISIDENTIFIER><![CDATA[N]]></ISIDENTIFIER>
+<!--D3C7655590C54ECEBA9A7C27A2D7B57D-->  <SEQNO><![CDATA[240]]></SEQNO>
+<!--D3C7655590C54ECEBA9A7C27A2D7B57D-->  <ISTRANSLATED><![CDATA[N]]></ISTRANSLATED>
+<!--D3C7655590C54ECEBA9A7C27A2D7B57D-->  <ISENCRYPTED><![CDATA[N]]></ISENCRYPTED>
+<!--D3C7655590C54ECEBA9A7C27A2D7B57D-->  <ISSELECTIONCOLUMN><![CDATA[N]]></ISSELECTIONCOLUMN>
+<!--D3C7655590C54ECEBA9A7C27A2D7B57D-->  <AD_ELEMENT_ID><![CDATA[1026]]></AD_ELEMENT_ID>
+<!--D3C7655590C54ECEBA9A7C27A2D7B57D-->  <ISSESSIONATTR><![CDATA[N]]></ISSESSIONATTR>
+<!--D3C7655590C54ECEBA9A7C27A2D7B57D-->  <ISSECONDARYKEY><![CDATA[N]]></ISSECONDARYKEY>
+<!--D3C7655590C54ECEBA9A7C27A2D7B57D-->  <ISDESENCRYPTABLE><![CDATA[N]]></ISDESENCRYPTABLE>
+<!--D3C7655590C54ECEBA9A7C27A2D7B57D-->  <DEVELOPMENTSTATUS><![CDATA[RE]]></DEVELOPMENTSTATUS>
+<!--D3C7655590C54ECEBA9A7C27A2D7B57D-->  <AD_MODULE_ID><![CDATA[0]]></AD_MODULE_ID>
+<!--D3C7655590C54ECEBA9A7C27A2D7B57D-->  <POSITION><![CDATA[23]]></POSITION>
+<!--D3C7655590C54ECEBA9A7C27A2D7B57D-->  <ISTRANSIENT><![CDATA[N]]></ISTRANSIENT>
+<!--D3C7655590C54ECEBA9A7C27A2D7B57D-->  <ISAUTOSAVE><![CDATA[Y]]></ISAUTOSAVE>
+<!--D3C7655590C54ECEBA9A7C27A2D7B57D-->  <VALIDATEONNEW><![CDATA[Y]]></VALIDATEONNEW>
+<!--D3C7655590C54ECEBA9A7C27A2D7B57D-->  <IMAGESIZEVALUESACTION><![CDATA[N]]></IMAGESIZEVALUESACTION>
+<!--D3C7655590C54ECEBA9A7C27A2D7B57D-->  <ISUSEDSEQUENCE><![CDATA[N]]></ISUSEDSEQUENCE>
+<!--D3C7655590C54ECEBA9A7C27A2D7B57D--></AD_COLUMN>
+
 <!--D3FE5311D6E04EDBA3BB2299082327BA--><AD_COLUMN>
 <!--D3FE5311D6E04EDBA3BB2299082327BA-->  <AD_COLUMN_ID><![CDATA[D3FE5311D6E04EDBA3BB2299082327BA]]></AD_COLUMN_ID>
 <!--D3FE5311D6E04EDBA3BB2299082327BA-->  <AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID>
--- a/src-db/database/sourcedata/AD_FIELD.xml	Tue Sep 11 18:23:54 2012 +0200
+++ b/src-db/database/sourcedata/AD_FIELD.xml	Tue Sep 11 18:33:05 2012 +0200
@@ -178748,6 +178748,35 @@
 <!--2113538C42F44FEA85C64B640938EA5D-->  <EM_OBUIAPP_SHOWSUMMARY><![CDATA[N]]></EM_OBUIAPP_SHOWSUMMARY>
 <!--2113538C42F44FEA85C64B640938EA5D--></AD_FIELD>
 
+<!--211DE32F933B4D72ABD824DCB2CF9A42--><AD_FIELD>
+<!--211DE32F933B4D72ABD824DCB2CF9A42-->  <AD_FIELD_ID><![CDATA[211DE32F933B4D72ABD824DCB2CF9A42]]></AD_FIELD_ID>
+<!--211DE32F933B4D72ABD824DCB2CF9A42-->  <AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID>
+<!--211DE32F933B4D72ABD824DCB2CF9A42-->  <AD_ORG_ID><![CDATA[0]]></AD_ORG_ID>
+<!--211DE32F933B4D72ABD824DCB2CF9A42-->  <ISACTIVE><![CDATA[Y]]></ISACTIVE>
+<!--211DE32F933B4D72ABD824DCB2CF9A42-->  <NAME><![CDATA[Goods Receipt Line]]></NAME>
+<!--211DE32F933B4D72ABD824DCB2CF9A42-->  <DESCRIPTION><![CDATA[A statement displaying one item, charge, or movement in a receipt.]]></DESCRIPTION>
+<!--211DE32F933B4D72ABD824DCB2CF9A42-->  <HELP><![CDATA[The Goods Receipt Line indicates a unique line in a Receipt document]]></HELP>
+<!--211DE32F933B4D72ABD824DCB2CF9A42-->  <ISCENTRALLYMAINTAINED><![CDATA[Y]]></ISCENTRALLYMAINTAINED>
+<!--211DE32F933B4D72ABD824DCB2CF9A42-->  <AD_TAB_ID><![CDATA[9195CC43B5A4419195030A4DB17D8737]]></AD_TAB_ID>
+<!--211DE32F933B4D72ABD824DCB2CF9A42-->  <AD_COLUMN_ID><![CDATA[B934D981294447DAB74A7F341C846537]]></AD_COLUMN_ID>
+<!--211DE32F933B4D72ABD824DCB2CF9A42-->  <IGNOREINWAD><![CDATA[N]]></IGNOREINWAD>
+<!--211DE32F933B4D72ABD824DCB2CF9A42-->  <ISDISPLAYED><![CDATA[N]]></ISDISPLAYED>
+<!--211DE32F933B4D72ABD824DCB2CF9A42-->  <DISPLAYLENGTH><![CDATA[32]]></DISPLAYLENGTH>
+<!--211DE32F933B4D72ABD824DCB2CF9A42-->  <ISREADONLY><![CDATA[N]]></ISREADONLY>
+<!--211DE32F933B4D72ABD824DCB2CF9A42-->  <SEQNO><![CDATA[100]]></SEQNO>
+<!--211DE32F933B4D72ABD824DCB2CF9A42-->  <ISSAMELINE><![CDATA[N]]></ISSAMELINE>
+<!--211DE32F933B4D72ABD824DCB2CF9A42-->  <ISFIELDONLY><![CDATA[N]]></ISFIELDONLY>
+<!--211DE32F933B4D72ABD824DCB2CF9A42-->  <ISENCRYPTED><![CDATA[N]]></ISENCRYPTED>
+<!--211DE32F933B4D72ABD824DCB2CF9A42-->  <SHOWINRELATION><![CDATA[N]]></SHOWINRELATION>
+<!--211DE32F933B4D72ABD824DCB2CF9A42-->  <ISFIRSTFOCUSEDFIELD><![CDATA[N]]></ISFIRSTFOCUSEDFIELD>
+<!--211DE32F933B4D72ABD824DCB2CF9A42-->  <AD_MODULE_ID><![CDATA[0]]></AD_MODULE_ID>
+<!--211DE32F933B4D72ABD824DCB2CF9A42-->  <GRID_SEQNO><![CDATA[0]]></GRID_SEQNO>
+<!--211DE32F933B4D72ABD824DCB2CF9A42-->  <STARTINODDCOLUMN><![CDATA[N]]></STARTINODDCOLUMN>
+<!--211DE32F933B4D72ABD824DCB2CF9A42-->  <STARTNEWLINE><![CDATA[N]]></STARTNEWLINE>
+<!--211DE32F933B4D72ABD824DCB2CF9A42-->  <ISSHOWNINSTATUSBAR><![CDATA[N]]></ISSHOWNINSTATUSBAR>
+<!--211DE32F933B4D72ABD824DCB2CF9A42-->  <EM_OBUIAPP_SHOWSUMMARY><![CDATA[N]]></EM_OBUIAPP_SHOWSUMMARY>
+<!--211DE32F933B4D72ABD824DCB2CF9A42--></AD_FIELD>
+
 <!--213C704E7DA24637A57E5EA08E9AFCE4--><AD_FIELD>
 <!--213C704E7DA24637A57E5EA08E9AFCE4-->  <AD_FIELD_ID><![CDATA[213C704E7DA24637A57E5EA08E9AFCE4]]></AD_FIELD_ID>
 <!--213C704E7DA24637A57E5EA08E9AFCE4-->  <AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID>
@@ -233807,6 +233836,35 @@
 <!--EAA7756C0C22496391FB11F9D54CE4B6-->  <EM_OBUIAPP_SHOWSUMMARY><![CDATA[N]]></EM_OBUIAPP_SHOWSUMMARY>
 <!--EAA7756C0C22496391FB11F9D54CE4B6--></AD_FIELD>
 
+<!--EB3EF5438B7044BEA1AE5731F4FB579D--><AD_FIELD>
+<!--EB3EF5438B7044BEA1AE5731F4FB579D-->  <AD_FIELD_ID><![CDATA[EB3EF5438B7044BEA1AE5731F4FB579D]]></AD_FIELD_ID>
+<!--EB3EF5438B7044BEA1AE5731F4FB579D-->  <AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID>
+<!--EB3EF5438B7044BEA1AE5731F4FB579D-->  <AD_ORG_ID><![CDATA[0]]></AD_ORG_ID>
+<!--EB3EF5438B7044BEA1AE5731F4FB579D-->  <ISACTIVE><![CDATA[Y]]></ISACTIVE>
+<!--EB3EF5438B7044BEA1AE5731F4FB579D-->  <NAME><![CDATA[Goods Shipment Line]]></NAME>
+<!--EB3EF5438B7044BEA1AE5731F4FB579D-->  <DESCRIPTION><![CDATA[A statement displaying one item, charge, or movement in a shipment.]]></DESCRIPTION>
+<!--EB3EF5438B7044BEA1AE5731F4FB579D-->  <HELP><![CDATA[The Goods Shipment Line indicates a unique line in a Shipment document]]></HELP>
+<!--EB3EF5438B7044BEA1AE5731F4FB579D-->  <ISCENTRALLYMAINTAINED><![CDATA[Y]]></ISCENTRALLYMAINTAINED>
+<!--EB3EF5438B7044BEA1AE5731F4FB579D-->  <AD_TAB_ID><![CDATA[FEFB495F59894AD6A1163D13ABE88833]]></AD_TAB_ID>
+<!--EB3EF5438B7044BEA1AE5731F4FB579D-->  <AD_COLUMN_ID><![CDATA[D3C7655590C54ECEBA9A7C27A2D7B57D]]></AD_COLUMN_ID>
+<!--EB3EF5438B7044BEA1AE5731F4FB579D-->  <IGNOREINWAD><![CDATA[N]]></IGNOREINWAD>
+<!--EB3EF5438B7044BEA1AE5731F4FB579D-->  <ISDISPLAYED><![CDATA[N]]></ISDISPLAYED>
+<!--EB3EF5438B7044BEA1AE5731F4FB579D-->  <DISPLAYLENGTH><![CDATA[32]]></DISPLAYLENGTH>
+<!--EB3EF5438B7044BEA1AE5731F4FB579D-->  <ISREADONLY><![CDATA[N]]></ISREADONLY>
+<!--EB3EF5438B7044BEA1AE5731F4FB579D-->  <SEQNO><![CDATA[100]]></SEQNO>
+<!--EB3EF5438B7044BEA1AE5731F4FB579D-->  <ISSAMELINE><![CDATA[N]]></ISSAMELINE>
+<!--EB3EF5438B7044BEA1AE5731F4FB579D-->  <ISFIELDONLY><![CDATA[N]]></ISFIELDONLY>
+<!--EB3EF5438B7044BEA1AE5731F4FB579D-->  <ISENCRYPTED><![CDATA[N]]></ISENCRYPTED>
+<!--EB3EF5438B7044BEA1AE5731F4FB579D-->  <SHOWINRELATION><![CDATA[N]]></SHOWINRELATION>
+<!--EB3EF5438B7044BEA1AE5731F4FB579D-->  <ISFIRSTFOCUSEDFIELD><![CDATA[N]]></ISFIRSTFOCUSEDFIELD>
+<!--EB3EF5438B7044BEA1AE5731F4FB579D-->  <AD_MODULE_ID><![CDATA[0]]></AD_MODULE_ID>
+<!--EB3EF5438B7044BEA1AE5731F4FB579D-->  <GRID_SEQNO><![CDATA[0]]></GRID_SEQNO>
+<!--EB3EF5438B7044BEA1AE5731F4FB579D-->  <STARTINODDCOLUMN><![CDATA[N]]></STARTINODDCOLUMN>
+<!--EB3EF5438B7044BEA1AE5731F4FB579D-->  <STARTNEWLINE><![CDATA[N]]></STARTNEWLINE>
+<!--EB3EF5438B7044BEA1AE5731F4FB579D-->  <ISSHOWNINSTATUSBAR><![CDATA[N]]></ISSHOWNINSTATUSBAR>
+<!--EB3EF5438B7044BEA1AE5731F4FB579D-->  <EM_OBUIAPP_SHOWSUMMARY><![CDATA[N]]></EM_OBUIAPP_SHOWSUMMARY>
+<!--EB3EF5438B7044BEA1AE5731F4FB579D--></AD_FIELD>
+
 <!--EB40FD68513C4A1098CF55A196A9E4BC--><AD_FIELD>
 <!--EB40FD68513C4A1098CF55A196A9E4BC-->  <AD_FIELD_ID><![CDATA[EB40FD68513C4A1098CF55A196A9E4BC]]></AD_FIELD_ID>
 <!--EB40FD68513C4A1098CF55A196A9E4BC-->  <AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID>
--- a/src/org/openbravo/common/actionhandler/RMInOutPickEditLines.java	Tue Sep 11 18:23:54 2012 +0200
+++ b/src/org/openbravo/common/actionhandler/RMInOutPickEditLines.java	Tue Sep 11 18:33:05 2012 +0200
@@ -30,6 +30,7 @@
 import org.openbravo.client.application.process.BaseProcessActionHandler;
 import org.openbravo.dal.core.OBContext;
 import org.openbravo.dal.service.OBDal;
+import org.openbravo.dal.service.OBDao;
 import org.openbravo.model.common.enterprise.Locator;
 import org.openbravo.model.common.order.OrderLine;
 import org.openbravo.model.materialmgmt.transaction.ShipmentInOut;
@@ -57,8 +58,10 @@
       // Issue 20585: https://issues.openbravo.com/view.php?id=20585
       final String strInOutId = jsonRequest.getString("M_InOut_ID");
       ShipmentInOut inOut = OBDal.getInstance().get(ShipmentInOut.class, strInOutId);
-      if (cleanInOutLines(inOut)) {
-        createInOutLines(jsonRequest);
+      if (inOut != null) {
+        List<String> idList = OBDao.getIDListFromOBObject(inOut
+            .getMaterialMgmtShipmentInOutLineList());
+        createInOutLines(jsonRequest, idList);
       }
 
     } catch (Exception e) {
@@ -69,36 +72,27 @@
     return jsonRequest;
   }
 
-  private boolean cleanInOutLines(ShipmentInOut inOut) {
-    if (inOut == null) {
-      return false;
-    } else if (inOut.getMaterialMgmtShipmentInOutLineList().isEmpty()) {
-      // nothing to delete.
-      return true;
-    }
-    try {
-      inOut.getMaterialMgmtShipmentInOutLineList().clear();
-      OBDal.getInstance().save(inOut);
-      OBDal.getInstance().flush();
-    } catch (Exception e) {
-      log.error(e.getMessage(), e);
-      return false;
-    }
-    return true;
-  }
-
-  private void createInOutLines(JSONObject jsonRequest) throws JSONException {
+  private void createInOutLines(JSONObject jsonRequest, List<String> idList) throws JSONException {
     JSONArray selectedLines = jsonRequest.getJSONArray("_selection");
+    final String strInOutId = jsonRequest.getString("M_InOut_ID");
+    ShipmentInOut inOut = OBDal.getInstance().get(ShipmentInOut.class, strInOutId);
     // if no lines selected don't do anything.
     if (selectedLines.length() == 0) {
+      removeNonSelectedLines(idList, inOut);
       return;
     }
-    final String strInOutId = jsonRequest.getString("M_InOut_ID");
-    ShipmentInOut inOut = OBDal.getInstance().get(ShipmentInOut.class, strInOutId);
     for (long i = 0; i < selectedLines.length(); i++) {
       JSONObject selectedLine = selectedLines.getJSONObject((int) i);
       log.debug(selectedLine);
-      ShipmentInOutLine newInOutLine = OBProvider.getInstance().get(ShipmentInOutLine.class);
+      ShipmentInOutLine newInOutLine = null;
+      boolean notExistsShipmentLine = selectedLine.get("goodsShipmentLine").equals(null);
+      if (notExistsShipmentLine) {
+        newInOutLine = OBProvider.getInstance().get(ShipmentInOutLine.class);
+      } else {
+        newInOutLine = OBDal.getInstance().get(ShipmentInOutLine.class,
+            selectedLine.get("goodsShipmentLine"));
+        idList.remove(selectedLine.get("goodsShipmentLine"));
+      }
       newInOutLine.setShipmentReceipt(inOut);
       newInOutLine.setOrganization(inOut.getOrganization());
       newInOutLine.setLineNo((i + 1L) * 10L);
@@ -122,13 +116,29 @@
         newInOutLine.setConditionGoods(inOut.getConditionGoods());
       }
 
-      List<ShipmentInOutLine> inOutLines = inOut.getMaterialMgmtShipmentInOutLineList();
-      inOutLines.add(newInOutLine);
-      inOut.setMaterialMgmtShipmentInOutLineList(inOutLines);
+      if (notExistsShipmentLine) {
+        List<ShipmentInOutLine> inOutLines = inOut.getMaterialMgmtShipmentInOutLineList();
+        inOutLines.add(newInOutLine);
+        inOut.setMaterialMgmtShipmentInOutLineList(inOutLines);
+      }
 
       OBDal.getInstance().save(newInOutLine);
       OBDal.getInstance().save(inOut);
       OBDal.getInstance().flush();
     }
+
+    removeNonSelectedLines(idList, inOut);
+  }
+
+  private void removeNonSelectedLines(List<String> idList, ShipmentInOut inOut) {
+    if (idList.size() > 0) {
+      for (String id : idList) {
+        ShipmentInOutLine iol = OBDal.getInstance().get(ShipmentInOutLine.class, id);
+        inOut.getMaterialMgmtShipmentInOutLineList().remove(iol);
+        OBDal.getInstance().remove(iol);
+      }
+      OBDal.getInstance().save(inOut);
+      OBDal.getInstance().flush();
+    }
   }
 }
--- a/src/org/openbravo/common/actionhandler/RMShipmentPickEditLines.java	Tue Sep 11 18:23:54 2012 +0200
+++ b/src/org/openbravo/common/actionhandler/RMShipmentPickEditLines.java	Tue Sep 11 18:33:05 2012 +0200
@@ -31,6 +31,7 @@
 import org.openbravo.client.application.process.BaseProcessActionHandler;
 import org.openbravo.dal.core.OBContext;
 import org.openbravo.dal.service.OBDal;
+import org.openbravo.dal.service.OBDao;
 import org.openbravo.model.common.enterprise.Locator;
 import org.openbravo.model.common.order.OrderLine;
 import org.openbravo.model.materialmgmt.transaction.ShipmentInOut;
@@ -58,8 +59,10 @@
       // Issue 20585: https://issues.openbravo.com/view.php?id=20585
       final String strInOutId = jsonRequest.getString("M_InOut_ID");
       ShipmentInOut inOut = OBDal.getInstance().get(ShipmentInOut.class, strInOutId);
-      if (cleanInOutLines(inOut)) {
-        createInOutLines(jsonRequest);
+      if (inOut != null) {
+        List<String> idList = OBDao.getIDListFromOBObject(inOut
+            .getMaterialMgmtShipmentInOutLineList());
+        createInOutLines(jsonRequest, idList);
       }
 
     } catch (Exception e) {
@@ -70,40 +73,33 @@
     return jsonRequest;
   }
 
-  private boolean cleanInOutLines(ShipmentInOut inOut) {
-    if (inOut == null) {
-      return false;
-    } else if (inOut.getMaterialMgmtShipmentInOutLineList().isEmpty()) {
-      if (inOut.getOrderReference() == null) {
-        setRefNo = true;
-      }
-      // nothing to delete.
-      return true;
-    }
-    try {
-      inOut.getMaterialMgmtShipmentInOutLineList().clear();
-      OBDal.getInstance().save(inOut);
-      OBDal.getInstance().flush();
-    } catch (Exception e) {
-      e.printStackTrace();
-      return false;
-    }
-    return true;
-  }
-
-  private void createInOutLines(JSONObject jsonRequest) throws JSONException {
+  private void createInOutLines(JSONObject jsonRequest, List<String> idList) throws JSONException {
     JSONArray selectedLines = jsonRequest.getJSONArray("_selection");
+    final String strInOutId = jsonRequest.getString("M_InOut_ID");
+    ShipmentInOut inOut = OBDal.getInstance().get(ShipmentInOut.class, strInOutId);
     // if no lines selected don't do anything.
     if (selectedLines.length() == 0) {
+      removeNonSelectedLines(idList, inOut);
       return;
     }
-    final String strInOutId = jsonRequest.getString("M_InOut_ID");
-    ShipmentInOut inOut = OBDal.getInstance().get(ShipmentInOut.class, strInOutId);
     TreeSet<String> rmVendorRefs = new TreeSet<String>();
     for (long i = 0; i < selectedLines.length(); i++) {
       JSONObject selectedLine = selectedLines.getJSONObject((int) i);
       log.debug(selectedLine);
-      ShipmentInOutLine newInOutLine = OBProvider.getInstance().get(ShipmentInOutLine.class);
+
+      if (selectedLine.get("movementQuantity").equals("0")) {
+        continue;
+      }
+
+      ShipmentInOutLine newInOutLine = null;
+      boolean notExistsShipmentLine = selectedLine.get("goodsShipmentLine").equals(null);
+      if (notExistsShipmentLine) {
+        newInOutLine = OBProvider.getInstance().get(ShipmentInOutLine.class);
+      } else {
+        newInOutLine = OBDal.getInstance().get(ShipmentInOutLine.class,
+            selectedLine.get("goodsShipmentLine"));
+        idList.remove(selectedLine.get("goodsShipmentLine"));
+      }
       newInOutLine.setShipmentReceipt(inOut);
       newInOutLine.setOrganization(inOut.getOrganization());
       newInOutLine.setLineNo((i + 1L) * 10L);
@@ -123,18 +119,35 @@
       BigDecimal qtyReceived = new BigDecimal(selectedLine.getString("movementQuantity"));
       newInOutLine.setMovementQuantity(qtyReceived.negate());
 
-      List<ShipmentInOutLine> inOutLines = inOut.getMaterialMgmtShipmentInOutLineList();
-      inOutLines.add(newInOutLine);
-      inOut.setMaterialMgmtShipmentInOutLineList(inOutLines);
+      if (notExistsShipmentLine) {
+        List<ShipmentInOutLine> inOutLines = inOut.getMaterialMgmtShipmentInOutLineList();
+        inOutLines.add(newInOutLine);
+        inOut.setMaterialMgmtShipmentInOutLineList(inOutLines);
+      }
 
       OBDal.getInstance().save(newInOutLine);
       OBDal.getInstance().save(inOut);
       OBDal.getInstance().flush();
     }
+
+    removeNonSelectedLines(idList, inOut);
+
     if (setRefNo && rmVendorRefs.size() == 1) {
       inOut.setOrderReference(rmVendorRefs.first());
       OBDal.getInstance().save(inOut);
       OBDal.getInstance().flush();
     }
   }
+
+  private void removeNonSelectedLines(List<String> idList, ShipmentInOut inOut) {
+    if (idList.size() > 0) {
+      for (String id : idList) {
+        ShipmentInOutLine iol = OBDal.getInstance().get(ShipmentInOutLine.class, id);
+        inOut.getMaterialMgmtShipmentInOutLineList().remove(iol);
+        OBDal.getInstance().remove(iol);
+      }
+      OBDal.getInstance().save(inOut);
+      OBDal.getInstance().flush();
+    }
+  }
 }