details:   https://code.openbravo.com/erp/devel/pi/rev/38a4c363f9c8
changeset: 33609:38a4c363f9c8
user:      Mark <markmm82 <at> gmail.com>
date:      Mon Feb 26 12:11:05 2018 -0500
summary:   Fixes issue 37882: Cannot add a purchase order line to a goods 
receipt if the
Alternate UOM feature is activated after the order was created.

If AUM is not enabled, when a purchase order is created it hasn't values in any 
of
the columns related with AUM. So, if the preference is activated after the order
creation, the ordered quantity will be used as AUMQTY and the UOM as AUM by 
default
when these order lines are copied to the receipt by the Create Lines From 
process and no
alternate units exists for the ordered product. In the case that alternate unit 
of
measure exists for the product the default AUM will be used as the receipt line 
AUM
and to calculate the operative quantity based on the conversion rate between 
the UOM and the AUM.

Were added to the XSQL file the return of the document type as C_DOCTYPE_ID 
field to use it when
the default AUM is calculated.

diffstat:

 src/org/openbravo/erpCommon/ad_actionButton/CreateFrom.java               |  
27 +++++++--
 src/org/openbravo/erpCommon/ad_actionButton/CreateFrom_Shipment_data.xsql |  
16 ++--
 2 files changed, 27 insertions(+), 16 deletions(-)

diffs (137 lines):

diff -r caae324d80d0 -r 38a4c363f9c8 
src/org/openbravo/erpCommon/ad_actionButton/CreateFrom.java
--- a/src/org/openbravo/erpCommon/ad_actionButton/CreateFrom.java       Tue Feb 
27 13:43:46 2018 +0530
+++ b/src/org/openbravo/erpCommon/ad_actionButton/CreateFrom.java       Mon Feb 
26 12:11:05 2018 -0500
@@ -11,7 +11,7 @@
  * under the License.
  * The Original Code is Openbravo ERP.
  * The Initial Developer of the Original Code is Openbravo SLU
- * All portions are Copyright (C) 2001-2017 Openbravo SLU
+ * All portions are Copyright (C) 2001-2018 Openbravo SLU
  * All Rights Reserved.
  * Contributor(s):  Cheli Pineda__________________________.
  ************************************************************************
@@ -46,8 +46,8 @@
 import org.openbravo.erpCommon.utility.AccDefUtility;
 import org.openbravo.erpCommon.utility.ComboTableData;
 import org.openbravo.erpCommon.utility.OBError;
+import org.openbravo.erpCommon.utility.SequenceIdData;
 import org.openbravo.erpCommon.utility.StringCollectionUtils;
-import org.openbravo.erpCommon.utility.SequenceIdData;
 import org.openbravo.erpCommon.utility.Utility;
 import org.openbravo.materialmgmt.UOMUtil;
 import org.openbravo.model.common.invoice.Invoice;
@@ -1891,15 +1891,15 @@
             String strAumQty = "";
             if (UOMUtil.isUomManagementEnabled() && 
data[i].mProductUomId.isEmpty()) {
               try {
+                if (data[i].cAum.isEmpty()) {
+                  data[i].cAum = getDefaultAUMForData(data[i]);
+                }
+                if (data[i].aumqty.isEmpty()) {
+                  data[i].aumqty = getConvertedAUMQtyForData(data[i]);
+                }
                 BigDecimal qtyAum = new BigDecimal(data[i].aumqty);
                 strAumQty = qtyAum.toString();
                 strMovementqty = qtyAum.toString();
-                if (data[i].cAum.isEmpty()) {
-                  FieldProvider[] defaultAumData = 
UOMUtil.selectDefaultAUM(data[i].mProductId,
-                      data[i].cDoctypeId);
-                  data[i].cAum = (defaultAumData.length > 0) ? 
defaultAumData[0]
-                      .getField(UOMUtil.FIELD_PROVIDER_ID) : data[i].cUomId;
-                }
                 if (!data[i].cUomId.equals(data[i].cAum)) {
                   strMovementqty = UOMUtil
                       .getConvertedQty(data[i].mProductId, qtyAum, 
data[i].cAum).toString();
@@ -2118,6 +2118,17 @@
     return myMessage;
   }
 
+  private String getConvertedAUMQtyForData(CreateFromShipmentData data) {
+    return UOMUtil.getConvertedAumQty(data.mProductId, new 
BigDecimal(data.id), data.cAum)
+        .toString();
+  }
+
+  private String getDefaultAUMForData(CreateFromShipmentData data) {
+    FieldProvider[] defaultAumData = UOMUtil.selectDefaultAUM(data.mProductId, 
data.cDoctypeId);
+    return (defaultAumData.length > 0) ? 
defaultAumData[0].getField(UOMUtil.FIELD_PROVIDER_ID)
+        : data.cUomId;
+  }
+
   protected OBError saveShipmentSO(VariablesSecureApp vars, String strKey, 
String strTableId,
       String strProcessId, String strWindowId) throws IOException, 
ServletException {
     if (log4j.isDebugEnabled())
diff -r caae324d80d0 -r 38a4c363f9c8 
src/org/openbravo/erpCommon/ad_actionButton/CreateFrom_Shipment_data.xsql
--- a/src/org/openbravo/erpCommon/ad_actionButton/CreateFrom_Shipment_data.xsql 
Tue Feb 27 13:43:46 2018 +0530
+++ b/src/org/openbravo/erpCommon/ad_actionButton/CreateFrom_Shipment_data.xsql 
Mon Feb 26 12:11:05 2018 -0500
@@ -12,7 +12,7 @@
  * under the License. 
  * The Original Code is Openbravo ERP. 
  * The Initial Developer of the Original Code is Openbravo SLU 
- * All portions are Copyright (C) 2001-2017 Openbravo SLU 
+ * All portions are Copyright (C) 2001-2018 Openbravo SLU 
  * All Rights Reserved. 
  * Contributor(s):  ______________________________________.
  ************************************************************************
@@ -267,7 +267,7 @@
       coalesce(l.a_asset_id,o.a_asset_id) as a_asset_id, 
coalesce(l.c_project_id, o.c_project_id) as c_project_id , 
          coalesce(l.c_costcenter_id,o.c_costcenter_id) as c_costcenter_id,
       coalesce(l.user1_id,o.user1_id) as user1_id,coalesce( 
l.user2_id,o.user2_id) as user2_id , 
-      coalesce (l.c_bpartner_id,o.c_bpartner_id) as c_bpartner_id, l.explode, 
'Y' as isorder
+      coalesce (l.c_bpartner_id,o.c_bpartner_id) as c_bpartner_id, l.explode, 
'Y' as isorder, o.C_DOCTYPE_ID AS C_DOCTYPE_ID
       FROM C_ORDERLINE l left join M_MATCHPO m on 
l.C_OrderLine_ID=m.C_OrderLine_ID
                                               and  m.M_InOutLine_ID IS NOT 
NULL 
                          left join M_Product_UOM mu on l.M_Product_UOM_ID = 
mu.M_Product_UOM_ID
@@ -279,7 +279,7 @@
       GROUP BY 
l.QtyOrdered,l.qtydelivered,l.C_UOM_ID,l.AUMQTY,l.C_AUM,uom.UOMSymbol,l.M_Product_ID,p.NAME,l.Line,l.C_OrderLine_ID,
 
       uom1.BREAKDOWN, l.QUANTITYORDER, l.M_Product_UOM_ID, 
l.M_ATTRIBUTESETINSTANCE_ID, l.ad_org_id, l.DESCRIPTION,
       coalesce(l.a_asset_id,o.a_asset_id), coalesce(l.c_project_id, 
o.c_project_id), coalesce(l.c_costcenter_id,o.c_costcenter_id) ,
-      coalesce(l.user1_id,o.user1_id) ,coalesce( l.user2_id,o.user2_id) , 
coalesce (l.c_bpartner_id,o.c_bpartner_id), l.explode 
+      coalesce(l.user1_id,o.user1_id) ,coalesce( l.user2_id,o.user2_id) , 
coalesce (l.c_bpartner_id,o.c_bpartner_id), l.explode, o.C_DOCTYPE_ID
       ORDER BY l.Line
       ]]>
     </Sql>
@@ -300,7 +300,7 @@
       coalesce(l.a_asset_id,o.a_asset_id) as a_asset_id, 
coalesce(l.c_project_id, o.c_project_id) as c_project_id , 
          coalesce(l.c_costcenter_id,o.c_costcenter_id) as c_costcenter_id,
       coalesce(l.user1_id,o.user1_id) as user1_id,coalesce( 
l.user2_id,o.user2_id) as user2_id , 
-      l.c_bpartner_id, l.explode, 'Y' as isorder
+      l.c_bpartner_id, l.explode, 'Y' as isorder, o.C_DOCTYPE_ID AS 
C_DOCTYPE_ID
       FROM C_ORDERLINE l left join M_Product_UOM mu on l.M_Product_UOM_ID = 
mu.M_Product_UOM_ID
                          left join C_UOM uom1 on mu.C_UOM_ID = uom1.C_UOM_ID ,
       C_UOM uom,  M_PRODUCT p, C_ORDER o
@@ -310,7 +310,7 @@
       GROUP BY 
l.QtyOrdered,l.qtydelivered,l.C_UOM_ID,l.AUMQTY,l.C_AUM,uom.UOMSymbol,l.M_Product_ID,p.NAME,l.Line,l.C_OrderLine_ID,
 
       uom1.BREAKDOWN, l.QUANTITYORDER, l.M_Product_UOM_ID, 
l.M_ATTRIBUTESETINSTANCE_ID, l.ad_org_id, l.DESCRIPTION,
       coalesce(l.a_asset_id,o.a_asset_id), coalesce(l.c_project_id, 
o.c_project_id), coalesce(l.c_costcenter_id,o.c_costcenter_id),
-         coalesce(l.user1_id,o.user1_id),coalesce( l.user2_id,o.user2_id), 
l.c_bpartner_id, l.explode
+         coalesce(l.user1_id,o.user1_id),coalesce( l.user2_id,o.user2_id), 
l.c_bpartner_id, l.explode, o.C_DOCTYPE_ID
       HAVING ((l.explode='Y')  OR (l.QtyOrdered - 
COALESCE(l.QTYDELIVERED,0)<>0)) 
       ORDER BY l.Line
       ]]>
@@ -341,7 +341,7 @@
         (SELECT M_ATTRIBUTESETINSTANCE.DESCRIPTION FROM M_ATTRIBUTESETINSTANCE 
WHERE l.M_ATTRIBUTESETINSTANCE_ID = 
M_ATTRIBUTESETINSTANCE.M_ATTRIBUTESETINSTANCE_ID) as ATTRIBUTESETINSTANCENAME, 
l.explode, l.Bom_parent_id, 
         CASE WHEN l.Bom_parent_id is null then 'Y' else 'N' END as isparent,
         l.AUMQTY - SUM(COALESCE(M_GET_CONVERTED_AUMQTY(l.m_product_id, mi.Qty, 
l.c_aum), 0)) AS AUMQTY, l.C_AUM AS C_AUM, 
-        (SELECT UOMSYMBOL FROM C_UOM WHERE C_UOM_ID = l.C_AUM) AS AUMNAME, '' 
AS UOMPREFERENCE
+        (SELECT UOMSYMBOL FROM C_UOM WHERE C_UOM_ID = l.C_AUM) AS AUMNAME, '' 
AS UOMPREFERENCE, i.C_DOCTYPE_ID AS C_DOCTYPE_ID
         FROM C_INVOICELINE l left join  M_MATCHINV mi  on 
l.C_InvoiceLine_ID=mi.C_InvoiceLine_ID,
         C_INVOICE i, C_UOM uom,  M_PRODUCT p
         WHERE i.C_INVOICE_ID = l.C_INVOICE_ID 
@@ -530,7 +530,7 @@
       coalesce(l.a_asset_id,i.a_asset_id) as a_asset_id, 
coalesce(l.c_project_id, i.c_project_id) as c_project_id, 
       coalesce(l.c_costcenter_id,i.c_costcenter_id) as c_costcenter_id , 
       coalesce(l.user1_id,i.user1_id ) as user1_id , coalesce(l.user2_id , 
i.user2_id) as user2_id, l.c_bpartner_id, l.explode, 
-      'N' as isorder,
+      'N' as isorder, i.C_DOCTYPE_ID AS C_DOCTYPE_ID,
       l.AUMQTY - SUM(COALESCE(M_GET_CONVERTED_AUMQTY(l.m_product_id, mi.Qty, 
l.c_aum), 0)) AS AUMQTY, l.C_AUM AS C_AUM, 
       (SELECT UOMSYMBOL FROM C_UOM WHERE C_UOM_ID = l.C_AUM) AS AUMNAME, '' AS 
UOMPREFERENCE
       FROM C_INVOICELINE l left join  M_Product_UOM mu on l.M_Product_UOM_ID = 
mu.M_Product_UOM_ID 
@@ -544,7 +544,7 @@
       l.C_UOM_ID,uom.UOMSymbol,l.M_Product_ID,p.NAME, 
l.C_InvoiceLine_ID,l.Line,l.C_OrderLine_ID, 
       l.AUMQTY, l.C_AUM,uom1.BREAKDOWN, l.QUANTITYORDER, l.M_Product_UOM_ID, 
l.M_ATTRIBUTESETINSTANCE_ID, l.ad_org_id, l.DESCRIPTION, l.C_INVOICE_ID,
       coalesce(l.a_asset_id,i.a_asset_id), coalesce(l.c_project_id, 
i.c_project_id), coalesce(l.c_costcenter_id,i.c_costcenter_id), 
-      coalesce(l.user1_id,i.user1_id ), coalesce(l.user2_id , 
i.user2_id),l.c_bpartner_id, l.explode
+      coalesce(l.user1_id,i.user1_id ), coalesce(l.user2_id , 
i.user2_id),l.c_bpartner_id, l.explode, i.c_doctype_id
       HAVING ((l.explode='Y')  OR (l.QtyInvoiced-SUM(COALESCE(mi.Qty,0))<>0))  
 
       ORDER BY l.Line
       ]]>

------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
Openbravo-commits mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/openbravo-commits

Reply via email to