[UOM Management] Sales and Purchase flows.
authorDavid Miguelez <david.miguelez@openbravo.com>
Fri, 11 Nov 2016 10:06:34 +0100
changeset 30807 ecf75ad34ce3
parent 30806 03b0e1ca6aac
child 30808 e8486b86b1cb
[UOM Management] Sales and Purchase flows.
Addapted both Sales and Purchase flows to support new UOM
Management functionality.
modules/org.openbravo.client.application/web/org.openbravo.client.application/js/procurement/ob-procurement.js
src-db/database/model/functions/C_INVOICE_CREATE.xml
src-db/database/model/functions/C_INVOICE_POST.xml
src-db/database/model/functions/C_ORDER_POST1.xml
src-db/database/model/functions/M_COPY_PRODUCT_TEMPLATE.xml
src-db/database/model/functions/M_EXPLODEBOMNOTSTOCK.xml
src-db/database/model/functions/M_INOUTEXPLODEBOMNOTSTOCK.xml
src-db/database/model/functions/M_INOUT_CREATE.xml
src-db/database/model/functions/M_INOUT_CREATEINVOICE.xml
src-db/database/model/functions/M_INOUT_POST.xml
src-db/database/model/functions/M_REQUISITION_CREATEPO.xml
src-db/database/model/triggers/C_INVLINE_CHK_RESTRICTIONS_TRG.xml
src-db/database/model/triggers/C_ORDLINE_CHK_RESTRICTIONS_TRG.xml
src-db/database/model/triggers/M_INOUTLINE_TRG.xml
src-db/database/model/triggers/M_IOLINE_CHK_RESTRICTIONS_TRG.xml
src-db/database/model/triggers/M_REQUISITIONLINE_TRG.xml
src-db/database/model/views/M_CREATEPOLINES_PE_V.xml
src-db/database/sourcedata/AD_CALLOUT.xml
src-db/database/sourcedata/AD_MODEL_OBJECT.xml
src-db/database/sourcedata/AD_MODEL_OBJECT_MAPPING.xml
src-db/database/sourcedata/OBUISEL_SELECTOR.xml
src/org/openbravo/common/actionhandler/OrderCreatePOLines.java
src/org/openbravo/erpCommon/ad_actionButton/CopyFromInvoice.java
src/org/openbravo/erpCommon/ad_actionButton/CopyFromInvoice_data.xsql
src/org/openbravo/erpCommon/ad_actionButton/CopyFromOrder.html
src/org/openbravo/erpCommon/ad_actionButton/CopyFromOrder.java
src/org/openbravo/erpCommon/ad_actionButton/CopyFromOrder.xml
src/org/openbravo/erpCommon/ad_actionButton/CopyFromOrder_data.xsql
src/org/openbravo/erpCommon/ad_actionButton/CopyFromPOOrder.java
src/org/openbravo/erpCommon/ad_actionButton/CopyFromPOOrder_data.xsql
src/org/openbravo/erpCommon/ad_actionButton/CreateFrom.java
src/org/openbravo/erpCommon/ad_actionButton/CreateFrom_Invoice.html
src/org/openbravo/erpCommon/ad_actionButton/CreateFrom_Invoice.xml
src/org/openbravo/erpCommon/ad_actionButton/CreateFrom_Invoice_data.xsql
src/org/openbravo/erpCommon/ad_actionButton/CreateFrom_ShipmentPO.html
src/org/openbravo/erpCommon/ad_actionButton/CreateFrom_ShipmentPO.xml
src/org/openbravo/erpCommon/ad_actionButton/CreateFrom_Shipment_data.xsql
src/org/openbravo/erpCommon/ad_callouts/SL_InOutLine_Product.java
src/org/openbravo/erpCommon/ad_callouts/SL_Invoice_Product.java
src/org/openbravo/erpCommon/ad_callouts/SL_Order_Product.java
src/org/openbravo/erpCommon/ad_callouts/SL_RequisitionLine_Product.java
src/org/openbravo/erpCommon/ad_forms/MaterialReceiptPending.html
src/org/openbravo/erpCommon/ad_forms/MaterialReceiptPending.java
src/org/openbravo/erpCommon/ad_forms/MaterialReceiptPending.xml
src/org/openbravo/erpCommon/ad_forms/MaterialReceiptPendingLines_data.xsql
src/org/openbravo/erpCommon/ad_forms/MaterialReceiptPending_data.xsql
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/modules/org.openbravo.client.application/web/org.openbravo.client.application/js/procurement/ob-procurement.js	Fri Nov 11 10:06:34 2016 +0100
@@ -0,0 +1,85 @@
+/*
+ *************************************************************************
+ * 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) 2016 Openbravo SLU
+ * All Rights Reserved.
+ * Contributor(s):  ______________________________________.
+ ************************************************************************
+ */
+
+OB.PROC = OB.PROC || {};
+
+/**
+ * Modify base Quantity when the Aum Quantity changes
+ */
+
+OB.PROC.CreateLinesOnChangeQuantityAum = function (item, view, form, grid) {
+  var aumQty = new BigDecimal(String(item.getValue()));
+  var record = grid.getSelectionObject().lastSelectionItem;
+  var aum = grid.getEditValues(grid.getRecordIndex(item.record)).aum === undefined ? record.aum : grid.getEditValues(grid.getRecordIndex(item.record)).aum;
+
+  OB.RemoteCallManager.call('org.openbravo.common.actionhandler.CreateLinesFromPOConvertAUM', {
+    productId: record.product,
+    quantity: Number(aumQty),
+    toUOM: aum,
+    reverse: 'N'
+  }, {}, function (response, data, request) {
+    if (data.amount) {
+      grid.setEditValue(item.grid.getEditRow(), 'orderedQuantity', Number(data.amount));
+    }
+  });
+};
+
+/**
+ * Modify base Aum Quantity when the base Quantity changes
+ */
+
+OB.PROC.CreateLinesOnChangeQuantity = function (item, view, form, grid) {
+  var qty = new BigDecimal(String(item.getValue()));
+  var record = grid.getSelectionObject().lastSelectionItem;
+  var aum = grid.getEditValues(grid.getRecordIndex(item.record)).aum === undefined ? record.aum : grid.getEditValues(grid.getRecordIndex(item.record)).aum;
+
+  OB.RemoteCallManager.call('org.openbravo.common.actionhandler.CreateLinesFromPOConvertAUM', {
+    productId: record.product,
+    quantity: Number(qty),
+    toUOM: aum,
+    reverse: 'Y'
+  }, {}, function (response, data, request) {
+    if (data.amount) {
+      grid.setEditValue(item.grid.getEditRow(), 'aumQuantity', Number(data.amount));
+    }
+  });
+};
+
+/**
+ * Modify base Quantity when the Aum selected changes
+ */
+
+OB.PROC.CreateLinesOnChangeAum = function (item, validator, value, record) {
+  var aum = item.getValue();
+  var changed_record = item.grid.getSelectionObject().lastSelectionItem;
+  var aumQty = item.grid.getEditValues(item.grid.getRecordIndex(item.record)).aumQuantity;
+
+  if (aumQty !== undefined) {
+    OB.RemoteCallManager.call('org.openbravo.common.actionhandler.CreateLinesFromPOConvertAUM', {
+      productId: changed_record.product,
+      quantity: Number(aumQty),
+      toUOM: aum,
+      reverse: 'N'
+    }, {}, function (response, data, request) {
+      if (data.amount) {
+        item.grid.setEditValue(item.grid.getEditRow(), 'orderedQuantity', Number(data.amount));
+      }
+    });
+  }
+};
\ No newline at end of file
--- a/src-db/database/model/functions/C_INVOICE_CREATE.xml	Fri Nov 11 10:01:28 2016 +0100
+++ b/src-db/database/model/functions/C_INVOICE_CREATE.xml	Fri Nov 11 10:06:34 2016 +0100
@@ -92,6 +92,10 @@
     v_period_inv C_InvoiceLine.c_period_id%TYPE;
     v_InOutLine_ID C_InvoiceLine.M_InOutLine_ID%TYPE;
 
+    v_uom_preference VARCHAR(1);	
+    v_default_aum VARCHAR(32);
+    v_aum_qty NUMBER;
+    
 
     Cur_Bpblocked RECORD;
     
@@ -124,6 +128,8 @@
           ol.C_Charge_ID,
           ol.ChargeAmt,
           COALESCE(sl.C_UOM_ID, ol.C_UOM_ID) AS C_UOM_ID,
+	  sl.AUMQTY,
+	  sl.C_AUM,
           --MODIFIED BY F.IRIAZABAL
           sl.M_PRODUCT_UOM_ID,
           ol.C_Tax_ID, --ol.IsTaxIncluded,
@@ -237,6 +243,15 @@
           END;
         END IF;
       BEGIN --BODY
+
+        -- Get UOMPreference value
+        SELECT COUNT(1) INTO v_count
+          FROM ad_preference
+          WHERE property = 'UomManagement';
+        IF (v_count > 0) THEN
+          v_uom_preference := AD_GET_PREFERENCE_VALUE('UomManagement', 'Y', NULL, v_AD_Org_ID, v_ADUserId, NULL, NULL);
+        END IF;
+		
         /**
         * Order Loop == all not completely invoiced orders == No Summary ==
         */
@@ -540,6 +555,7 @@
                     Description, M_Product_ID, QtyInvoiced, PriceList,
                     PriceActual, PriceLimit, LineNetAmt, C_Charge_ID,
                     ChargeAmt, C_UOM_ID, C_Tax_ID, PriceStd, 
+		    AUMQTY, C_AUM,
                     explode, bom_parent_id,
                     C_Project_ID, C_Bpartner_ID, A_Asset_ID,
                     C_Costcenter_ID, User1_ID, User2_ID
@@ -552,6 +568,7 @@
                     v_Reference, NULL, 0, 0,
                     0, 0, 0, NULL,
                     0, NULL, NULL, 0, 
+		    NULL, NULL,
                     ptr_sl.explode, (SELECT c_invoiceline_id 
                                             FROM c_invoiceline 
                                             WHERE c_invoice_id=p_Invoice_ID 
@@ -638,6 +655,15 @@
 												END IF;
 											END IF;
 	                  END IF;
+
+	            v_default_aum := CASE WHEN v_uom_preference = 'Y' AND ptr_ol.AUMQTY IS NULL AND ptr_ol.M_Product_Uom_ID IS NULL 
+					 THEN M_GET_DEFAULT_AUM_FOR_DOCUMENT(ptr_ol.M_Product_ID, '01360D369B5F473686354A701A6EA559') 
+					 ELSE ptr_ol.C_AUM 
+					 END;
+		    v_aum_qty := CASE WHEN v_uom_preference = 'Y' AND ptr_ol.AUMQTY IS NULL AND ptr_ol.M_Product_Uom_ID IS NULL 
+				     THEN M_GET_CONVERTED_AUMQTY(ptr_ol.M_Product_ID,v_Qty,v_default_aum) 
+				     ELSE ptr_ol.AUMQTY 
+				     END;					
                     INSERT
                     INTO C_INVOICELINE
                       (
@@ -647,6 +673,7 @@
                         Description, M_Product_ID, QtyInvoiced, PriceList,
                         PriceActual, PriceLimit, LineNetAmt, C_Charge_ID,
                         ChargeAmt, C_UOM_ID,
+			AUMQTY, C_AUM,
                         C_Tax_ID,  --MODIFIED BY F.IRIAZABAL
                         QuantityOrder, M_Product_Uom_ID, PriceStd,
                         m_attributesetinstance_id, taxbaseamt,
@@ -662,9 +689,13 @@
                         v_NextNo, ptr_ol.AD_Client_ID, ptr_ol.AD_Org_ID, 'Y',
                         now(), v_ADUserId, now(), v_ADUserId,
                         p_Invoice_ID, ptr_ol.C_OrderLine_ID, v_InOutLine_ID, v_LineNo,
-                        ptr_ol.Description, ptr_ol.M_Product_ID, v_Qty, ptr_ol.PriceList,
+                        ptr_ol.Description, ptr_ol.M_Product_ID,
+						v_Qty, 
+						ptr_ol.PriceList,
                         ptr_ol.PriceActual, ptr_ol.PriceLimit, C_Currency_Round(v_Qty*ptr_ol.PriceActual, Cur_Order.C_Currency_ID, NULL), ptr_ol.C_Charge_ID,
                         ptr_ol.ChargeAmt, ptr_ol.C_UOM_ID,
+			v_aum_qty, 
+			v_default_aum,
                         ptr_ol.C_Tax_ID,  --MODIFIED BY F.IRIAZABAL
                         v_QtyOrder, ptr_ol.M_Product_Uom_ID, ptr_ol.PriceStd,
                         ptr_ol.m_attributesetinstance_id, ptr_ol.taxbaseamt,
@@ -738,7 +769,16 @@
 												END IF;
 											END IF;
 	                  END IF;
-
+		    
+		    v_default_aum := CASE WHEN v_uom_preference = 'Y' AND ptr_sl.AUMQTY IS NULL AND ptr_sl.M_Product_Uom_ID IS NULL 
+					 THEN M_GET_DEFAULT_AUM_FOR_DOCUMENT(ptr_sl.M_Product_ID, '01360D369B5F473686354A701A6EA559') 
+					 ELSE ptr_sl.C_AUM 
+					 END;
+		    v_aum_qty := CASE WHEN v_uom_preference = 'Y' AND ptr_sl.AUMQTY IS NULL AND ptr_sl.M_Product_Uom_ID IS NULL 
+				     THEN M_GET_CONVERTED_AUMQTY(ptr_sl.M_Product_ID,ptr_sl.MovementQty,v_default_aum) 
+				     ELSE ptr_sl.AUMQTY 
+				     END;
+				
                     INSERT
                     INTO C_INVOICELINE
                       (
@@ -748,6 +788,7 @@
                         Description, M_Product_ID, QtyInvoiced, PriceList,
                         PriceActual, PriceLimit, LineNetAmt, C_Charge_ID,
                         ChargeAmt, C_UOM_ID,
+			AUMQTY, C_AUM,
                         C_Tax_ID,  --MODIFIED BY F.IRIAZABAL
                         QuantityOrder, M_Product_Uom_ID, PriceStd,
                         m_attributesetinstance_id, 
@@ -767,6 +808,7 @@
                         ptr_sl.Description, ptr_sl.M_Product_ID, ptr_sl.MovementQty, ptr_sl.PriceList,
                         ptr_sl.PriceActual, ptr_sl.PriceLimit, C_Currency_Round(ptr_sl.MovementQty*ptr_sl.PriceActual, Cur_Order.C_Currency_ID, NULL), ptr_sl.C_Charge_ID,
                         ptr_sl.ChargeAmt, ptr_sl.C_UOM_ID,
+			v_aum_qty, v_default_aum,
                         ptr_sl.C_Tax_ID,  --MODIFIED BY F.IRIAZABAL
                         ptr_sl.QuantityOrder, ptr_sl.M_Product_Uom_ID, ptr_sl.PriceStd,
                         ptr_sl.m_attributesetinstance_id,
@@ -916,6 +958,8 @@
                 sl.C_UOM_ID,
                 sl.MovementQty,
                 --MODIFIED BY F.IRIAZABAL
+		sl.AUMQTY,
+		sl.C_AUM,
                 sl.QuantityOrder,
                 sl.M_Product_UOM_ID,
                 COALESCE(ol.PriceList, 0) AS PriceList,
@@ -1293,6 +1337,16 @@
 										v_periodnumber_inv := NULL;
 									END IF;
                 END IF;
+
+                v_default_aum := CASE WHEN v_uom_preference = 'Y' AND Cur_InvoiceSchedule.AUMQTY IS NULL AND Cur_InvoiceSchedule.M_Product_Uom_ID IS NULL 
+					 THEN M_GET_DEFAULT_AUM_FOR_DOCUMENT(Cur_InvoiceSchedule.M_Product_ID, '01360D369B5F473686354A701A6EA559') 
+					 ELSE Cur_InvoiceSchedule.C_AUM 
+					 END;
+		v_aum_qty := CASE WHEN v_uom_preference = 'Y' AND Cur_InvoiceSchedule.AUMQTY IS NULL AND Cur_InvoiceSchedule.M_Product_Uom_ID IS NULL 
+				  THEN M_GET_CONVERTED_AUMQTY(Cur_InvoiceSchedule.M_Product_ID,Cur_InvoiceSchedule.MovementQty,v_default_aum) 
+				  ELSE Cur_InvoiceSchedule.AUMQTY 
+				  END;
+				     
                 INSERT
                 INTO C_INVOICELINE
                   (
@@ -1302,6 +1356,7 @@
                     Description, M_Product_ID, QtyInvoiced, PriceList,
                     PriceActual, PriceLimit, LineNetAmt, C_Charge_ID,
                     ChargeAmt, C_UOM_ID,
+		    AUMQTY, C_AUM,
                     C_Tax_ID,  --MODIFIED BY F.IRIAZABAL
                     QuantityOrder, M_Product_Uom_ID, PriceStd,
                     m_attributesetinstance_id, 
@@ -1321,6 +1376,7 @@
                     Cur_InvoiceSchedule.Line_Description, Cur_InvoiceSchedule.M_Product_ID, Cur_InvoiceSchedule.MovementQty, Cur_InvoiceSchedule.PriceList,
                     Cur_InvoiceSchedule.PriceActual, Cur_InvoiceSchedule.PriceLimit, C_Currency_Round(Cur_InvoiceSchedule.MovementQty*Cur_InvoiceSchedule.PriceActual, Cur_InvoiceSchedule.C_Currency_ID, NULL), Cur_InvoiceSchedule.Line_C_Charge_ID,
                     Cur_InvoiceSchedule.Line_ChargeAmt, Cur_InvoiceSchedule.C_UOM_ID,
+		    v_aum_qty, v_default_aum,
                     Cur_InvoiceSchedule.C_Tax_ID,  --MODIFIED BY F.IRIAZABAL
                     Cur_InvoiceSchedule.QuantityOrder, Cur_InvoiceSchedule.M_Product_Uom_ID, Cur_InvoiceSchedule.PriceStd,
                     Cur_InvoiceSchedule.m_attributesetinstance_id, 
--- a/src-db/database/model/functions/C_INVOICE_POST.xml	Fri Nov 11 10:01:28 2016 +0100
+++ b/src-db/database/model/functions/C_INVOICE_POST.xml	Fri Nov 11 10:06:34 2016 +0100
@@ -705,7 +705,8 @@
               gross_unit_price, line_gross_amount,
               isdeferred, defplantype, periodnumber, c_period_id,
               c_bpartner_id, c_project_id, c_projectline_id, a_asset_id,
-              user1_id, user2_id, c_costcenter_id)
+              user1_id, user2_id, c_costcenter_id,
+              C_AUM, AUMQTY)
             VALUES
             (
               v_NextNo, Cur_InvoiceLine.AD_Client_ID, Cur_InvoiceLine.AD_Org_ID, 'Y',
@@ -718,7 +719,8 @@
               Cur_InvoiceLine.gross_unit_price, Cur_InvoiceLine.line_gross_amount * -1,
               Cur_InvoiceLine.isdeferred, Cur_InvoiceLine.defplantype, Cur_InvoiceLine.periodnumber, Cur_InvoiceLine.c_period_id,
               Cur_InvoiceLine.c_bpartner_id, Cur_InvoiceLine.c_project_id, Cur_InvoiceLine.c_projectline_id, Cur_InvoiceLine.a_asset_id,
-              Cur_InvoiceLine.user1_id, Cur_InvoiceLine.user2_id, Cur_InvoiceLine.C_CostCenter_ID
+              Cur_InvoiceLine.user1_id, Cur_InvoiceLine.user2_id, Cur_InvoiceLine.C_CostCenter_ID,
+              Cur_InvoiceLine.C_AUM, Cur_InvoiceLine.AUMQTY
             );
           INSERT INTO M_MATCHINV
             (M_MATCHINV_ID, AD_CLIENT_ID, AD_ORG_ID, ISACTIVE, CREATED, CREATEDBY, UPDATED, UPDATEDBY,
@@ -1287,7 +1289,8 @@
            TAXAMT, M_ATTRIBUTESETINSTANCE_ID, ISDESCRIPTION,
            QUANTITYORDER, M_PRODUCT_UOM_ID, PRICESTD,
            GROSS_UNIT_PRICE, TAXBASEAMT, LINE_GROSS_AMOUNT,
-           ISDEFERRED, DEFPLANTYPE, PERIODNUMBER, C_PERIOD_ID
+           ISDEFERRED, DEFPLANTYPE, PERIODNUMBER, C_PERIOD_ID,
+           C_AUM, AUMQTY
           )
           VALUES
           (
@@ -1300,7 +1303,8 @@
            NULL, NULL, 'N' ,
            NULL, NULL, v_Discount,
            ROUND(v_gross_unit_price, v_precision), v_Discount  ,ROUND(v_line_gross_amount, v_precision),
-           v_isdeferred_inv, v_defplantype_inv, v_periodnumber_inv, v_period_inv
+           v_isdeferred_inv, v_defplantype_inv, v_periodnumber_inv, v_period_inv,
+           NULL, NULL
           );
         --v_InvoiceDiscount:=Ad_Sequence_Nextno('C_InvoiceLine');
         UPDATE C_INVOICELINE
--- a/src-db/database/model/functions/C_ORDER_POST1.xml	Fri Nov 11 10:01:28 2016 +0100
+++ b/src-db/database/model/functions/C_ORDER_POST1.xml	Fri Nov 11 10:06:34 2016 +0100
@@ -547,7 +547,7 @@
           FOR Cur_ResLine IN
             (SELECT l.M_Warehouse_ID, l.M_Product_ID, l.M_AttributeSetInstance_ID, l.C_OrderLine_ID,
                  l.QtyOrdered AS Qty, l.QUANTITYORDER, l.qtyreserved, l.qtydelivered,
-                l.C_UOM_ID, l.M_PRODUCT_UOM_ID
+                l.C_UOM_ID, l.M_PRODUCT_UOM_ID, C_AUM
              FROM C_ORDERLINE l, M_PRODUCT p
              WHERE l.C_Order_ID=v_Record_ID  -- Reserve Products (not: services, null products)
                AND l.M_Product_ID=p.M_Product_ID
@@ -563,7 +563,7 @@
               v_QtyOrderPO:=NULL;
               IF (Cur_ResLine.QtyDelivered=0) THEN
                 v_QtyOrderPO := -Cur_ResLine.QuantityOrder;
-              ELSIF Cur_ResLine.M_Product_UOM_ID IS NOT NULL THEN
+              ELSIF Cur_ResLine.C_AUM IS NULL AND Cur_ResLine.M_Product_UOM_ID IS NOT NULL THEN
                 SELECT c_uom_id
                 INTO v_UOM_ID
                 FROM m_product_uom
@@ -574,7 +574,7 @@
               v_QtySO:=-Cur_ResLine.QtyReserved;
               IF (Cur_ResLine.QtyReserved=Cur_ResLine.Qty) THEN
                 v_QtyOrderSO := -Cur_ResLine.QuantityOrder;
-              ELSIF Cur_ResLine.M_Product_UOM_ID IS NOT NULL THEN
+              ELSIF Cur_ResLine.C_AUM IS NULL AND Cur_ResLine.M_Product_UOM_ID IS NOT NULL THEN
                 SELECT c_uom_id
                 INTO v_UOM_ID
                 FROM m_product_uom
@@ -697,6 +697,7 @@
 	      M_Warehouse_ID,
 	      M_AttributeSetInstance_ID,
 	      C_UOM_ID,
+              C_AUM,
 	      M_PRODUCT_UOM_ID,
           C_Currency_ID
 	      FROM C_ORDERLINE
@@ -716,9 +717,9 @@
               INTO v_ProductUOM
               FROM M_PRODUCT_UOM UOM 
               WHERE UOM.M_PRODUCT_UOM_ID=Cur_Inventory.M_PRODUCT_UOM_ID;
-              v_QuantityOrder := CASE WHEN Cur_Inventory.M_PRODUCT_UOM_ID IS NULL THEN Cur_Inventory.QuantityOrder
-                                ELSE (c_uom_convert((CASE WHEN (Cur_Inventory.QtyDelivered < 0) THEN LEAST(Cur_Inventory.QtyDelivered, Cur_Inventory.QtyInvoiced) ELSE GREATEST(Cur_Inventory.QtyDelivered, Cur_Inventory.QtyInvoiced) END),
-                    Cur_Inventory.C_UOM_ID, v_ProductUOM,'Y')) END;
+              v_QuantityOrder := CASE WHEN Cur_Inventory.C_AUM IS NOT NULL OR (Cur_Inventory.C_AUM IS NULL AND Cur_Inventory.M_PRODUCT_UOM_ID IS NULL) THEN Cur_Inventory.QuantityOrder
+                                 ELSE (c_uom_convert((CASE WHEN (Cur_Inventory.QtyDelivered < 0) THEN LEAST(Cur_Inventory.QtyDelivered, Cur_Inventory.QtyInvoiced) ELSE GREATEST(Cur_Inventory.QtyDelivered, Cur_Inventory.QtyInvoiced) END), 
+              Cur_Inventory.C_UOM_ID, v_ProductUOM,'Y')) END;
 
               IF (Cur_Inventory.QtyOrdered <> v_QtyOrdered) THEN
                 M_UPDATE_STORAGE_PENDING(v_Client_ID, v_Org_ID, v_UpdatedBy, Cur_Inventory.M_Product_ID, Cur_Inventory.M_Warehouse_ID, Cur_Inventory.M_AttributeSetInstance_ID,
@@ -754,6 +755,7 @@
 	        M_Warehouse_ID,
 	        M_AttributeSetInstance_ID,
 	        C_UOM_ID,
+                C_AUM,
 	        M_PRODUCT_UOM_ID,
 	        C_Currency_ID
               FROM C_ORDERLINE
@@ -776,13 +778,14 @@
               v_QtyOrdered := COALESCE(CASE WHEN (Cur_Inventory.QtyDelivered < 0) THEN LEAST(Cur_Inventory.QtyDelivered, Cur_Inventory.QtyInvoiced) ELSE GREATEST(Cur_Inventory.QtyDelivered, Cur_Inventory.QtyInvoiced) END, 0);
               v_linenetamt := ROUND(COALESCE(v_QtyOrdered, 0) * Cur_Inventory.priceactual, C_GET_CURRENCY_PRECISION(Cur_Inventory.C_Currency_ID, 'A'));
               v_linegrossamt := ROUND(COALESCE(v_QtyOrdered, 0) * Cur_Inventory.gross_unit_price, C_GET_CURRENCY_PRECISION(Cur_Inventory.C_Currency_ID, 'A'));
+
               SELECT MAX(UOM.C_UOM_ID)
               INTO v_ProductUOM
               FROM M_PRODUCT_UOM UOM 
               WHERE UOM.M_PRODUCT_UOM_ID=Cur_Inventory.M_PRODUCT_UOM_ID;
-              v_QuantityOrder := CASE WHEN Cur_Inventory.M_PRODUCT_UOM_ID IS NULL THEN Cur_Inventory.QuantityOrder
-                                ELSE (COALESCE(c_uom_convert((CASE WHEN (Cur_Inventory.QtyDelivered < 0) THEN LEAST(Cur_Inventory.QtyDelivered, Cur_Inventory.QtyInvoiced) ELSE GREATEST(Cur_Inventory.QtyDelivered, Cur_Inventory.QtyInvoiced) END),
-                    Cur_Inventory.C_UOM_ID, v_ProductUOM,'Y'), 0)) END;
+              v_QuantityOrder := CASE WHEN Cur_Inventory.C_AUM IS NOT NULL OR (Cur_Inventory.C_AUM IS NULL AND Cur_Inventory.M_PRODUCT_UOM_ID IS NULL) THEN Cur_Inventory.QuantityOrder
+                                 ELSE (COALESCE(c_uom_convert((CASE WHEN (Cur_Inventory.QtyDelivered < 0) THEN LEAST(Cur_Inventory.QtyDelivered, Cur_Inventory.QtyInvoiced) ELSE GREATEST(Cur_Inventory.QtyDelivered, Cur_Inventory.QtyInvoiced) END),
+              Cur_Inventory.C_UOM_ID, v_ProductUOM,'Y'), 0)) END;
               IF (Cur_Inventory.QtyOrdered <> v_QtyOrdered) THEN
                 M_UPDATE_STORAGE_PENDING(v_Client_ID, v_Org_ID, v_UpdatedBy, Cur_Inventory.M_Product_ID, Cur_Inventory.M_Warehouse_ID, Cur_Inventory.M_AttributeSetInstance_ID,
                 Cur_Inventory.C_UOM_ID, Cur_Inventory.M_PRODUCT_UOM_ID, 0, null, -(Cur_Inventory.QtyOrdered - v_QtyOrdered), -(Cur_Inventory.QuantityOrder - v_QuantityOrder));
@@ -824,7 +827,7 @@
         UPDATE C_ORDERLINE
           SET QtyOrdered=0,
           --MODIFIED BY F.IRIAZABAL
-          QuantityOrder = CASE WHEN M_PRODUCT_UOM_ID IS NULL THEN NULL ELSE 0 END,
+          QuantityOrder = CASE WHEN C_AUM IS NOT NULL OR (C_AUM IS NULL AND M_PRODUCT_UOM_ID IS NULL) THEN NULL ELSE 0 END,
           LineNetAmt=0,
           Updated=now()
         WHERE C_Order_ID=v_Record_ID
@@ -999,7 +1002,7 @@
                   qtyreserved, qtydelivered, qtyinvoiced, m_shipper_id, c_currency_id,
                   pricelist, priceactual, pricelimit, linenetamt, discount, freightamt,
                   c_charge_id, chargeamt, c_tax_id, s_resourceassignment_id, ref_orderline_id,
-                  m_attributesetinstance_id, isdescription, quantityorder, m_product_uom_id,
+                  m_attributesetinstance_id, isdescription, quantityorder, m_product_uom_id, aumqty, c_aum,
                   m_offer_id, pricestd, C_ORDER_DISCOUNT_ID,
                   gross_unit_price, taxbaseamt,line_gross_amount
                 )
@@ -1012,7 +1015,7 @@
                   0, 0, 0, NULL, v_c_currency_id,
                   ROUND(v_Discount,v_precision), ROUND(v_Discount,v_precision), ROUND(v_Discount,v_precision), ROUND(v_Discount,v_precision), 0, 0,
                   NULL, NULL, Cur_TaxDiscount.C_TAX_ID, NULL, NULL,
-                  NULL, 'N', NULL, NULL,
+                  NULL, 'N', NULL, NULL, NULL, NULL,
                   NULL, ROUND(v_Discount,v_precision), NULL,
                   ROUND(v_gross_unit_price, v_precision), ROUND(v_Discount,v_precision),ROUND(v_line_gross_amount, v_precision)
                 );
@@ -1150,7 +1153,7 @@
                 -- Target Level = 0 if DirectShip='Y' or Binding='N'
                 (CASE l.DirectShip WHEN 'Y' THEN 0 ELSE (CASE v_IsBinding WHEN 'N' THEN 0 ELSE l.QtyOrdered END) END)
                  -l.QtyReserved-l.QtyDelivered AS Qty, l.QUANTITYORDER,
-                l.QtyReserved, l.QtyDelivered, l.DatePromised, l.C_UOM_ID,
+                l.QtyReserved, l.QtyDelivered, l.DatePromised, l.C_UOM_ID, l.C_AUM,
                 l.M_PRODUCT_UOM_ID
               FROM C_ORDERLINE l, M_PRODUCT p
               WHERE l.C_Order_ID=v_Record_ID
@@ -1168,7 +1171,7 @@
               v_QtyOrderSO := NULL;
               IF (Cur_ResLine.QtyReserved = 0 AND Cur_ResLine.QtyDelivered = 0) THEN
                 v_QtyOrderSO := Cur_ResLine.QuantityOrder;
-              ELSIF (Cur_ResLine.M_Product_UOM_ID IS NOT NULL) THEN
+              ELSIF (Cur_ResLine.C_AUM IS NULL AND Cur_ResLine.M_Product_UOM_ID IS NOT NULL) THEN
                 SELECT c_uom_id
                 INTO v_UOM_ID
                 FROM m_product_uom
@@ -1184,7 +1187,7 @@
               v_QtyOrderPO := NULL;
               IF (Cur_ResLine.QtyReserved = 0 AND Cur_ResLine.QtyDelivered = 0) THEN
                 v_QtyOrderPO := Cur_ResLine.QuantityOrder;
-              ELSIF (Cur_ResLine.M_Product_UOM_ID IS NOT NULL) THEN
+              ELSIF (Cur_ResLine.C_AUM IS NULL AND Cur_ResLine.M_Product_UOM_ID IS NOT NULL) THEN
                 SELECT c_uom_id
                 INTO v_UOM_ID
                 FROM m_product_uom
--- a/src-db/database/model/functions/M_COPY_PRODUCT_TEMPLATE.xml	Fri Nov 11 10:01:28 2016 +0100
+++ b/src-db/database/model/functions/M_COPY_PRODUCT_TEMPLATE.xml	Fri Nov 11 10:06:34 2016 +0100
@@ -49,6 +49,8 @@
     v_Issotrx CHAR;
     v_NoOfLines NUMBER:=0;
     v_projectID varchar2(32);
+    v_doctypeID varchar2(32);
+    v_aum varchar2(32);
     -- Copy
     Cur_ProductTemplate RECORD;
   BEGIN
@@ -78,10 +80,10 @@
     v_ResultStr:='ReadingOrder';
     SELECT AD_CLIENT_ID, AD_ORG_ID, CREATEDBY, DATEORDERED,
       C_BPARTNER_ID, BILLTO_ID, C_BPARTNER_LOCATION_ID, C_CURRENCY_ID,
-      M_WAREHOUSE_ID, M_PRICELIST_ID, C_PROJECT_ID, ISSOTRX
+      M_WAREHOUSE_ID, M_PRICELIST_ID, C_PROJECT_ID, ISSOTRX, C_DOCTYPE_ID
     INTO v_client, v_org, v_Createdby, v_Dateordered,
       v_Bpartner, v_BillTo, v_BpartnerLocation, v_Currency,
-      v_Warehouse, v_Mpricelist, v_projectID, v_Issotrx
+      v_Warehouse, v_Mpricelist, v_projectID, v_Issotrx, v_doctypeID
     FROM C_ORDER
     WHERE C_Order_ID=v_Record_ID;
     SELECT COALESCE(MAX(C_ORDERLINE.line), 10)
@@ -126,6 +128,10 @@
       INTO v_tax
       FROM DUAL;
       v_Discount:=(v_Pricelist - v_Pricestd) /v_Pricelist;
+      
+      --Get Default AUM
+      v_aum := M_GET_DEFAULT_AUM_FOR_DOCUMENT(Cur_ProductTemplate.M_PRODUCT_ID, v_DocTypeID);
+
       -- Get next no
       Ad_Sequence_Next('C_OrderLine', v_client, v_CorderId) ;
       -- Insert
@@ -143,7 +149,7 @@
           FREIGHTAMT, C_CHARGE_ID, CHARGEAMT, C_TAX_ID,
           S_RESOURCEASSIGNMENT_ID, REF_ORDERLINE_ID,
           M_ATTRIBUTESETINSTANCE_ID, ISDESCRIPTION, QUANTITYORDER, M_PRODUCT_UOM_ID,
-          PriceStd
+          PriceStd, c_aum, aumqty
         )
         VALUES
         (
@@ -158,7 +164,7 @@
           0, NULL, 0, v_tax,
           NULL, NULL,
           NULL, 'N', NULL, NULL,
-          v_Pricestd
+          v_Pricestd, v_aum, 0
         )
         ;
       -- update translation
--- a/src-db/database/model/functions/M_EXPLODEBOMNOTSTOCK.xml	Fri Nov 11 10:01:28 2016 +0100
+++ b/src-db/database/model/functions/M_EXPLODEBOMNOTSTOCK.xml	Fri Nov 11 10:06:34 2016 +0100
@@ -48,6 +48,10 @@
   v_istaxincluded CHAR(1);
   v_BaseAmount  VARCHAR2(32);
   v_orderline_ID  VARCHAR2(32);
+  v_aum  VARCHAR2(32);
+  v_aumqty NUMBER;
+  v_count NUMBER;
+  v_uom_preference CHAR(1);
   
   BEGIN
   IF (p_PInstance_ID IS NOT NULL) THEN
@@ -107,7 +111,7 @@
     -- Replace Lines
     v_ResultStr:='Inserting lines';
     For Cur_Bom_Line In
-      (SELECT l.*,o.M_Warehouse_ID as ord_m_warehouse_id,o.C_BPartner_Location_ID as ord_C_BPartner_Location_ID,o.issotrx
+      (SELECT l.*,o.M_Warehouse_ID as ord_m_warehouse_id,o.C_BPartner_Location_ID as ord_C_BPartner_Location_ID,o.issotrx, o.c_doctypetarget_id as ord_c_doctype_id
        FROM C_ORDERLINE l,c_order o
        WHERE l.C_Orderline_ID=v_Record_ID
          AND l.c_order_id=o.c_order_id
@@ -153,7 +157,23 @@
 					v_price_actual:=M_Get_Offers_Price(CUR_BOM_Line.DateOrdered, v_CBPartner_ID, CUR_BOM.M_ProductBOM_ID, M_BOM_PriceStd(CUR_BOM.M_ProductBOM_ID, v_PriceList_Version_ID), CUR_BOM_Line.QtyInvoiced*CUR_BOM.BOMQty, v_PriceList_ID);
 					v_line_net_amt:=ROUND(CUR_BOM_Line.QtyOrdered*CUR_BOM.BOMQty*v_gross_unit_price, v_Precision);
 				END IF;
-
+				
+        -- Get AUM
+        SELECT COUNT(1) INTO v_count
+        FROM ad_preference
+        WHERE property = 'UomManagement';
+      
+        IF (v_count > 0) THEN
+          v_uom_preference := AD_GET_PREFERENCE_VALUE('UomManagement', 'Y', CUR_BOM_Line.ad_client_id, CUR_BOM_Line.ad_org_id, CUR_BOM_Line.createdby, NULL, NULL);
+        END IF;
+      
+        v_Aum := NULL;
+        v_AumQty := NULL;
+        IF (v_uom_preference = 'Y') THEN
+          v_aum := M_GET_DEFAULT_AUM_FOR_DOCUMENT(CUR_BOM.M_ProductBOM_ID, CUR_BOM_Line.ord_c_doctype_id);
+          v_aumqty := M_GET_CONVERTED_QTY(CUR_BOM.M_ProductBOM_ID, CUR_BOM_Line.QtyOrdered, v_aum); 
+        END IF;
+      
         v_Line:=v_Line + 1;
         v_orderline_ID:=get_uuid();
         INSERT
@@ -172,7 +192,8 @@
             QuantityOrder, M_Product_Uom_ID, PriceStd,
             c_project_id, a_asset_id, c_costcenter_id,
             user1_id, user2_id, bom_parent_id,
-            gross_unit_price, grosspricelist, line_gross_amount
+            gross_unit_price, grosspricelist, line_gross_amount,
+            c_aum, aumqty
           )
         VALUES
           (
@@ -190,7 +211,7 @@
             CUR_BOM_Line.QuantityOrder, CUR_BOM_Line.M_Product_UOM_ID, M_BOM_PriceStd(CUR_BOM.M_ProductBOM_ID, v_PriceList_Version_ID),
             CUR_BOM_Line.c_project_id, CUR_BOM_Line.a_asset_id, CUR_BOM_Line.c_costcenter_id,
             CUR_BOM_Line.user1_id, CUR_BOM_Line.user2_id, v_Record_ID,
-            v_gross_unit_price, v_gross_price_list, v_line_gross_amount
+            v_gross_unit_price, v_gross_price_list, v_line_gross_amount, v_aum, v_aumqty*CUR_BOM.BOMQty
           );
           SELECT BASEAMOUNT
           INTO v_BaseAmount
--- a/src-db/database/model/functions/M_INOUTEXPLODEBOMNOTSTOCK.xml	Fri Nov 11 10:01:28 2016 +0100
+++ b/src-db/database/model/functions/M_INOUTEXPLODEBOMNOTSTOCK.xml	Fri Nov 11 10:06:34 2016 +0100
@@ -35,6 +35,11 @@
   v_Line NUMBER:=0;
   v_ResultStr VARCHAR2(2000):='';
   v_result NUMBER:= 1;  
+    v_aum  VARCHAR2(32);
+  v_aumqty NUMBER;
+  v_count NUMBER;
+  v_uom_preference CHAR(1);
+  
   BEGIN
   IF (p_PInstance_ID IS NOT NULL) THEN
       --  Update AD_PInstance
@@ -77,10 +82,11 @@
     -- Replace Lines
     v_ResultStr:='Inserting lines';
     FOR CUR_BOM_Line IN
-      (SELECT *
+      (SELECT l.*, i.c_doctype_id as io_c_doctype_id
        FROM M_INOUTLINE l
+       JOIN M_INOUT i USING (m_inout_id)
        WHERE l.m_inoutline_ID=v_Record_ID
-         AND IsActive='Y'
+         AND l.IsActive='Y'
          AND EXISTS
            (SELECT *
             FROM M_PRODUCT p
@@ -102,6 +108,23 @@
          ORDER BY Line
          )
       LOOP
+
+        -- Get AUM
+        SELECT COUNT(1) INTO v_count
+        FROM ad_preference
+        WHERE property = 'UomManagement';
+      
+        IF (v_count > 0) THEN
+          v_uom_preference := AD_GET_PREFERENCE_VALUE('UomManagement', 'Y', CUR_BOM_Line.ad_client_id, CUR_BOM_Line.ad_org_id, CUR_BOM_Line.createdby, NULL, NULL);
+        END IF;
+      
+        v_Aum := NULL;
+        v_AumQty := NULL;
+        IF (v_uom_preference = 'Y') THEN
+          v_aum := M_GET_DEFAULT_AUM_FOR_DOCUMENT(CUR_BOM.M_ProductBOM_ID, CUR_BOM_Line.io_c_doctype_id);
+          v_aumqty := M_GET_CONVERTED_QTY(CUR_BOM.M_ProductBOM_ID, CUR_BOM_Line.movementqty, v_aum); 
+        END IF;      
+
         v_Line:=v_Line + 1;
         INSERT
         INTO M_INOUTLINE
@@ -112,7 +135,8 @@
             C_UOM_ID,MovementQty,
             IsInvoiced, QuantityOrder, M_PRODUCT_UOM_ID,
             A_ASSET_ID, C_PROJECT_ID, C_COSTCENTER_ID,
-            USER1_ID, USER2_ID, C_BPARTNER_ID, bom_parent_id
+            USER1_ID, USER2_ID, C_BPARTNER_ID, bom_parent_id,
+            c_aum, aumqty
           )
         VALUES
           (
@@ -122,7 +146,8 @@
             CUR_BOM.C_UOM_ID, CUR_BOM_Line.MovementQty*CUR_BOM.BOMQty, 
             'N', CUR_BOM_Line.QuantityOrder, CUR_BOM_Line.M_Product_UOM_ID,
             CUR_BOM_Line.a_asset_id, CUR_BOM_Line.c_project_id, CUR_BOM_Line.c_costcenter_id,
-            CUR_BOM_Line.user1_id, CUR_BOM_Line.user2_id, CUR_BOM_Line.C_BPartner_ID, v_Record_ID
+            CUR_BOM_Line.user1_id, CUR_BOM_Line.user2_id, CUR_BOM_Line.C_BPartner_ID, v_Record_ID, 
+            v_aum, v_aumqty*CUR_BOM.BOMQty
           );
       END LOOP; -- Create New Lines
     END LOOP; -- Replace Lines
--- a/src-db/database/model/functions/M_INOUT_CREATE.xml	Fri Nov 11 10:01:28 2016 +0100
+++ b/src-db/database/model/functions/M_INOUT_CREATE.xml	Fri Nov 11 10:06:34 2016 +0100
@@ -85,14 +85,14 @@
       l.M_Product_ID IS NULL)) -- Don't include Direct Ship's
       AND
       DirectShip='N' 
-    ORDER BY l.line, l.M_Product_ID, l.M_Warehouse_id, l.c_uom_id, l.m_attributesetinstance_id, 
+    ORDER BY l.line, l.M_Product_ID, l.M_Warehouse_id, l.c_uom_id, l.c_aum, l.m_attributesetinstance_id, 
       l.m_product_uom_id, qtyordered-qtydelivered;
     ol Cur_OrderLine%ROWTYPE;
     CURSOR Cur_Storage (v_ad_pinstance_id varchar, v_inout_id varchar) IS
       SELECT sd.m_product_id, sd.m_locator_id, sd.m_attributesetinstance_id,
           sd.c_uom_id, sd.m_product_uom_id, u.stdprecision,
           ms.quantity - COALESCE(SUM(iol.movementqty), 0) AS qtyonhand, ms.qtyorder AS qtyorder,
-          ms.priority
+          ms.priority, iol.c_aum, iol.aumqty
       FROM m_stock_proposed ms 
             LEFT JOIN m_storage_detail sd ON ms.m_storage_detail_id = sd.m_storage_detail_id
             LEFT JOIN m_product_uom pu ON sd.m_product_uom_id = pu.m_product_uom_id
@@ -105,7 +105,7 @@
                                          AND iol.m_inout_id = v_inout_id
       WHERE ms.ad_pinstance_id = v_ad_pinstance_id
       GROUP BY sd.m_product_id, sd.m_locator_id, sd.m_attributesetinstance_id, sd.c_uom_id,
-          sd.m_product_uom_id, u.stdprecision, ms.quantity, ms.qtyorder, ms.priority
+          sd.m_product_uom_id, u.stdprecision, ms.quantity, ms.qtyorder, ms.priority, iol.c_aum, iol.aumqty
       HAVING ms.quantity - COALESCE(SUM(iol.movementqty), 0) > 0
       ORDER BY ms.priority;
 
@@ -148,6 +148,9 @@
   v_DeliveryRule CHAR(1);
   v_isreturn C_Doctype.IsReturn%TYPE;
   v_returnbin M_Warehouse.M_ReturnLocator_ID%TYPE;
+  v_uom_preference VARCHAR(1);
+  v_c_aum VARCHAR2(32);
+  v_aumqty NUMBER;
 
 BEGIN
   -- Process Parameters
@@ -208,6 +211,13 @@
     AND c_order_id = v_record_id;
   END IF;
 BEGIN --BODY
+
+  -- Get UOMPreference value
+  SELECT COUNT(1) INTO v_count FROM ad_preference WHERE property = 'UomManagement';
+  IF (v_count > 0) THEN
+    v_uom_preference := AD_GET_PREFERENCE_VALUE('UomManagement', 'Y', NULL, v_AD_Org_ID, v_User_ID, NULL, NULL);
+  END IF;
+
   IF(NOT CREATE_FROM_INVOICE) THEN
     -- May be NULL or 0
     IF(v_Record_ID IS NULL) THEN
@@ -454,6 +464,7 @@
             IF (v_Qty=0 AND ol.M_Product_ID IS NOT NULL) THEN
               Next_Line:=true;
             END IF;
+
             IF (NOT Next_Line) THEN
               -- Is it a standard stocked product?
               v_isstocked := 0;
@@ -464,6 +475,7 @@
                   AND IsStocked='Y'
                   AND ProductType='I';
               END IF;
+
               -- Item is stocked - check availability
               IF (v_IsStocked <> 0) THEN
                 -- check every locator availability and if qty available
@@ -524,6 +536,7 @@
                   CLOSE Cur_Storage;
                   Cur_Storage_ISOPEN:=false;
                 END IF;
+
                 IF (NOT NEXT_PRODUCT) THEN
                   v_QtyStorage:=v_storage.QtyOnHand;
                   LOOP
@@ -539,12 +552,28 @@
                     IF (v_storage.M_Product_UOM_ID IS NOT NULL) THEN
                       v_ActualQty:=ROUND(v_storage.QtyOrder*(v_LocatorQty/v_storage.QtyOnHand), v_storage.stdprecision) ;
                     END IF;
+
                     IF (v_LocatorQty <> 0) THEN
                       -- Create InOut Line
                       Ad_Sequence_Next('M_InOutLine', Cur_Order.C_Order_ID, v_NextNo) ;
                       --
                       DBMS_OUTPUT.PUT_LINE('    Line ' || ol.Line || '  Qty=' || v_LocatorQty) ;
                       v_ResultStr:='CreateInOutLine';
+
+                      v_aumqty := v_storage.aumqty;
+                      v_c_aum := v_storage.c_aum;
+
+                      IF (v_uom_preference = 'Y' AND v_storage.M_Product_UOM_ID IS NULL) THEN
+                        IF (v_storage.c_aum IS NULL AND v_storage.aumqty IS NULL) THEN
+                          IF (ol.c_aum IS NULL) THEN
+                            v_c_aum := M_GET_DEFAULT_AUM_FOR_DOCUMENT(ol.M_Product_ID, v_DocType_ID);
+                          ELSE
+                            v_c_aum := ol.c_aum;
+                          END IF;
+                          v_aumqty := M_GET_CONVERTED_AUMQTY(ol.M_Product_ID, v_LocatorQty, v_c_aum);
+                        END IF;
+                      END IF;
+
                       INSERT INTO M_INOUTLINE
                         (M_InOutLine_ID, Line, M_InOut_ID, C_OrderLine_ID,
                         AD_Client_ID, AD_Org_ID, IsActive, Created,
@@ -555,7 +584,8 @@
                         QuantityOrder, M_Product_Uom_ID, M_AttributeSetInstance_ID,
                         C_Project_ID, A_Asset_ID, 
                         C_CostCenter_ID, User1_ID, User2_ID, 
-                        explode, bom_parent_id)
+                        explode, bom_parent_id,
+                        c_aum, aumqty)
                       VALUES
                         (v_NextNo, v_lines, p_InOut_ID, ol.C_OrderLine_ID,
                         ol.AD_Client_ID, ol.AD_Org_ID, 'Y', now(),
@@ -569,7 +599,8 @@
                         ol.explode, (select m_inoutline_id 
                                      from m_inoutline 
                                      where m_inout_id = p_InOut_ID
-                                       and c_orderline_id = (SELECT BOM_parent_id from c_orderline WHERE c_orderline_id = ol.C_OrderLine_ID)));
+                                       and c_orderline_id = (SELECT BOM_parent_id from c_orderline WHERE c_orderline_id = ol.C_OrderLine_ID)),
+                        v_c_aum, v_aumqty);
                       v_lines:=v_lines + 10;
                       v_lines_per_orderline:= v_lines_per_orderline + 10;
                       DBMS_OUTPUT.PUT_LINE('v_lines' || v_lines) ;
@@ -608,6 +639,16 @@
 
                   DBMS_OUTPUT.PUT_LINE('    Line ' || ol.Line || '  Qty=' || v_LocatorQty) ;
                   v_ResultStr:='CreateInOutLine';
+
+                  v_aumqty := ol.aumqty;
+                  v_c_aum := ol.c_aum;
+                  IF (v_uom_preference = 'Y' AND ol.M_PRODUCT_UOM_ID IS NULL) THEN
+                    IF (ol.c_aum IS NULL AND ol.aumqty IS NULL) THEN
+                      v_c_aum := M_GET_DEFAULT_AUM_FOR_DOCUMENT(ol.M_Product_ID, v_DocType_ID);
+                      v_aumqty := M_GET_CONVERTED_AUMQTY(ol.M_Product_ID, v_Qty, v_c_aum);
+                    END IF;
+                  END IF;
+
                   INSERT INTO M_INOUTLINE
                     (M_InOutLine_ID, Line, M_InOut_ID, C_OrderLine_ID,
                     AD_Client_ID, AD_Org_ID, IsActive, Created,
@@ -618,7 +659,8 @@
                     QuantityOrder, M_Product_Uom_ID, M_AttributeSetInstance_ID,
                     C_Project_ID, A_Asset_ID, 
                     C_CostCenter_ID, User1_ID, User2_ID,
-                    explode, bom_parent_id)
+                    explode, bom_parent_id,
+                    c_aum, aumqty)
                   VALUES
                     (v_NextNo, v_lines, p_InOut_ID, ol.C_OrderLine_ID,
                     ol.AD_Client_ID, ol.AD_Org_ID, 'Y', now(),
@@ -632,7 +674,8 @@
                     ol.explode, (select m_inoutline_id 
                                      from m_inoutline 
                                      where m_inout_id = p_InOut_ID
-                                       and c_orderline_id = (SELECT BOM_parent_id from c_orderline WHERE c_orderline_id = ol.C_OrderLine_ID)));
+                                       and c_orderline_id = (SELECT BOM_parent_id from c_orderline WHERE c_orderline_id = ol.C_OrderLine_ID)),
+                    v_c_aum, v_aumqty);
                   v_lines:=v_lines + 10;
                 ELSIF (v_qty <> 0) THEN
                   IF (v_DeliveryRule = 'O') THEN
@@ -670,6 +713,16 @@
                 --
                 DBMS_OUTPUT.PUT_LINE('    Line* ' || ol.Line || '  Qty=' || v_Qty) ;
                 v_ResultStr:='CreateInOutLine*2 '||ol.c_order_id||'-'||ol.line||'-'||ol.m_product_id;
+
+                v_aumqty := ol.aumqty;
+                v_c_aum := ol.c_aum;
+                IF (v_uom_preference = 'Y' AND ol.M_PRODUCT_UOM_ID IS NULL) THEN
+                  IF (ol.c_aum IS NULL AND ol.aumqty IS NULL) THEN
+                    v_c_aum := M_GET_DEFAULT_AUM_FOR_DOCUMENT(ol.M_Product_ID, v_DocType_ID);
+                    v_aumqty := M_GET_CONVERTED_AUMQTY(ol.M_Product_ID, v_Qty, v_c_aum);
+                  END IF;
+                END IF;
+
                 INSERT INTO M_INOUTLINE
                   (M_InOutLine_ID, Line, M_InOut_ID, C_OrderLine_ID,
                   AD_Client_ID, AD_Org_ID, IsActive, Created,
@@ -680,7 +733,8 @@
                   QuantityOrder, M_Product_Uom_ID, M_AttributeSetInstance_ID,
                   C_Project_ID, A_Asset_ID, 
                   C_CostCenter_ID, User1_ID, User2_ID, 
-                  explode, bom_parent_id)
+                  explode, bom_parent_id,
+                  c_aum, aumqty)
                 VALUES
                   (v_NextNo, v_lines, p_InOut_ID, ol.C_OrderLine_ID,
                   ol.AD_Client_ID, ol.AD_Org_ID, 'Y', now(),
@@ -694,7 +748,8 @@
                   ol.explode, (select m_inoutline_id 
                                      from m_inoutline 
                                      where m_inout_id = p_InOut_ID
-                                       and c_orderline_id = (SELECT BOM_parent_id from c_orderline WHERE c_orderline_id = ol.C_OrderLine_ID)));
+                                       and c_orderline_id = (SELECT BOM_parent_id from c_orderline WHERE c_orderline_id = ol.C_OrderLine_ID)),
+                  v_c_aum, v_aumqty);
                 v_lines:=v_lines + 10;
               END IF;
             END IF;--Next_Line
@@ -888,6 +943,16 @@
           Ad_Sequence_Next('M_InOutLine', Cur_Invoice.C_Invoice_ID, v_NextNo) ;
           DBMS_OUTPUT.PUT_LINE('    Line* ' || Cur_Lines.Line) ;
           v_ResultStr:='CreateInOutLine*3';
+
+           v_aumqty := Cur_Lines.aumqty;
+          v_c_aum := Cur_Lines.c_aum;
+          IF (v_uom_preference = 'Y' AND Cur_Lines.M_Product_Uom_ID IS NULL) THEN
+            IF (Cur_Lines.c_aum IS NULL AND Cur_Lines.aumqty IS NULL) THEN
+              v_c_aum := M_GET_DEFAULT_AUM_FOR_DOCUMENT(Cur_Lines.M_Product_ID, v_DocType_ID);
+              v_aumqty := M_GET_CONVERTED_AUMQTY(Cur_Lines.M_Product_ID, Cur_Lines.QtyInvoiced, v_c_aum);
+            END IF;
+          END IF;
+
           INSERT INTO M_INOUTLINE (
             M_InOutLine_ID, Line, M_InOut_ID, C_OrderLine_ID,
             AD_Client_ID, AD_Org_ID, IsActive, Created,
@@ -898,7 +963,8 @@
             QuantityOrder, M_Product_Uom_ID, M_AttributeSetInstance_ID,
             C_Project_ID, A_Asset_ID, 
             C_CostCenter_ID, User1_ID,
-            User2_ID, explode, bom_parent_id
+            User2_ID, explode, bom_parent_id,
+            c_aum, aumqty
           ) VALUES (
             v_NextNo, Cur_Lines.Line, p_InOut_ID, Cur_Lines.C_OrderLine_ID,
             Cur_Lines.AD_Client_ID, Cur_Lines.AD_Org_ID, 'Y', now(),
@@ -912,7 +978,8 @@
             coalesce(Cur_Lines.User2_ID, Cur_Invoice.User2_ID), Cur_Lines.explode, (select m_inoutline_id 
                                      from c_invoiceline
                                      where c_invoice_id = Cur_Lines.C_Invoice_ID
-                                       and c_invoiceline_id = Cur_Lines.BOM_parent_id));
+                                       and c_invoiceline_id = Cur_Lines.BOM_parent_id),
+            v_c_aum, v_aumqty);
           UPDATE C_INVOICELINE
           SET M_INOUTLINE_ID=v_NextNo,
               Updated=now(),
--- a/src-db/database/model/functions/M_INOUT_CREATEINVOICE.xml	Fri Nov 11 10:01:28 2016 +0100
+++ b/src-db/database/model/functions/M_INOUT_CREATEINVOICE.xml	Fri Nov 11 10:06:34 2016 +0100
@@ -362,7 +362,8 @@
                 gross_unit_price, line_gross_amount,
                 grosspricestd, grosspricelist,
                 isdeferred, defplantype, periodnumber, c_period_id,
-                c_project_id, user1_id, user2_id, c_costcenter_id, a_asset_id
+                c_project_id, user1_id, user2_id, c_costcenter_id, a_asset_id,
+                c_aum, aumqty
               )
               VALUES
               (
@@ -381,7 +382,8 @@
                 coalesce(CUR_ShipmentLines.user1_id, CUR_Shipment.user1_id),
                 coalesce(CUR_ShipmentLines.user2_id, CUR_Shipment.user2_id),
                 coalesce(CUR_ShipmentLines.c_costcenter_id, CUR_Shipment.c_costcenter_id),
-                coalesce(CUR_ShipmentLines.a_asset_id, CUR_Shipment.a_asset_id)
+                coalesce(CUR_ShipmentLines.a_asset_id, CUR_Shipment.a_asset_id),
+                CUR_ShipmentLines.c_aum, CUR_ShipmentLines.aumqty
               )
               ;
             v_TotalNet:=v_TotalNet + v_LineNetAmt;
--- a/src-db/database/model/functions/M_INOUT_POST.xml	Fri Nov 11 10:01:28 2016 +0100
+++ b/src-db/database/model/functions/M_INOUT_POST.xml	Fri Nov 11 10:06:34 2016 +0100
@@ -1082,7 +1082,8 @@
                 QuantityOrder, M_Product_UOM_ID, IsDescription,
                 canceled_inoutline_id, A_Asset_ID, C_Project_ID, C_BPartner_ID,
                 User1_ID, User2_ID, C_CostCenter_ID, 
-                explode
+                explode,
+                C_AUM, AUMQTY
               )
               VALUES
               (
@@ -1094,7 +1095,8 @@
                 Cur_InOutLine.QuantityOrder * -1, Cur_InOutLine.M_PRODUCT_UOM_ID, Cur_InOutLine.IsDescription,
                 Cur_InOutLine.M_InOutLine_ID, Cur_InOutLine.A_Asset_ID, Cur_InOutLine.C_Project_ID, Cur_InOutLine.C_BPartner_ID,
                 Cur_InOutLine.User1_ID, Cur_InOutLine.User2_ID, Cur_InOutLine.C_CostCenter_ID, 
-                Cur_InOutLine.explode 
+                Cur_InOutLine.explode ,
+                Cur_InOutLine.C_AUM, Cur_InOutLine.AUMQTY
               )
               ;
 
--- a/src-db/database/model/functions/M_REQUISITION_CREATEPO.xml	Fri Nov 11 10:01:28 2016 +0100
+++ b/src-db/database/model/functions/M_REQUISITION_CREATEPO.xml	Fri Nov 11 10:06:34 2016 +0100
@@ -61,6 +61,12 @@
   p_PriceList_ID VARCHAR2(32);
   p_Org_ID VARCHAR2(32);
   p_Warehouse_ID VARCHAR2(32);
+
+  v_UomManagement_Pref VARCHAR2(60);
+  v_Aum VARCHAR2(32);
+  v_AumQty NUMBER;
+  v_uom_preference VARCHAR(1);
+  v_count NUMBER;
   
   --  Parameter
   TYPE RECORD IS REF CURSOR;
@@ -277,6 +283,20 @@
         END IF;
       END IF;
 
+      SELECT COUNT(1) INTO v_count
+      FROM ad_preference
+      WHERE property = 'UomManagement';
+      IF (v_count > 0) THEN
+        v_uom_preference := AD_GET_PREFERENCE_VALUE('UomManagement', 'Y', v_client_ID, p_org_ID, v_User_ID, NULL, NULL);
+      END IF;
+
+      v_Aum := NULL;
+      v_AumQty := NULL;
+      IF (v_uom_preference = 'Y') THEN
+        v_Aum := Cur_Lines.c_aum;
+        v_AumQty := Cur_Lines.aumqty;
+      END IF;
+
       v_Description := COALESCE(Cur_Lines.DESCRIPTION, '');
       IF (Cur_Lines.SUPPLIERNOTES IS NOT NULL) THEN
         v_Description := v_Description || ' ' || Cur_Lines.SUPPLIERNOTES;
@@ -291,7 +311,8 @@
           M_WAREHOUSE_ID, C_UOM_ID, QTYORDERED, C_CURRENCY_ID,
           PRICELIST, PRICEACTUAL, PRICELIMIT,
           PRICESTD, LINENETAMT, DISCOUNT,
-          C_TAX_ID, M_PRODUCT_UOM_ID, QUANTITYORDER, GROSS_UNIT_PRICE, LINE_GROSS_AMOUNT
+          C_TAX_ID, M_PRODUCT_UOM_ID, QUANTITYORDER, GROSS_UNIT_PRICE, LINE_GROSS_AMOUNT,
+          C_AUM, AUMQTY
       ) VALUES (
           v_COrderLine_ID,v_Client_ID, p_Org_ID,'Y',
           now(), v_User_ID, now(), v_User_ID,
@@ -301,7 +322,8 @@
           p_Warehouse_ID, Cur_Lines.C_UOM_ID, Cur_Lines.QTY - Cur_Lines.ORDEREDQTY, v_Currency_ID,
           v_PriceList, v_PriceActual, v_PriceLimit,
           v_PriceStd, v_LineNetAmt,v_Discount,
-          v_Tax_ID, Cur_Lines.M_Product_UOM_ID, Cur_Lines.QuantityOrder, v_gross_unit_price, v_line_gross_amount
+          v_Tax_ID, Cur_Lines.M_Product_UOM_ID, Cur_Lines.QuantityOrder, v_gross_unit_price, v_line_gross_amount,
+          v_Aum, v_AumQty
       );
 
       Ad_Sequence_Next('M_RequisitionOrder', v_User_ID, v_RequisitionOrder_ID);
--- a/src-db/database/model/triggers/C_INVLINE_CHK_RESTRICTIONS_TRG.xml	Fri Nov 11 10:01:28 2016 +0100
+++ b/src-db/database/model/triggers/C_INVLINE_CHK_RESTRICTIONS_TRG.xml	Fri Nov 11 10:06:34 2016 +0100
@@ -18,7 +18,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-2015 Openbravo SLU
+    * All portions are Copyright (C) 2001-2016 Openbravo SLU
     * All Rights Reserved.
     * Contributor(s):  ______________________________________.
     ************************************************************************/
@@ -66,6 +66,8 @@
       OR(COALESCE(:OLD.QUANTITYORDER, 0) <> COALESCE(:NEW.QUANTITYORDER, 0))
       OR(COALESCE(:OLD.C_ORDERLINE_ID, '0') <> COALESCE(:NEW.C_ORDERLINE_ID, '0'))
       OR(COALESCE(:OLD.M_PRODUCT_UOM_ID, '0') <> COALESCE(:NEW.M_PRODUCT_UOM_ID, '0'))
+      OR(COALESCE(:OLD.C_AUM, '0') <> COALESCE(:NEW.C_AUM, '0'))
+      OR(COALESCE(:OLD.AUMQTY, 0) <> COALESCE(:NEW.AUMQTY, 0))	
       OR(COALESCE(:OLD.AD_ORG_ID, '0') <> COALESCE(:NEW.AD_ORG_ID, '0'))
       OR(COALESCE(:OLD.AD_CLIENT_ID, '0') <> COALESCE(:NEW.AD_CLIENT_ID, '0'))
       )) THEN
@@ -127,6 +129,13 @@
       END IF;
     END IF;
   END IF;
+
+  IF (INSERTING OR UPDATING) THEN
+    IF (:NEW.C_AUM IS NOT NULL AND :NEW.AUMQTY IS NOT NULL AND :NEW.M_PRODUCT_UOM_ID IS NOT NULL AND :NEW.QUANTITYORDER IS NOT NULL) THEN
+      RAISE_APPLICATION_ERROR(-20000, '@CannotUseAUMandSecondUOM@');
+    END IF;
+  END IF;
+  
 END C_INVLINE_CHK_RESTRICTIONS_TRG
 ]]></body>
     </trigger>
--- a/src-db/database/model/triggers/C_ORDLINE_CHK_RESTRICTIONS_TRG.xml	Fri Nov 11 10:01:28 2016 +0100
+++ b/src-db/database/model/triggers/C_ORDLINE_CHK_RESTRICTIONS_TRG.xml	Fri Nov 11 10:06:34 2016 +0100
@@ -14,7 +14,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-2013 Openbravo SLU
+* All portions are Copyright (C) 2001-2016 Openbravo SLU
 * All Rights Reserved.
 * Contributor(s):  ______________________________________.
 ************************************************************************/
@@ -43,7 +43,7 @@
   END IF;
   IF UPDATING THEN
     IF((COALESCE(:old.LINE, 0) <> COALESCE(:NEW.LINE, 0) OR COALESCE(:old.M_PRODUCT_ID, '0') <> COALESCE(:NEW.M_PRODUCT_ID, '0') OR COALESCE(:old.QTYORDERED, 0) <> COALESCE(:NEW.QTYORDERED, 0) OR COALESCE(:old.PRICELIST, 0) <> COALESCE(:NEW.PRICELIST, 0) OR COALESCE(:old.PRICEACTUAL, 0) <> COALESCE(:NEW.PRICEACTUAL, 0) OR COALESCE(:old.PRICELIMIT, 0) <> COALESCE(:NEW.PRICELIMIT, 0) OR COALESCE(:old.LINENETAMT, 0) <> COALESCE(:NEW.LINENETAMT, 0) OR COALESCE(:old.C_CHARGE_ID, '0') <> COALESCE(:NEW.C_CHARGE_ID, '0') OR COALESCE(:old.CHARGEAMT, 0) <> COALESCE(:NEW.CHARGEAMT, 0) OR COALESCE(:old.C_TAX_ID, '0') <> COALESCE(:NEW.C_TAX_ID, '0')  OR COALESCE(:old.DIRECTSHIP, '.') <> COALESCE(:NEW.DIRECTSHIP, '.') OR COALESCE(:old.M_ATTRIBUTESETINSTANCE_ID, '0') <> COALESCE(:NEW.M_ATTRIBUTESETINSTANCE_ID, '0') OR COALESCE(:old.QUANTITYORDER, 0) <> COALESCE(:NEW.QUANTITYORDER, 0) OR COALESCE(
-      :old.M_PRODUCT_UOM_ID, '0') <> COALESCE(:NEW.M_PRODUCT_UOM_ID, '0')
+      :old.M_PRODUCT_UOM_ID, '0') <> COALESCE(:NEW.M_PRODUCT_UOM_ID, '0') OR COALESCE(:old.C_AUM, '0') <> COALESCE(:NEW.C_AUM, '0') OR COALESCE(:old.aumqty, 0) <> COALESCE(:NEW.aumqty, 0)
       OR COALESCE(:old.QtyInvoiced, 0) <> COALESCE(:NEW.QtyInvoiced, 0))) THEN
       SELECT PROCESSED,
         DOCACTION, DOCSTATUS, DocumentNo, ISSOTRX
@@ -68,6 +68,8 @@
           OR(COALESCE(:OLD.M_ATTRIBUTESETINSTANCE_ID, '0') <> COALESCE(:NEW.M_ATTRIBUTESETINSTANCE_ID, '0'))
           OR(COALESCE(:OLD.QUANTITYORDER, 0) <> COALESCE(:NEW.QUANTITYORDER, 0))
           OR(COALESCE(:OLD.M_PRODUCT_UOM_ID, '0') <> COALESCE(:NEW.M_PRODUCT_UOM_ID, '0'))
+          OR(COALESCE(:OLD.C_AUM, '0') <> COALESCE(:NEW.C_AUM, '0'))
+          OR(COALESCE(:OLD.AUMQTY, 0) <> COALESCE(:NEW.AUMQTY, 0))
           OR(COALESCE(:old.AD_ORG_ID, '0') <> COALESCE(:new.AD_ORG_ID, '0'))
           OR(COALESCE(:old.AD_CLIENT_ID, '0') <> COALESCE(:new.AD_CLIENT_ID, '0'))
         ) THEN
@@ -119,6 +121,9 @@
       IF (v_isgeneric = 'Y') THEN
         RAISE_APPLICATION_ERROR(-20000, '@CannotUseGenericProduct@');
       END IF;
+      IF (:NEW.C_AUM IS NOT NULL AND :NEW.AUMQTY IS NOT NULL AND :NEW.M_PRODUCT_UOM_ID IS NOT NULL AND :NEW.QUANTITYORDER IS NOT NULL) THEN
+        RAISE_APPLICATION_ERROR(-20000, '@CannotUseAUMandSecondUOM@');
+      END IF;
     END IF;
   END IF;
 END C_ORDLINE_CHK_RESTRICTIONS_TRG
--- a/src-db/database/model/triggers/M_INOUTLINE_TRG.xml	Fri Nov 11 10:01:28 2016 +0100
+++ b/src-db/database/model/triggers/M_INOUTLINE_TRG.xml	Fri Nov 11 10:06:34 2016 +0100
@@ -34,7 +34,7 @@
  * Portions created by Jorg Janke are Copyright (C) 1999-2001 Jorg Janke, parts
  * created by ComPiere are Copyright (C) ComPiere, Inc.;   All Rights Reserved.
  * Contributor(s): Openbravo SLU
- * Contributions are Copyright (C) 2001-2015 Openbravo S.L.U.
+ * Contributions are Copyright (C) 2001-2016 Openbravo S.L.U.
  ******************************************************************************/
      
 BEGIN
@@ -226,6 +226,8 @@
       OR COALESCE(:OLD.M_AttributeSetInstance_ID,'0') <> COALESCE(:NEW.M_AttributeSetInstance_ID,'0')
       OR :OLD.C_UOM_ID <> :NEW.C_UOM_ID
       OR COALESCE(:OLD.M_Product_UOM_ID,'0') <> COALESCE(:NEW.M_Product_UOM_ID,'0')
+      OR COALESCE(:OLD.C_AUM,'0') <> COALESCE(:NEW.C_AUM,'0')
+      OR COALESCE(:OLD.AUMQTY,0) <> COALESCE(:NEW.AUMQTY,0)
       OR :OLD.MOVEMENTQTY <> :NEW.MOVEMENTQTY
       OR COALESCE(:OLD.QUANTITYORDER, 0) <> COALESCE(:NEW.QUANTITYORDER, 0)) THEN
       
--- a/src-db/database/model/triggers/M_IOLINE_CHK_RESTRICTIONS_TRG.xml	Fri Nov 11 10:01:28 2016 +0100
+++ b/src-db/database/model/triggers/M_IOLINE_CHK_RESTRICTIONS_TRG.xml	Fri Nov 11 10:06:34 2016 +0100
@@ -19,7 +19,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-2013 Openbravo SLU
+* All portions are Copyright (C) 2001-2016 Openbravo SLU
 * All Rights Reserved.
 * Contributor(s):  ______________________________________.
 ************************************************************************/
@@ -51,6 +51,8 @@
    OR(COALESCE(:old.M_PRODUCT_UOM_ID, '0') <> COALESCE(:new.M_PRODUCT_UOM_ID, '0'))
    OR(COALESCE(:old.C_ORDERLINE_ID, '0') <> COALESCE(:new.C_ORDERLINE_ID, '0') AND v_DocStatus != 'VO')
    OR(COALESCE(:old.M_LOCATOR_ID, '0') <> COALESCE(:new.M_LOCATOR_ID, '0'))
+   OR(COALESCE(:OLD.C_AUM, '0') <> COALESCE(:NEW.C_AUM, '0'))
+   OR(COALESCE(:OLD.AUMQTY, 0) <> COALESCE(:NEW.AUMQTY, 0))
    OR(COALESCE(:old.AD_ORG_ID, '0') <> COALESCE(:new.AD_ORG_ID, '0'))
    OR(COALESCE(:old.AD_CLIENT_ID, '0') <> COALESCE(:new.AD_CLIENT_ID, '0'))))
   THEN
@@ -80,6 +82,13 @@
       END IF;
     END IF;
   END IF;
+
+  IF (INSERTING OR UPDATING) THEN
+    IF (:NEW.C_AUM IS NOT NULL AND :NEW.AUMQTY IS NOT NULL AND :NEW.M_PRODUCT_UOM_ID IS NOT NULL AND :NEW.QUANTITYORDER IS NOT NULL) THEN
+      RAISE_APPLICATION_ERROR(-20000, '@CannotUseAUMandSecondUOM@');
+    END IF;
+  END IF;
+  
 END M_IOLINE_CHK_RESTRICTIONS_TRG
 ]]></body>
     </trigger>
--- a/src-db/database/model/triggers/M_REQUISITIONLINE_TRG.xml	Fri Nov 11 10:01:28 2016 +0100
+++ b/src-db/database/model/triggers/M_REQUISITIONLINE_TRG.xml	Fri Nov 11 10:06:34 2016 +0100
@@ -14,7 +14,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) 2008-2014 Openbravo SLU
+* All portions are Copyright (C) 2008-2016 Openbravo SLU
 * All Rights Reserved.
 * Contributor(s):  ______________________________________.
 ************************************************************************/
@@ -29,7 +29,6 @@
     IF AD_isTriggerEnabled()='N' THEN RETURN;
     END IF;
 
-
   IF INSERTING THEN
     SELECT DocStatus, :new.ReqStatus, 0 INTO v_DocStatus, v_ReqStatus, v_OrderedQty
     FROM M_Requisition
@@ -78,6 +77,8 @@
        OR (COALESCE(:old.C_BPartner_ID, '0') <> COALESCE(:new.C_BPartner_ID, '0' ))
        OR (COALESCE(:old.C_UOM_ID, '0') <> COALESCE(:new.C_UOM_ID, '0' ))
        OR (COALESCE(:old.M_Product_UOM_ID, '0') <> COALESCE(:new.M_Product_UOM_ID, '0' ))
+       OR (COALESCE(:OLD.C_AUM, '0') <> COALESCE(:NEW.C_AUM, '0'))
+       OR (COALESCE(:OLD.AUMQTY, 0) <> COALESCE(:NEW.AUMQTY, 0))
        OR (COALESCE(:old.QuantityOrder, -1) <> COALESCE(:new.QuantityOrder, -1 ))
        OR (COALESCE(:old.M_AttributeSetInstance_ID, '-1') <> COALESCE(:new.M_AttributeSetInstance_ID, '-1' ))
        OR (COALESCE(:old.NeedByDate, TO_DATE('01-01-1900', 'DD-MM-YYYY')) <> COALESCE(:new.NeedByDate, TO_DATE('01-01-1900', 'DD-MM-YYYY')))) THEN
@@ -97,6 +98,9 @@
       IF (v_isgeneric = 'Y') THEN
         RAISE_APPLICATION_ERROR(-20000, '@CannotUseGenericProduct@');
       END IF;
+      IF (:NEW.C_AUM IS NOT NULL AND :NEW.AUMQTY IS NOT NULL AND :NEW.M_PRODUCT_UOM_ID IS NOT NULL AND :NEW.QUANTITYORDER IS NOT NULL) THEN
+        RAISE_APPLICATION_ERROR(-20000, '@CannotUseAUMandSecondUOM@');
+      END IF;
     END IF;
   END IF;
 END M_REQUISITIONLINE_TRG
--- a/src-db/database/model/views/M_CREATEPOLINES_PE_V.xml	Fri Nov 11 10:01:28 2016 +0100
+++ b/src-db/database/model/views/M_CREATEPOLINES_PE_V.xml	Fri Nov 11 10:06:34 2016 +0100
@@ -1,4 +1,4 @@
 <?xml version="1.0"?>
   <database name="VIEW M_CREATEPOLINES_PE_V">
-    <view name="M_CREATEPOLINES_PE_V"><![CDATA[SELECT pp.m_productprice_id AS m_createpolines_pe_v_id, pp.ad_client_id, pp.ad_org_id, pp.isactive, pp.created, pp.createdby, pp.updated, pp.updatedby, 'N' AS ob_selected, pp.m_product_id, plv.m_pricelist_id, pp.pricestd, NULL AS qtyordered FROM m_productprice pp JOIN m_product p ON pp.m_product_id = p.m_product_id AND COALESCE(p.isgeneric, 'N') = 'N' JOIN m_pricelist_version plv ON pp.m_pricelist_version_id = plv.m_pricelist_version_id JOIN m_pricelist pl ON pl.m_pricelist_id = plv.m_pricelist_id WHERE p.isactive = 'Y' AND pl.issopricelist = 'N' AND plv.validfrom = ((SELECT max(plv2.validfrom) AS max FROM m_pricelist_version plv2 WHERE plv2.m_pricelist_id = pl.m_pricelist_id AND plv2.validfrom <= now()))]]></view>
+    <view name="M_CREATEPOLINES_PE_V"><![CDATA[SELECT pp.m_productprice_id AS m_createpolines_pe_v_id, pp.ad_client_id, pp.ad_org_id, pp.isactive, pp.created, pp.createdby, pp.updated, pp.updatedby, 'N' AS ob_selected, pp.m_product_id, plv.m_pricelist_id, pp.pricestd, NULL AS qtyordered, NULL AS qtyaum, p.c_uom_id AS aum FROM m_productprice pp JOIN m_product p ON pp.m_product_id = p.m_product_id AND COALESCE(p.isgeneric, 'N') = 'N' JOIN m_pricelist_version plv ON pp.m_pricelist_version_id = plv.m_pricelist_version_id JOIN m_pricelist pl ON pl.m_pricelist_id = plv.m_pricelist_id WHERE p.isactive = 'Y' AND pl.issopricelist = 'N' AND plv.validfrom = ((SELECT max(plv2.validfrom) AS max FROM m_pricelist_version plv2 WHERE plv2.m_pricelist_id = pl.m_pricelist_id AND plv2.validfrom <= now()))]]></view>
   </database>
--- a/src-db/database/sourcedata/AD_CALLOUT.xml	Fri Nov 11 10:01:28 2016 +0100
+++ b/src-db/database/sourcedata/AD_CALLOUT.xml	Fri Nov 11 10:06:34 2016 +0100
@@ -796,6 +796,15 @@
 <!--16E14A45CD654B78B2C22C1EF5B84A74-->  <AD_MODULE_ID><![CDATA[0]]></AD_MODULE_ID>
 <!--16E14A45CD654B78B2C22C1EF5B84A74--></AD_CALLOUT>
 
+<!--1AB9BD3356D643A79C058AA3B4EB175E--><AD_CALLOUT>
+<!--1AB9BD3356D643A79C058AA3B4EB175E-->  <AD_CALLOUT_ID><![CDATA[1AB9BD3356D643A79C058AA3B4EB175E]]></AD_CALLOUT_ID>
+<!--1AB9BD3356D643A79C058AA3B4EB175E-->  <AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID>
+<!--1AB9BD3356D643A79C058AA3B4EB175E-->  <AD_ORG_ID><![CDATA[0]]></AD_ORG_ID>
+<!--1AB9BD3356D643A79C058AA3B4EB175E-->  <ISACTIVE><![CDATA[Y]]></ISACTIVE>
+<!--1AB9BD3356D643A79C058AA3B4EB175E-->  <NAME><![CDATA[OperativeQuantity_To_BaseQuantity]]></NAME>
+<!--1AB9BD3356D643A79C058AA3B4EB175E-->  <AD_MODULE_ID><![CDATA[0]]></AD_MODULE_ID>
+<!--1AB9BD3356D643A79C058AA3B4EB175E--></AD_CALLOUT>
+
 <!--1D72DBC1B228453A9A64443CAC145991--><AD_CALLOUT>
 <!--1D72DBC1B228453A9A64443CAC145991-->  <AD_CALLOUT_ID><![CDATA[1D72DBC1B228453A9A64443CAC145991]]></AD_CALLOUT_ID>
 <!--1D72DBC1B228453A9A64443CAC145991-->  <AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID>
@@ -1098,6 +1107,16 @@
 <!--896299C6800F496C83FAE276E1F37B6A-->  <AD_MODULE_ID><![CDATA[0]]></AD_MODULE_ID>
 <!--896299C6800F496C83FAE276E1F37B6A--></AD_CALLOUT>
 
+<!--8A5A44A91EBF4081B316572504DD68DA--><AD_CALLOUT>
+<!--8A5A44A91EBF4081B316572504DD68DA-->  <AD_CALLOUT_ID><![CDATA[8A5A44A91EBF4081B316572504DD68DA]]></AD_CALLOUT_ID>
+<!--8A5A44A91EBF4081B316572504DD68DA-->  <AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID>
+<!--8A5A44A91EBF4081B316572504DD68DA-->  <AD_ORG_ID><![CDATA[0]]></AD_ORG_ID>
+<!--8A5A44A91EBF4081B316572504DD68DA-->  <ISACTIVE><![CDATA[Y]]></ISACTIVE>
+<!--8A5A44A91EBF4081B316572504DD68DA-->  <NAME><![CDATA[GtinFormat]]></NAME>
+<!--8A5A44A91EBF4081B316572504DD68DA-->  <DESCRIPTION><![CDATA[Validate GTIN Format]]></DESCRIPTION>
+<!--8A5A44A91EBF4081B316572504DD68DA-->  <AD_MODULE_ID><![CDATA[0]]></AD_MODULE_ID>
+<!--8A5A44A91EBF4081B316572504DD68DA--></AD_CALLOUT>
+
 <!--8D5A298D3BEF4E14BB9B9C2A7D0CFA18--><AD_CALLOUT>
 <!--8D5A298D3BEF4E14BB9B9C2A7D0CFA18-->  <AD_CALLOUT_ID><![CDATA[8D5A298D3BEF4E14BB9B9C2A7D0CFA18]]></AD_CALLOUT_ID>
 <!--8D5A298D3BEF4E14BB9B9C2A7D0CFA18-->  <AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID>
@@ -1155,6 +1174,16 @@
 <!--AE1F6503340441ABBF1BC89FD46DEF13-->  <AD_MODULE_ID><![CDATA[0]]></AD_MODULE_ID>
 <!--AE1F6503340441ABBF1BC89FD46DEF13--></AD_CALLOUT>
 
+<!--B21CED81B17544D09C608BB9EEEC51F6--><AD_CALLOUT>
+<!--B21CED81B17544D09C608BB9EEEC51F6-->  <AD_CALLOUT_ID><![CDATA[B21CED81B17544D09C608BB9EEEC51F6]]></AD_CALLOUT_ID>
+<!--B21CED81B17544D09C608BB9EEEC51F6-->  <AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID>
+<!--B21CED81B17544D09C608BB9EEEC51F6-->  <AD_ORG_ID><![CDATA[0]]></AD_ORG_ID>
+<!--B21CED81B17544D09C608BB9EEEC51F6-->  <ISACTIVE><![CDATA[Y]]></ISACTIVE>
+<!--B21CED81B17544D09C608BB9EEEC51F6-->  <NAME><![CDATA[AUM_ConversionRate]]></NAME>
+<!--B21CED81B17544D09C608BB9EEEC51F6-->  <DESCRIPTION><![CDATA[Set the BUM-AUM conversion rate]]></DESCRIPTION>
+<!--B21CED81B17544D09C608BB9EEEC51F6-->  <AD_MODULE_ID><![CDATA[0]]></AD_MODULE_ID>
+<!--B21CED81B17544D09C608BB9EEEC51F6--></AD_CALLOUT>
+
 <!--B7913B8983F94C7AA8D871F657D9DD32--><AD_CALLOUT>
 <!--B7913B8983F94C7AA8D871F657D9DD32-->  <AD_CALLOUT_ID><![CDATA[B7913B8983F94C7AA8D871F657D9DD32]]></AD_CALLOUT_ID>
 <!--B7913B8983F94C7AA8D871F657D9DD32-->  <AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID>
--- a/src-db/database/sourcedata/AD_MODEL_OBJECT.xml	Fri Nov 11 10:01:28 2016 +0100
+++ b/src-db/database/sourcedata/AD_MODEL_OBJECT.xml	Fri Nov 11 10:06:34 2016 +0100
@@ -3294,6 +3294,18 @@
 <!--2B209CEDF6564F9DBE160FC5D6AD5CF5-->  <OBJECT_TYPE><![CDATA[P]]></OBJECT_TYPE>
 <!--2B209CEDF6564F9DBE160FC5D6AD5CF5--></AD_MODEL_OBJECT>
 
+<!--2B2FBE22CEBC443EB31953D99A6B0AEB--><AD_MODEL_OBJECT>
+<!--2B2FBE22CEBC443EB31953D99A6B0AEB-->  <AD_MODEL_OBJECT_ID><![CDATA[2B2FBE22CEBC443EB31953D99A6B0AEB]]></AD_MODEL_OBJECT_ID>
+<!--2B2FBE22CEBC443EB31953D99A6B0AEB-->  <AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID>
+<!--2B2FBE22CEBC443EB31953D99A6B0AEB-->  <AD_ORG_ID><![CDATA[0]]></AD_ORG_ID>
+<!--2B2FBE22CEBC443EB31953D99A6B0AEB-->  <ISACTIVE><![CDATA[Y]]></ISACTIVE>
+<!--2B2FBE22CEBC443EB31953D99A6B0AEB-->  <ACTION><![CDATA[C]]></ACTION>
+<!--2B2FBE22CEBC443EB31953D99A6B0AEB-->  <CLASSNAME><![CDATA[org.openbravo.erpCommon.ad_callouts.OperativeQuantity_To_BaseQuantity]]></CLASSNAME>
+<!--2B2FBE22CEBC443EB31953D99A6B0AEB-->  <ISDEFAULT><![CDATA[Y]]></ISDEFAULT>
+<!--2B2FBE22CEBC443EB31953D99A6B0AEB-->  <AD_CALLOUT_ID><![CDATA[1AB9BD3356D643A79C058AA3B4EB175E]]></AD_CALLOUT_ID>
+<!--2B2FBE22CEBC443EB31953D99A6B0AEB-->  <OBJECT_TYPE><![CDATA[S]]></OBJECT_TYPE>
+<!--2B2FBE22CEBC443EB31953D99A6B0AEB--></AD_MODEL_OBJECT>
+
 <!--2D675A25948F4CCCA8C3C7B1906DD131--><AD_MODEL_OBJECT>
 <!--2D675A25948F4CCCA8C3C7B1906DD131-->  <AD_MODEL_OBJECT_ID><![CDATA[2D675A25948F4CCCA8C3C7B1906DD131]]></AD_MODEL_OBJECT_ID>
 <!--2D675A25948F4CCCA8C3C7B1906DD131-->  <AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID>
@@ -3873,6 +3885,18 @@
 <!--6AE5F2D3163C178BE040007F010174B7-->  <OBJECT_TYPE><![CDATA[S]]></OBJECT_TYPE>
 <!--6AE5F2D3163C178BE040007F010174B7--></AD_MODEL_OBJECT>
 
+<!--6C6F9021253A44EA8DC3E1517818A402--><AD_MODEL_OBJECT>
+<!--6C6F9021253A44EA8DC3E1517818A402-->  <AD_MODEL_OBJECT_ID><![CDATA[6C6F9021253A44EA8DC3E1517818A402]]></AD_MODEL_OBJECT_ID>
+<!--6C6F9021253A44EA8DC3E1517818A402-->  <AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID>
+<!--6C6F9021253A44EA8DC3E1517818A402-->  <AD_ORG_ID><![CDATA[0]]></AD_ORG_ID>
+<!--6C6F9021253A44EA8DC3E1517818A402-->  <ISACTIVE><![CDATA[Y]]></ISACTIVE>
+<!--6C6F9021253A44EA8DC3E1517818A402-->  <ACTION><![CDATA[C]]></ACTION>
+<!--6C6F9021253A44EA8DC3E1517818A402-->  <CLASSNAME><![CDATA[org.openbravo.erpCommon.ad_callouts.GtinFormat]]></CLASSNAME>
+<!--6C6F9021253A44EA8DC3E1517818A402-->  <ISDEFAULT><![CDATA[Y]]></ISDEFAULT>
+<!--6C6F9021253A44EA8DC3E1517818A402-->  <AD_CALLOUT_ID><![CDATA[8A5A44A91EBF4081B316572504DD68DA]]></AD_CALLOUT_ID>
+<!--6C6F9021253A44EA8DC3E1517818A402-->  <OBJECT_TYPE><![CDATA[S]]></OBJECT_TYPE>
+<!--6C6F9021253A44EA8DC3E1517818A402--></AD_MODEL_OBJECT>
+
 <!--6DAAF7531ABD453383873AA790B1967A--><AD_MODEL_OBJECT>
 <!--6DAAF7531ABD453383873AA790B1967A-->  <AD_MODEL_OBJECT_ID><![CDATA[6DAAF7531ABD453383873AA790B1967A]]></AD_MODEL_OBJECT_ID>
 <!--6DAAF7531ABD453383873AA790B1967A-->  <AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID>
@@ -4623,6 +4647,18 @@
 <!--CB0093CB5B33AA24E040007F010049A5-->  <OBJECT_TYPE><![CDATA[S]]></OBJECT_TYPE>
 <!--CB0093CB5B33AA24E040007F010049A5--></AD_MODEL_OBJECT>
 
+<!--CB7941BCFDD347548A495FCE2EFDD6CE--><AD_MODEL_OBJECT>
+<!--CB7941BCFDD347548A495FCE2EFDD6CE-->  <AD_MODEL_OBJECT_ID><![CDATA[CB7941BCFDD347548A495FCE2EFDD6CE]]></AD_MODEL_OBJECT_ID>
+<!--CB7941BCFDD347548A495FCE2EFDD6CE-->  <AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID>
+<!--CB7941BCFDD347548A495FCE2EFDD6CE-->  <AD_ORG_ID><![CDATA[0]]></AD_ORG_ID>
+<!--CB7941BCFDD347548A495FCE2EFDD6CE-->  <ISACTIVE><![CDATA[Y]]></ISACTIVE>
+<!--CB7941BCFDD347548A495FCE2EFDD6CE-->  <ACTION><![CDATA[C]]></ACTION>
+<!--CB7941BCFDD347548A495FCE2EFDD6CE-->  <CLASSNAME><![CDATA[org.openbravo.erpCommon.ad_callouts.AUM_ConversionRate]]></CLASSNAME>
+<!--CB7941BCFDD347548A495FCE2EFDD6CE-->  <ISDEFAULT><![CDATA[Y]]></ISDEFAULT>
+<!--CB7941BCFDD347548A495FCE2EFDD6CE-->  <AD_CALLOUT_ID><![CDATA[B21CED81B17544D09C608BB9EEEC51F6]]></AD_CALLOUT_ID>
+<!--CB7941BCFDD347548A495FCE2EFDD6CE-->  <OBJECT_TYPE><![CDATA[S]]></OBJECT_TYPE>
+<!--CB7941BCFDD347548A495FCE2EFDD6CE--></AD_MODEL_OBJECT>
+
 <!--CBD971929B504D11A3164B58D8C69CBE--><AD_MODEL_OBJECT>
 <!--CBD971929B504D11A3164B58D8C69CBE-->  <AD_MODEL_OBJECT_ID><![CDATA[CBD971929B504D11A3164B58D8C69CBE]]></AD_MODEL_OBJECT_ID>
 <!--CBD971929B504D11A3164B58D8C69CBE-->  <AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID>
--- a/src-db/database/sourcedata/AD_MODEL_OBJECT_MAPPING.xml	Fri Nov 11 10:01:28 2016 +0100
+++ b/src-db/database/sourcedata/AD_MODEL_OBJECT_MAPPING.xml	Fri Nov 11 10:06:34 2016 +0100
@@ -3560,6 +3560,16 @@
 <!--20A280A2B6424864BBBAD9CC6B27462C-->  <ISDEFAULT><![CDATA[Y]]></ISDEFAULT>
 <!--20A280A2B6424864BBBAD9CC6B27462C--></AD_MODEL_OBJECT_MAPPING>
 
+<!--21D638B595D84A3586034B568AA5EDD3--><AD_MODEL_OBJECT_MAPPING>
+<!--21D638B595D84A3586034B568AA5EDD3-->  <AD_MODEL_OBJECT_MAPPING_ID><![CDATA[21D638B595D84A3586034B568AA5EDD3]]></AD_MODEL_OBJECT_MAPPING_ID>
+<!--21D638B595D84A3586034B568AA5EDD3-->  <AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID>
+<!--21D638B595D84A3586034B568AA5EDD3-->  <AD_ORG_ID><![CDATA[0]]></AD_ORG_ID>
+<!--21D638B595D84A3586034B568AA5EDD3-->  <ISACTIVE><![CDATA[Y]]></ISACTIVE>
+<!--21D638B595D84A3586034B568AA5EDD3-->  <AD_MODEL_OBJECT_ID><![CDATA[2B2FBE22CEBC443EB31953D99A6B0AEB]]></AD_MODEL_OBJECT_ID>
+<!--21D638B595D84A3586034B568AA5EDD3-->  <MAPPINGNAME><![CDATA[/ad_callouts/OperativeQuantity_To_BaseQuantity.html]]></MAPPINGNAME>
+<!--21D638B595D84A3586034B568AA5EDD3-->  <ISDEFAULT><![CDATA[Y]]></ISDEFAULT>
+<!--21D638B595D84A3586034B568AA5EDD3--></AD_MODEL_OBJECT_MAPPING>
+
 <!--253ABF537A3842FD94D7749273A6AA99--><AD_MODEL_OBJECT_MAPPING>
 <!--253ABF537A3842FD94D7749273A6AA99-->  <AD_MODEL_OBJECT_MAPPING_ID><![CDATA[253ABF537A3842FD94D7749273A6AA99]]></AD_MODEL_OBJECT_MAPPING_ID>
 <!--253ABF537A3842FD94D7749273A6AA99-->  <AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID>
@@ -4510,6 +4520,16 @@
 <!--CB0093CB5B34AA24E040007F010049A5-->  <ISDEFAULT><![CDATA[Y]]></ISDEFAULT>
 <!--CB0093CB5B34AA24E040007F010049A5--></AD_MODEL_OBJECT_MAPPING>
 
+<!--CF9F51866E78444DB90ED5FD054F526B--><AD_MODEL_OBJECT_MAPPING>
+<!--CF9F51866E78444DB90ED5FD054F526B-->  <AD_MODEL_OBJECT_MAPPING_ID><![CDATA[CF9F51866E78444DB90ED5FD054F526B]]></AD_MODEL_OBJECT_MAPPING_ID>
+<!--CF9F51866E78444DB90ED5FD054F526B-->  <AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID>
+<!--CF9F51866E78444DB90ED5FD054F526B-->  <AD_ORG_ID><![CDATA[0]]></AD_ORG_ID>
+<!--CF9F51866E78444DB90ED5FD054F526B-->  <ISACTIVE><![CDATA[Y]]></ISACTIVE>
+<!--CF9F51866E78444DB90ED5FD054F526B-->  <AD_MODEL_OBJECT_ID><![CDATA[CB7941BCFDD347548A495FCE2EFDD6CE]]></AD_MODEL_OBJECT_ID>
+<!--CF9F51866E78444DB90ED5FD054F526B-->  <MAPPINGNAME><![CDATA[/ad_callouts/AUM_ConversionRate.html]]></MAPPINGNAME>
+<!--CF9F51866E78444DB90ED5FD054F526B-->  <ISDEFAULT><![CDATA[Y]]></ISDEFAULT>
+<!--CF9F51866E78444DB90ED5FD054F526B--></AD_MODEL_OBJECT_MAPPING>
+
 <!--D018FD05F805446099A9DE17D02C8AAE--><AD_MODEL_OBJECT_MAPPING>
 <!--D018FD05F805446099A9DE17D02C8AAE-->  <AD_MODEL_OBJECT_MAPPING_ID><![CDATA[D018FD05F805446099A9DE17D02C8AAE]]></AD_MODEL_OBJECT_MAPPING_ID>
 <!--D018FD05F805446099A9DE17D02C8AAE-->  <AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID>
@@ -4800,6 +4820,16 @@
 <!--FAC7271D69F343BCA656BB3FDF81FD59-->  <ISDEFAULT><![CDATA[N]]></ISDEFAULT>
 <!--FAC7271D69F343BCA656BB3FDF81FD59--></AD_MODEL_OBJECT_MAPPING>
 
+<!--FBC62CA002F640D59E0B8AC70935B26F--><AD_MODEL_OBJECT_MAPPING>
+<!--FBC62CA002F640D59E0B8AC70935B26F-->  <AD_MODEL_OBJECT_MAPPING_ID><![CDATA[FBC62CA002F640D59E0B8AC70935B26F]]></AD_MODEL_OBJECT_MAPPING_ID>
+<!--FBC62CA002F640D59E0B8AC70935B26F-->  <AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID>
+<!--FBC62CA002F640D59E0B8AC70935B26F-->  <AD_ORG_ID><![CDATA[0]]></AD_ORG_ID>
+<!--FBC62CA002F640D59E0B8AC70935B26F-->  <ISACTIVE><![CDATA[Y]]></ISACTIVE>
+<!--FBC62CA002F640D59E0B8AC70935B26F-->  <AD_MODEL_OBJECT_ID><![CDATA[6C6F9021253A44EA8DC3E1517818A402]]></AD_MODEL_OBJECT_ID>
+<!--FBC62CA002F640D59E0B8AC70935B26F-->  <MAPPINGNAME><![CDATA[/ad_callouts/GtinFormat.html]]></MAPPINGNAME>
+<!--FBC62CA002F640D59E0B8AC70935B26F-->  <ISDEFAULT><![CDATA[Y]]></ISDEFAULT>
+<!--FBC62CA002F640D59E0B8AC70935B26F--></AD_MODEL_OBJECT_MAPPING>
+
 <!--FF808181316C298101316C3F6E7F0013--><AD_MODEL_OBJECT_MAPPING>
 <!--FF808181316C298101316C3F6E7F0013-->  <AD_MODEL_OBJECT_MAPPING_ID><![CDATA[FF808181316C298101316C3F6E7F0013]]></AD_MODEL_OBJECT_MAPPING_ID>
 <!--FF808181316C298101316C3F6E7F0013-->  <AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID>
--- a/src-db/database/sourcedata/OBUISEL_SELECTOR.xml	Fri Nov 11 10:01:28 2016 +0100
+++ b/src-db/database/sourcedata/OBUISEL_SELECTOR.xml	Fri Nov 11 10:06:34 2016 +0100
@@ -428,6 +428,22 @@
 <!--5E026139F74D4FD5AC4FA23189A03C92-->  <CUSTOM_QUERY><![CDATA[N]]></CUSTOM_QUERY>
 <!--5E026139F74D4FD5AC4FA23189A03C92--></OBUISEL_SELECTOR>
 
+<!--631ED05BC8594B1FBF55D1079BAB30B5--><OBUISEL_SELECTOR>
+<!--631ED05BC8594B1FBF55D1079BAB30B5-->  <OBUISEL_SELECTOR_ID><![CDATA[631ED05BC8594B1FBF55D1079BAB30B5]]></OBUISEL_SELECTOR_ID>
+<!--631ED05BC8594B1FBF55D1079BAB30B5-->  <AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID>
+<!--631ED05BC8594B1FBF55D1079BAB30B5-->  <AD_ORG_ID><![CDATA[0]]></AD_ORG_ID>
+<!--631ED05BC8594B1FBF55D1079BAB30B5-->  <AD_MODULE_ID><![CDATA[0]]></AD_MODULE_ID>
+<!--631ED05BC8594B1FBF55D1079BAB30B5-->  <NAME><![CDATA[UOM Selector]]></NAME>
+<!--631ED05BC8594B1FBF55D1079BAB30B5-->  <AD_REFERENCE_ID><![CDATA[4E76A829897D466394409273FBE6D5EE]]></AD_REFERENCE_ID>
+<!--631ED05BC8594B1FBF55D1079BAB30B5-->  <AD_TABLE_ID><![CDATA[146]]></AD_TABLE_ID>
+<!--631ED05BC8594B1FBF55D1079BAB30B5-->  <WHERECLAUSE><![CDATA[e.id not in (select p.uOM.id from Product p where p.id = @M_Product_ID@) and e.id not in (select a.uOM.id from ProductAUM a where a.product.id = @M_Product_ID@)]]></WHERECLAUSE>
+<!--631ED05BC8594B1FBF55D1079BAB30B5-->  <OBCLKER_TEMPLATE_ID><![CDATA[9314DE8599AD44E7BFC4CC50699042AB]]></OBCLKER_TEMPLATE_ID>
+<!--631ED05BC8594B1FBF55D1079BAB30B5-->  <ISACTIVE><![CDATA[Y]]></ISACTIVE>
+<!--631ED05BC8594B1FBF55D1079BAB30B5-->  <SUGGESTIONTEXTMATCHSTYLE><![CDATA[substring]]></SUGGESTIONTEXTMATCHSTYLE>
+<!--631ED05BC8594B1FBF55D1079BAB30B5-->  <POPUPTEXTMATCHSTYLE><![CDATA[substring]]></POPUPTEXTMATCHSTYLE>
+<!--631ED05BC8594B1FBF55D1079BAB30B5-->  <CUSTOM_QUERY><![CDATA[N]]></CUSTOM_QUERY>
+<!--631ED05BC8594B1FBF55D1079BAB30B5--></OBUISEL_SELECTOR>
+
 <!--632F319DE1564495B3B5D710127DA6DC--><OBUISEL_SELECTOR>
 <!--632F319DE1564495B3B5D710127DA6DC-->  <OBUISEL_SELECTOR_ID><![CDATA[632F319DE1564495B3B5D710127DA6DC]]></OBUISEL_SELECTOR_ID>
 <!--632F319DE1564495B3B5D710127DA6DC-->  <AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID>
@@ -652,6 +668,22 @@
 <!--A48B1462EE7F4C109F06564E0B4677A8-->  <CUSTOM_QUERY><![CDATA[N]]></CUSTOM_QUERY>
 <!--A48B1462EE7F4C109F06564E0B4677A8--></OBUISEL_SELECTOR>
 
+<!--A9173FEF71164322A789C8B0ACD753D5--><OBUISEL_SELECTOR>
+<!--A9173FEF71164322A789C8B0ACD753D5-->  <OBUISEL_SELECTOR_ID><![CDATA[A9173FEF71164322A789C8B0ACD753D5]]></OBUISEL_SELECTOR_ID>
+<!--A9173FEF71164322A789C8B0ACD753D5-->  <AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID>
+<!--A9173FEF71164322A789C8B0ACD753D5-->  <AD_ORG_ID><![CDATA[0]]></AD_ORG_ID>
+<!--A9173FEF71164322A789C8B0ACD753D5-->  <AD_MODULE_ID><![CDATA[0]]></AD_MODULE_ID>
+<!--A9173FEF71164322A789C8B0ACD753D5-->  <NAME><![CDATA[RTV/RFC ReturnedUOMSelector]]></NAME>
+<!--A9173FEF71164322A789C8B0ACD753D5-->  <AD_REFERENCE_ID><![CDATA[0CFE6C62BC4141149723A8A2F5CA4135]]></AD_REFERENCE_ID>
+<!--A9173FEF71164322A789C8B0ACD753D5-->  <AD_TABLE_ID><![CDATA[146]]></AD_TABLE_ID>
+<!--A9173FEF71164322A789C8B0ACD753D5-->  <FILTER_EXPRESSION><![CDATA["e.id = '" + OB.getParameters().get('inpuom')  + "' or e.id = '" + OB.getParameters().get('inpaumid')  + "'"]]></FILTER_EXPRESSION>
+<!--A9173FEF71164322A789C8B0ACD753D5-->  <OBCLKER_TEMPLATE_ID><![CDATA[9314DE8599AD44E7BFC4CC50699042AB]]></OBCLKER_TEMPLATE_ID>
+<!--A9173FEF71164322A789C8B0ACD753D5-->  <ISACTIVE><![CDATA[Y]]></ISACTIVE>
+<!--A9173FEF71164322A789C8B0ACD753D5-->  <SUGGESTIONTEXTMATCHSTYLE><![CDATA[startsWith]]></SUGGESTIONTEXTMATCHSTYLE>
+<!--A9173FEF71164322A789C8B0ACD753D5-->  <POPUPTEXTMATCHSTYLE><![CDATA[startsWith]]></POPUPTEXTMATCHSTYLE>
+<!--A9173FEF71164322A789C8B0ACD753D5-->  <CUSTOM_QUERY><![CDATA[N]]></CUSTOM_QUERY>
+<!--A9173FEF71164322A789C8B0ACD753D5--></OBUISEL_SELECTOR>
+
 <!--ACF43EE5C10F4A83ABCDF1C9F55CDB12--><OBUISEL_SELECTOR>
 <!--ACF43EE5C10F4A83ABCDF1C9F55CDB12-->  <OBUISEL_SELECTOR_ID><![CDATA[ACF43EE5C10F4A83ABCDF1C9F55CDB12]]></OBUISEL_SELECTOR_ID>
 <!--ACF43EE5C10F4A83ABCDF1C9F55CDB12-->  <AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID>
@@ -804,6 +836,22 @@
 <!--BD1DA40E134A42B9889B529302A96871-->  <CUSTOM_QUERY><![CDATA[N]]></CUSTOM_QUERY>
 <!--BD1DA40E134A42B9889B529302A96871--></OBUISEL_SELECTOR>
 
+<!--BE418876228146A39B8F020CC3531BB2--><OBUISEL_SELECTOR>
+<!--BE418876228146A39B8F020CC3531BB2-->  <OBUISEL_SELECTOR_ID><![CDATA[BE418876228146A39B8F020CC3531BB2]]></OBUISEL_SELECTOR_ID>
+<!--BE418876228146A39B8F020CC3531BB2-->  <AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID>
+<!--BE418876228146A39B8F020CC3531BB2-->  <AD_ORG_ID><![CDATA[0]]></AD_ORG_ID>
+<!--BE418876228146A39B8F020CC3531BB2-->  <AD_MODULE_ID><![CDATA[0]]></AD_MODULE_ID>
+<!--BE418876228146A39B8F020CC3531BB2-->  <NAME><![CDATA[RTVSH Returned UOM]]></NAME>
+<!--BE418876228146A39B8F020CC3531BB2-->  <AD_REFERENCE_ID><![CDATA[F418216771C7413CB74DCFBFA548F540]]></AD_REFERENCE_ID>
+<!--BE418876228146A39B8F020CC3531BB2-->  <AD_TABLE_ID><![CDATA[146]]></AD_TABLE_ID>
+<!--BE418876228146A39B8F020CC3531BB2-->  <FILTER_EXPRESSION><![CDATA["e.id = '" + OB.getParameters().get('inpcUomId') + "' or e.id = '" + OB.getParameters().get('inpcAum') + "'" ]]></FILTER_EXPRESSION>
+<!--BE418876228146A39B8F020CC3531BB2-->  <OBCLKER_TEMPLATE_ID><![CDATA[9314DE8599AD44E7BFC4CC50699042AB]]></OBCLKER_TEMPLATE_ID>
+<!--BE418876228146A39B8F020CC3531BB2-->  <ISACTIVE><![CDATA[Y]]></ISACTIVE>
+<!--BE418876228146A39B8F020CC3531BB2-->  <SUGGESTIONTEXTMATCHSTYLE><![CDATA[startsWith]]></SUGGESTIONTEXTMATCHSTYLE>
+<!--BE418876228146A39B8F020CC3531BB2-->  <POPUPTEXTMATCHSTYLE><![CDATA[startsWith]]></POPUPTEXTMATCHSTYLE>
+<!--BE418876228146A39B8F020CC3531BB2-->  <CUSTOM_QUERY><![CDATA[N]]></CUSTOM_QUERY>
+<!--BE418876228146A39B8F020CC3531BB2--></OBUISEL_SELECTOR>
+
 <!--BE6ACDD8B76E4BA994E7127F112FDFAC--><OBUISEL_SELECTOR>
 <!--BE6ACDD8B76E4BA994E7127F112FDFAC-->  <OBUISEL_SELECTOR_ID><![CDATA[BE6ACDD8B76E4BA994E7127F112FDFAC]]></OBUISEL_SELECTOR_ID>
 <!--BE6ACDD8B76E4BA994E7127F112FDFAC-->  <AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID>
@@ -935,6 +983,22 @@
 <!--DF21B651CB604FA9A709D7108FA51177-->  <CUSTOM_QUERY><![CDATA[N]]></CUSTOM_QUERY>
 <!--DF21B651CB604FA9A709D7108FA51177--></OBUISEL_SELECTOR>
 
+<!--DFC496029B4743E49D78E6B4414BDAF2--><OBUISEL_SELECTOR>
+<!--DFC496029B4743E49D78E6B4414BDAF2-->  <OBUISEL_SELECTOR_ID><![CDATA[DFC496029B4743E49D78E6B4414BDAF2]]></OBUISEL_SELECTOR_ID>
+<!--DFC496029B4743E49D78E6B4414BDAF2-->  <AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID>
+<!--DFC496029B4743E49D78E6B4414BDAF2-->  <AD_ORG_ID><![CDATA[0]]></AD_ORG_ID>
+<!--DFC496029B4743E49D78E6B4414BDAF2-->  <AD_MODULE_ID><![CDATA[0]]></AD_MODULE_ID>
+<!--DFC496029B4743E49D78E6B4414BDAF2-->  <NAME><![CDATA[AUM Selector Filtered by Product]]></NAME>
+<!--DFC496029B4743E49D78E6B4414BDAF2-->  <AD_REFERENCE_ID><![CDATA[C258AE68FAD2494AA02C8EC0E5930C4F]]></AD_REFERENCE_ID>
+<!--DFC496029B4743E49D78E6B4414BDAF2-->  <AD_TABLE_ID><![CDATA[146]]></AD_TABLE_ID>
+<!--DFC496029B4743E49D78E6B4414BDAF2-->  <FILTER_EXPRESSION><![CDATA["e.id in (select p.uOM.id from Product p where p.id = '" + OB.getParameters().get('inpmProductId') + "') or e.id in (select a.uOM.id from ProductAUM a where a.product.id = '" + OB.getParameters().get('inpmProductId') + "')"]]></FILTER_EXPRESSION>
+<!--DFC496029B4743E49D78E6B4414BDAF2-->  <OBCLKER_TEMPLATE_ID><![CDATA[9314DE8599AD44E7BFC4CC50699042AB]]></OBCLKER_TEMPLATE_ID>
+<!--DFC496029B4743E49D78E6B4414BDAF2-->  <ISACTIVE><![CDATA[Y]]></ISACTIVE>
+<!--DFC496029B4743E49D78E6B4414BDAF2-->  <SUGGESTIONTEXTMATCHSTYLE><![CDATA[substring]]></SUGGESTIONTEXTMATCHSTYLE>
+<!--DFC496029B4743E49D78E6B4414BDAF2-->  <POPUPTEXTMATCHSTYLE><![CDATA[substring]]></POPUPTEXTMATCHSTYLE>
+<!--DFC496029B4743E49D78E6B4414BDAF2-->  <CUSTOM_QUERY><![CDATA[N]]></CUSTOM_QUERY>
+<!--DFC496029B4743E49D78E6B4414BDAF2--></OBUISEL_SELECTOR>
+
 <!--E1F081829D324B20B7214E7018B589C4--><OBUISEL_SELECTOR>
 <!--E1F081829D324B20B7214E7018B589C4-->  <OBUISEL_SELECTOR_ID><![CDATA[E1F081829D324B20B7214E7018B589C4]]></OBUISEL_SELECTOR_ID>
 <!--E1F081829D324B20B7214E7018B589C4-->  <AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID>
@@ -1150,6 +1214,22 @@
 <!--F42A1DD1B941461EB3B9AD07A534D91E-->  <CUSTOM_QUERY><![CDATA[Y]]></CUSTOM_QUERY>
 <!--F42A1DD1B941461EB3B9AD07A534D91E--></OBUISEL_SELECTOR>
 
+<!--F879D55C4CEA4364BEC07ED3C002F230--><OBUISEL_SELECTOR>
+<!--F879D55C4CEA4364BEC07ED3C002F230-->  <OBUISEL_SELECTOR_ID><![CDATA[F879D55C4CEA4364BEC07ED3C002F230]]></OBUISEL_SELECTOR_ID>
+<!--F879D55C4CEA4364BEC07ED3C002F230-->  <AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID>
+<!--F879D55C4CEA4364BEC07ED3C002F230-->  <AD_ORG_ID><![CDATA[0]]></AD_ORG_ID>
+<!--F879D55C4CEA4364BEC07ED3C002F230-->  <AD_MODULE_ID><![CDATA[0]]></AD_MODULE_ID>
+<!--F879D55C4CEA4364BEC07ED3C002F230-->  <NAME><![CDATA[Operative UOM Selector]]></NAME>
+<!--F879D55C4CEA4364BEC07ED3C002F230-->  <AD_REFERENCE_ID><![CDATA[EB56DAD76DFB4001B6CE960B92A979FA]]></AD_REFERENCE_ID>
+<!--F879D55C4CEA4364BEC07ED3C002F230-->  <AD_TABLE_ID><![CDATA[146]]></AD_TABLE_ID>
+<!--F879D55C4CEA4364BEC07ED3C002F230-->  <WHERECLAUSE><![CDATA[e.id in (select p.uOM.id from Product p where p.id = @M_Product_ID@) or e.id in (select a.uOM.id from ProductAUM a where a.product.id = @M_Product_ID@)]]></WHERECLAUSE>
+<!--F879D55C4CEA4364BEC07ED3C002F230-->  <OBCLKER_TEMPLATE_ID><![CDATA[9314DE8599AD44E7BFC4CC50699042AB]]></OBCLKER_TEMPLATE_ID>
+<!--F879D55C4CEA4364BEC07ED3C002F230-->  <ISACTIVE><![CDATA[Y]]></ISACTIVE>
+<!--F879D55C4CEA4364BEC07ED3C002F230-->  <SUGGESTIONTEXTMATCHSTYLE><![CDATA[substring]]></SUGGESTIONTEXTMATCHSTYLE>
+<!--F879D55C4CEA4364BEC07ED3C002F230-->  <POPUPTEXTMATCHSTYLE><![CDATA[substring]]></POPUPTEXTMATCHSTYLE>
+<!--F879D55C4CEA4364BEC07ED3C002F230-->  <CUSTOM_QUERY><![CDATA[N]]></CUSTOM_QUERY>
+<!--F879D55C4CEA4364BEC07ED3C002F230--></OBUISEL_SELECTOR>
+
 <!--FA5BC3AD909645C3BCF9384AE635009A--><OBUISEL_SELECTOR>
 <!--FA5BC3AD909645C3BCF9384AE635009A-->  <OBUISEL_SELECTOR_ID><![CDATA[FA5BC3AD909645C3BCF9384AE635009A]]></OBUISEL_SELECTOR_ID>
 <!--FA5BC3AD909645C3BCF9384AE635009A-->  <AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID>
--- a/src/org/openbravo/common/actionhandler/OrderCreatePOLines.java	Fri Nov 11 10:01:28 2016 +0100
+++ b/src/org/openbravo/common/actionhandler/OrderCreatePOLines.java	Fri Nov 11 10:06:34 2016 +0100
@@ -121,13 +121,17 @@
         newOrderLine.setAttributeSetValue(product.getAttributeSetValue());
       }
       UOM uom = OBDal.getInstance().get(UOM.class, selectedLine.get("product$uOM"));
+      UOM aum = OBDal.getInstance().get(UOM.class, selectedLine.get("aum"));
 
       newOrderLine.setProduct(product);
 
       newOrderLine.setUOM(uom);
+      newOrderLine.setOperativeUOM(aum);
       // Ordered Quantity = returned quantity.
       BigDecimal qtyOrdered = new BigDecimal(selectedLine.getString("orderedQuantity"));
+      BigDecimal aumQty = new BigDecimal(selectedLine.getString("aumQuantity"));
       newOrderLine.setOrderedQuantity(qtyOrdered);
+      newOrderLine.setOperativeQuantity(aumQty);
 
       List<Object> parameters = new ArrayList<Object>();
       parameters.add(product.getId());
--- a/src/org/openbravo/erpCommon/ad_actionButton/CopyFromInvoice.java	Fri Nov 11 10:01:28 2016 +0100
+++ b/src/org/openbravo/erpCommon/ad_actionButton/CopyFromInvoice.java	Fri Nov 11 10:06:34 2016 +0100
@@ -43,6 +43,7 @@
 import org.openbravo.erpCommon.utility.SequenceIdData;
 import org.openbravo.erpCommon.utility.Utility;
 import org.openbravo.financial.FinancialUtils;
+import org.openbravo.materialmgmt.CentralBroker;
 import org.openbravo.model.common.businesspartner.Location;
 import org.openbravo.model.common.invoice.Invoice;
 import org.openbravo.model.common.invoice.InvoiceLine;
@@ -133,6 +134,21 @@
           String strWharehouse = Utility.getContext(this, vars, "#M_Warehouse_ID", strWindowId);
           String strIsSOTrx = Utility.getContext(this, vars, "isSOTrx", strWindowId);
 
+          String propertyValue = CentralBroker.getInstance().isUomManagementEnabled();
+          if (propertyValue.equalsIgnoreCase("Y") && data[i].mProductUomId.isEmpty()) {
+            if (data[i].cAum.isEmpty() && data[i].aumqty.isEmpty()) {
+              String defaultAum = CentralBroker.getInstance().getDefaultAUMForDocument(
+                  data[i].productId, invToCopy.getTransactionDocument().getId());
+              data[i].aumqty = data[i].qtyinvoiced;
+              data[i].cAum = defaultAum;
+              if (!defaultAum.equals(data[i].cUomId)) {
+                data[i].qtyinvoiced = CentralBroker.getInstance()
+                    .getConvertedQty(data[i].productId, new BigDecimal(data[i].aumqty), defaultAum)
+                    .toString();
+              }
+            }
+          }
+
           String strCTaxID = Tax.get(this, data[i].productId, dataInvoice[0].dateinvoiced,
               dataInvoice[0].adOrgId, strWharehouse, dataInvoice[0].cBpartnerLocationId,
               dataInvoice[0].cBpartnerLocationId, dataInvoice[0].cProjectId,
@@ -206,10 +222,10 @@
                 dataInvoice[0].cBpartnerLocationId);
           }
           CopyFromInvoiceData.insert(conn, this, strSequence, strKey, dataInvoice[0].adClientId,
-              dataInvoice[0].adOrgId, vars.getUser(), priceList.toString(), priceActual.toString(),
+              dataInvoice[0].adOrgId, vars.getUser(), data[i].qtyinvoiced, priceList.toString(), priceActual.toString(),
               priceLimit.toString(), lineNetAmt.toString(), strCTaxID, priceGross.toString(),
               lineGrossAmt.toString(), priceListGross.toString(), priceStdGross.toString(),
-              data[i].cInvoicelineId);
+              data[i].cAum, data[i].aumqty, data[i].cInvoicelineId);
 
           // Copy accounting dimensions
           CopyFromInvoiceData.insertAcctDimension(conn, this, dataInvoice[0].adClientId,
--- a/src/org/openbravo/erpCommon/ad_actionButton/CopyFromInvoice_data.xsql	Fri Nov 11 10:01:28 2016 +0100
+++ b/src/org/openbravo/erpCommon/ad_actionButton/CopyFromInvoice_data.xsql	Fri Nov 11 10:06:34 2016 +0100
@@ -39,7 +39,9 @@
         '' AS ISSOTRX, '' AS TAXDATE,
         '' AS PRICESTD, '' AS VALIDFROM,
         '' AS StdPrecision, '' AS PricePrecision, '' AS EnforcePriceLimit,
-        C_INVOICELINE.ACCOUNT_ID AS ACCOUNT_ID
+        C_INVOICELINE.ACCOUNT_ID AS ACCOUNT_ID,
+        C_AUM, AUMQTY,
+        M_PRODUCT_UOM_ID
         FROM C_INVOICELINE 
         LEFT JOIN C_INVOICE ON C_INVOICE.C_INVOICE_ID = C_INVOICELINE.C_INVOICE_ID
         LEFT OUTER JOIN C_INVOICE_DISCOUNT ON C_INVOICELINE.C_INVOICE_DISCOUNT_ID = C_INVOICE_DISCOUNT.C_INVOICE_DISCOUNT_ID
@@ -67,11 +69,12 @@
             PRICESTD, ACCOUNT_ID,FINANCIAL_INVOICE_LINE,
             gross_unit_price, line_gross_amount, grosspricelist, grosspricestd,
             isdeferred, defplantype, periodnumber, c_period_id,
-            C_PROJECT_ID, A_ASSET_ID, C_COSTCENTER_ID, USER1_ID, USER2_ID
+            C_PROJECT_ID, A_ASSET_ID, C_COSTCENTER_ID, USER1_ID, USER2_ID,
+            C_AUM, AUMQTY
         )
         SELECT ?, ?, ?, ?, 'Y', now(), ?, now(), ?,
         (SELECT COALESCE(MAX(LINE),0)+10 FROM C_InvoiceLine WHERE C_Invoice_ID = ?), l.DESCRIPTION, l.M_PRODUCT_ID,
-        l.QTYINVOICED, TO_NUMBER(?), TO_NUMBER(?), TO_NUMBER(?), TO_NUMBER(?), l.C_CHARGE_ID, l.CHARGEAMT, l.C_UOM_ID, ?,
+        TO_NUMBER(?), TO_NUMBER(?), TO_NUMBER(?), TO_NUMBER(?), TO_NUMBER(?), l.C_CHARGE_ID, l.CHARGEAMT, l.C_UOM_ID, ?,
         l.S_RESOURCEASSIGNMENT_ID, l.TAXAMT, l.M_ATTRIBUTESETINSTANCE_ID, l.ISDESCRIPTION, l.QUANTITYORDER, l.M_PRODUCT_UOM_ID,
         l.PRICESTD, l.ACCOUNT_ID,l.FINANCIAL_INVOICE_LINE,
         TO_NUMBER(?), TO_NUMBER(?), TO_NUMBER(?), TO_NUMBER(?),
@@ -80,7 +83,8 @@
         COALESCE(l.A_Asset_ID, inv.A_Asset_ID) AS A_Asset_ID,
         COALESCE(l.C_Costcenter_ID, inv.C_Costcenter_ID) AS C_Costcenter_ID,
         COALESCE(l.User1_ID, inv.User1_ID) AS User1_ID,
-        COALESCE(l.User2_ID, inv.User2_ID) AS User2_ID
+        COALESCE(l.User2_ID, inv.User2_ID) AS User2_ID,
+        ?, TO_NUMBER(?)
         FROM C_INVOICELINE l, C_Invoice inv
         WHERE C_INVOICELINE_ID = ? 
         AND l.C_Invoice_ID = inv.C_Invoice_ID
@@ -93,6 +97,7 @@
     <Parameter name="adUserId"/>
     <Parameter name="adUserId"/>
     <Parameter name="cInvoiceId"/>
+    <Parameter name="qtyInvoiced"/>
     <Parameter name="priceList"/>
     <Parameter name="priceActual"/>
     <Parameter name="priceLimit"/>
@@ -102,6 +107,8 @@
     <Parameter name="amtGross"/>
     <Parameter name="priceListGros"/>
     <Parameter name="priceStdGross"/>
+    <Parameter name="cAum"/>
+    <Parameter name="aumQty"/>
     <Parameter name="cInvoicelineId"/>
   </SqlMethod>
   <SqlMethod name="insertAcctDimension" type="preparedStatement" connection="true" return="rowCount">
@@ -128,12 +135,14 @@
       <![CDATA[
         SELECT I.AD_ORG_ID,I.AD_CLIENT_ID,I.C_BPartner_Location_ID,I.DateInvoiced,I.C_Project_ID,
          I.C_Bpartner_ID,I.C_Currency_ID,I.M_Pricelist_ID,COALESCE(MAX(IL.Line),0) AS LINE,I.IsSOTrx AS ISSOTRX, I.TaxDate,
-         IL.PRICELIST, IL.PRICEACTUAL, IL.PRICELIMIT, IL.LINENETAMT
+         IL.PRICELIST, IL.PRICEACTUAL, IL.PRICELIMIT, IL.LINENETAMT,
+         C_AUM, AUMQTY
          FROM C_Invoice I LEFT JOIN C_INVOICELINE IL ON I.C_INVOICE_ID = IL.C_INVOICE_ID 
         WHERE I.C_Invoice_ID = ? 
         AND I.ISACTIVE = 'Y'
         GROUP BY I.AD_ORG_ID,I.AD_CLIENT_ID,I.C_BPartner_Location_ID,I.DateInvoiced,I.C_Project_ID,
-         I.C_Bpartner_ID,I.C_Currency_ID,I.M_Pricelist_ID,I.IsSOTrx, I.TaxDate,IL.PRICELIST, IL.PRICEACTUAL, IL.PRICELIMIT, IL.LINENETAMT
+         I.C_Bpartner_ID,I.C_Currency_ID,I.M_Pricelist_ID,I.IsSOTrx, I.TaxDate,IL.PRICELIST, IL.PRICEACTUAL, IL.PRICELIMIT, IL.LINENETAMT,
+         C_AUM, AUMQTY
       ]]>
     </Sql>
     <Parameter name="cInvoiceId"/>
--- a/src/org/openbravo/erpCommon/ad_actionButton/CopyFromOrder.html	Fri Nov 11 10:01:28 2016 +0100
+++ b/src/org/openbravo/erpCommon/ad_actionButton/CopyFromOrder.html	Fri Nov 11 10:06:34 2016 +0100
@@ -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-2012 Openbravo SLU 
+ * All portions are Copyright (C) 2001-2016 Openbravo SLU 
  * All Rights Reserved. 
  * Contributor(s):  ______________________________________.
  ************************************************************************
@@ -64,13 +64,29 @@
   } else if ( !document.frmMain.elements["inpLastpriceso" + value].enable ){
     document.frmMain.elements["inpLastpriceso" + value].className += " readonly";
   }
-  document.frmMain.elements["inpquantity" + value].disabled = !enable;
-  if ( !document.frmMain.elements["inpquantity" + value].disabled )
-  {
-    document.frmMain.elements["inpquantity" + value].className = document.frmMain.elements["inpquantity" + value].className.replace(' readonly', '');
-  } else if ( !document.frmMain.elements["inpquantity" + value].enable ){
-    document.frmMain.elements["inpquantity" + value].className += " readonly";
+  if(document.frmMain.elements["inpUomEnabled"].value == 'Y'){
+	document.frmMain.elements["inpaumquantity" + value].disabled = !enable;
+    if ( !document.frmMain.elements["inpaumquantity" + value].disabled ){
+      document.frmMain.elements["inpaumquantity" + value].className = document.frmMain.elements["inpaumquantity" + value].className.replace(' readonly', '');
+    } else if ( !document.frmMain.elements["inpaumquantity" + value].enable ){
+      document.frmMain.elements["inpaumquantity" + value].className += " readonly";
+    } 
+    document.frmMain.elements["inpcAUMId" + value].disabled = !enable;
+    if ( !document.frmMain.elements["inpcAUMId" + value].disabled ){
+        document.frmMain.elements["inpcAUMId" + value].className = document.frmMain.elements["inpcAUMId" + value].className.replace(' readonly', '');
+      } else if ( !document.frmMain.elements["inpcAUMId" + value].enable ){
+        document.frmMain.elements["inpcAUMId" + value].className += " readonly";
+      } 
+  }else{
+    document.frmMain.elements["inpquantity" + value].disabled = !enable;
+    if ( !document.frmMain.elements["inpquantity" + value].disabled )
+    {
+      document.frmMain.elements["inpquantity" + value].className = document.frmMain.elements["inpquantity" + value].className.replace(' readonly', '');
+    } else if ( !document.frmMain.elements["inpquantity" + value].enable ){
+      document.frmMain.elements["inpquantity" + value].className += " readonly";
+    }
   }
+  
   return true;
 }
 
@@ -82,7 +98,9 @@
 	  var numRow = frm.elements[i].id.slice("CheckNum".length);
 	  var lp =document.getElementsByName('inpLastpriceso'+ numRow)[0];
 	  var qty = document.getElementsByName('inpquantity'+ numRow)[0];
-	  if ((!isValidNumber(lp, 'inpLastpriceso', 'lpinvalid')) || (!isValidNumber(qty, 'inpquantity', 'qtyinvalid'))) {
+	  var aumqty = document.getElementsByName('inpaumquantity'+ numRow)[0];
+	  if ((!isValidNumber(lp, 'inpLastpriceso', 'lpinvalid')) || (!isValidNumber(qty, 'inpquantity', 'qtyinvalid')) ||
+			  (!isValidNumber(aumqty, 'inpaumquantity', 'aumqtyinvalid'))) {
 	    setWindowElementFocus(frm.elements[i]);
 	 	showJSMessage('APRM_NotValidNumber');
 	 	return false;
@@ -172,6 +190,25 @@
       return true;
     } 
   </script>  
+  
+  <script language="JavaScript" type="text/javascript">
+    function updateQty(selKey) {
+      var frm = document.frmMain;
+      if(frm.elements["inpcUOMId" + selKey].value != frm.elements["inpcAUMId" + selKey].value){
+        callback = function (response, data, request) {
+    	  frm.elements["inpquantity" + selKey].value = data.qty;
+   	    };
+   	
+        window.parent.parent.OB.RemoteCallManager.call('org.openbravo.common.actionhandler.GetConvertedQtyActionHandler', {
+          mProductId: frm.elements["inpmProductId" + selKey].value,
+          qty: frm.elements["inpaumquantity" + selKey].value,
+          toUOM: frm.elements["inpcAUMId" + selKey].value
+        }, {}, callback);
+      }else {
+    	frm.elements["inpquantity" + selKey].value = frm.elements["inpaumquantity" + selKey].value;
+      }
+    }
+  </script>
 </head>
 
 
@@ -183,6 +220,7 @@
   <input type="hidden" name="inpWindowId" value="" id="paramWindowId"/>
   <input type="hidden" name="inpTabId" value="" id="paramTabId"/>
   <input type="hidden" name="inpissotrx" value="" id="paramisSOTrx"/>
+  <input type="hidden" name="inpUomEnabled" value="xx" id="paramUomEnabled"/>
 
   <div class="Popup_ContentPane_CircleLogo">
     <div class="Popup_WindowLogo">
@@ -456,6 +494,8 @@
                       <th width="9%"  class="DataGrid_Header_Cell">Last price</th>
                       <th width="7%"  class="DataGrid_Header_Cell">Quantity</th>
                       <th width="13%" class="DataGrid_Header_Cell">UOM</th>
+                      <th width="7%"  class="DataGrid_Header_Cell" id="paramAumQtyVisible" style="display:xx;">Quantity in Alternative UOM</th>                      
+                      <th width="13%" class="DataGrid_Header_Cell" id="paramAumVisible" style="display:xx;">Alternative UOM</th>                      
                       <th width="11%" class="DataGrid_Header_Cell">Tax</th>
                     </tr>
                     <div id="sectionDetail">
@@ -493,6 +533,22 @@
                           		</table>
                        		 </span>
                         </td><td width="13%" class="DataGrid_Body_Cell" onmouseover="HoverCell(this);" onmouseout="unHoverCell(this);"><input type="hidden" name="inpcUOMIdxx" id="fieldUomid" value=""/><span id="fieldUomsymbol">xxKg</span></td>
+                        <td id="paramAumQtyVisible" style="display:xx" width="7%" class="DataGrid_Body_Cell" onmouseover="HoverCell(this);" onmouseout="unHoverCell(this);"><input class="dojoValidateValid readonly" id="fieldAumQty" style="font-weight: normal;" name="inpaumquantityxx" type="text" size="5" value="0" outputformat="euroEdition" onfocus="numberInputEvent('onfocus', this);" onblur="numberInputEvent('onblur', this);" onkeydown="numberInputEvent('onkeydown', this, event);" onchange="isValidNumber(this, 'inpaumquantity','aumqtyinvalid');"  onkeyup="updateQty('yy');" disabled="" />
+                         	<span class="TextBox_MsgContainer_span" id="aumqtyinvalidxx" style="display: none;">
+                       		 	<table class="TextBox_MsgContainer_table">
+                           			 <tbody><tr class="TextBox_MsgContainer_tr">
+                           			   <td class="TextBox_MsgContainer_td"><div class="TextBox_MsgContainer_div"></div></td><td></td>
+                           			 </tr>
+                           			 <tr>
+                             			 <td class="invalid" colspan="2"><div name="invalidText" id="aumqtyinvalidText" class="TextBox_MsgContainer_div2">* The value entered is not valid.</div></td>
+                           			 </tr>
+                          			</tbody>
+                          		</table>
+                       		 </span>
+                        </td>
+                        <td id="paramAumVisible" style="display:xx;" width="13%" class="DataGrid_Body_Cell" onmouseover="HoverCell(this);" onmouseout="unHoverCell(this);">
+                          <select class="DataGrid_Body_Cell" name="inpcAUMIdxx" id="fieldAumCombo" disabled="true" onchange="updateQty('yy');return true;"><div id="reportAUM_ID"></div></select>
+                        </td>
                         <td width="11%" class="DataGrid_Body_Cell" onmouseover="HoverCell(this);" onmouseout="unHoverCell(this);"><input type="hidden" name="inpcTaxIdxx" id="fieldTaxid" value=""/><span id="fieldNametax">xx16%</span></td>
                       </tr>
                     </div>
--- a/src/org/openbravo/erpCommon/ad_actionButton/CopyFromOrder.java	Fri Nov 11 10:01:28 2016 +0100
+++ b/src/org/openbravo/erpCommon/ad_actionButton/CopyFromOrder.java	Fri Nov 11 10:06:34 2016 +0100
@@ -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-2014 Openbravo SLU 
+ * All portions are Copyright (C) 2001-2016 Openbravo SLU 
  * All Rights Reserved. 
  * Contributor(s):  ______________________________________.
  ************************************************************************
@@ -41,6 +41,7 @@
 import org.openbravo.erpCommon.utility.SequenceIdData;
 import org.openbravo.erpCommon.utility.Utility;
 import org.openbravo.financial.FinancialUtils;
+import org.openbravo.materialmgmt.CentralBroker;
 import org.openbravo.model.common.order.Order;
 import org.openbravo.model.common.plm.Product;
 import org.openbravo.model.pricing.pricelist.ProductPrice;
@@ -135,6 +136,20 @@
         String strcTaxId = vars.getStringParameter("inpcTaxId" + strRownum);
         String strcUOMId = vars.getStringParameter("inpcUOMId" + strRownum);
         String strCOrderlineID = SequenceIdData.getUUID();
+        
+        String propertyValue = CentralBroker.getInstance().isUomManagementEnabled();
+        String strAumQty = null;
+        String strcAumId = null;
+        if (propertyValue.equalsIgnoreCase("Y")) {
+          strAumQty = vars.getNumericParameter("inpaumquantity" + strRownum);
+          strcAumId = vars.getStringParameter("inpcAUMId" + strRownum);
+          strQty = strAumQty;
+          if (!strcAumId.equals(strcUOMId)) {
+            strQty = CentralBroker.getInstance()
+                .getConvertedQty(strmProductId, new BigDecimal(strAumQty), strcAumId).toString();
+          }
+        }
+
         priceStd = new BigDecimal(CopyFromOrderData.getOffersStdPrice(this,
             orderData[0].cBpartnerId, strLastpriceso, strmProductId, orderData[0].dateordered,
             strQty, orderData[0].mPricelistId, strKey));
@@ -207,7 +222,7 @@
               netPriceList.toString(), priceActual.toString(), priceLimit.toString(), priceStd
                   .toString(), discount.toString(), strcTaxId, strmAttributesetinstanceId,
               grossPriceList.toString(), priceGross.toString(), amtGross.toString(), pricestdgross
-                  .toString());
+                  .toString(), strcAumId, strAumQty);
         } catch (ServletException ex) {
           myError = OBMessageUtils.translateError(this, vars, vars.getLanguage(), ex.getMessage());
           releaseRollbackConnection(conn);
@@ -245,10 +260,17 @@
     CopyFromOrderData[] data = CopyFromOrderData.select(this, strBpartner, strmPricelistId,
         dataOrder[0].dateordered, order.getPriceList().isPriceIncludesTax() ? "Y" : "N", strSOTrx,
         dataOrder[0].lastDays.equals("") ? "0" : dataOrder[0].lastDays);
+    CopyFromOrderData[][] dataAUM = new CopyFromOrderData[data.length][];
     for (int i = 0; i < data.length; i++) {
       Product product = OBDal.getInstance().get(Product.class, data[i].mProductId);
       data[i].lastpriceso = (PriceAdjustment.calculatePriceActual(order, product, new BigDecimal(
           data[i].qty), new BigDecimal(data[i].lastpriceso))).toString();
+      
+      dataAUM[i] = CopyFromOrderData.selectAUM(this, data[i].mProductId);
+      if (dataAUM[i].length == 0) {
+        dataAUM[i] = CopyFromOrderData.selectAUMDefault(this, data[i].mProductId,
+            data[i].cDoctypeId);
+      }
     }
     xmlDocument.setParameter("language", "defaultLang=\"" + vars.getLanguage() + "\";");
     xmlDocument.setParameter("directory", "var baseDirectory = \"" + strReplaceWith + "/\";\n");
@@ -287,6 +309,17 @@
     xmlDocument.setParameter("invoicing", strInvoicing);
     xmlDocument.setParameter("bpartnername", dataOrder[0].bpartnername);
 
+    String propertyValue = CentralBroker.getInstance().isUomManagementEnabled();
+    if (propertyValue.equalsIgnoreCase("Y")) {
+      xmlDocument.setParameter("aumQtyVisible", "table-cell");
+      xmlDocument.setParameter("aumVisible", "table-cell");
+      xmlDocument.setParameter("uomEnabled", "Y");
+    } else {
+      xmlDocument.setParameter("aumQtyVisible", "none");
+      xmlDocument.setParameter("aumVisible", "none");
+      xmlDocument.setParameter("uomEnabled", "N");
+    }
+
     BigDecimal invoicing, total, totalAverage;
 
     invoicing = (strInvoicing.equals("") ? ZERO : (new BigDecimal(strInvoicing)));
@@ -299,11 +332,12 @@
       strTotalAverage = totalAverage.toPlainString();
       // int intscale = totalAverage.scale();
     }
-
+    
     xmlDocument.setParameter("totalAverage", strTotalAverage);
 
     xmlDocument.setData("structure1", data);
     xmlDocument.setData("structure2", dataOrder);
+    xmlDocument.setDataArray("reportAUM_ID", "liststructure", dataAUM);
     response.setContentType("text/html; charset=UTF-8");
     PrintWriter out = response.getWriter();
     out.println(xmlDocument.print());
--- a/src/org/openbravo/erpCommon/ad_actionButton/CopyFromOrder.xml	Fri Nov 11 10:01:28 2016 +0100
+++ b/src/org/openbravo/erpCommon/ad_actionButton/CopyFromOrder.xml	Fri Nov 11 10:06:34 2016 +0100
@@ -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-2014 Openbravo SLU 
+ * All portions are Copyright (C) 2001-2016 Openbravo SLU 
  * All Rights Reserved. 
  * Contributor(s):  ______________________________________.
  ************************************************************************
@@ -49,6 +49,11 @@
 <PARAMETER id="messageBoxIDTitle" name="messageTitle" default=""/>
 <PARAMETER id="messageBoxIDMessage" name="messageMessage" default=""/>
 
+
+<PARAMETER id="paramAumQtyVisible" name="aumQtyVisible" attribute="style" replace="xx"/>
+<PARAMETER id="paramAumVisible" name="aumVisible" attribute="style" replace="xx"/>
+<PARAMETER id="paramUomEnabled" name="uomEnabled" attribute="value" replace="xx"/>
+
 <PARAMETER id="param2" name="param2" default="2"/>
 
 <structure name="structure1">
@@ -83,13 +88,25 @@
 <FIELD id="fieldTaxid" attribute="name" replace="xx">rownum</FIELD>
 <FIELD id="fieldNametax" replaceCharacters="html">nametax</FIELD>
 <FIELD id="fieldUomid" attribute="value">cUomId</FIELD>
+ 
+<FIELD id="fieldAum" attribute="value">cAum</FIELD>
+<FIELD id="fieldAumCombo" attribute="name" replace="xx">rownum</FIELD>
+<FIELD id="fieldAumCombo" attribute="onchange" replace="yy">rownum</FIELD>
 <FIELD id="fieldUomid" attribute="name" replace="xx">rownum</FIELD>
 <FIELD id="fieldUomsymbol" replaceCharacters="html">uomsymbol</FIELD>
+<FIELD id="fieldAumsymbol" replaceCharacters="html">cAumsymbol</FIELD>
 <FIELD id="fieldQty" attribute="value" format="euroEdition">qty</FIELD>
 <FIELD id="fieldQty" attribute="name" replace="xx">rownum</FIELD>
+<FIELD id="fieldAumQty" attribute="value" format="euroEdition">aumqty</FIELD>
+<FIELD id="fieldAumQty" attribute="name" replace="xx">rownum</FIELD>
+<FIELD id="fieldAumQty" attribute="onkeyup" replace="yy">rownum</FIELD>
 <FIELD id="lpinvalidxx" attribute="id" replace="xx">rownum</FIELD>
 <FIELD id="qtyinvalidxx" attribute="id" replace="xx">rownum</FIELD>
+<FIELD id="aumqtyinvalidxx" attribute="id" replace="xx">rownum</FIELD>
 
+<SUBREPORT id="reportAUM_ID" name="reportAUM_ID" report="org/openbravo/erpCommon/reference/List">
+  <ARGUMENT name="parameterListSelected"  withId="fieldAum"/>
+</SUBREPORT>
 <SECTION id="sectionDetail"/>
 </structure>
 
--- a/src/org/openbravo/erpCommon/ad_actionButton/CopyFromOrder_data.xsql	Fri Nov 11 10:01:28 2016 +0100
+++ b/src/org/openbravo/erpCommon/ad_actionButton/CopyFromOrder_data.xsql	Fri Nov 11 10:06:34 2016 +0100
@@ -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-2012 Openbravo SLU 
+ * All portions are Copyright (C) 2001-2016 Openbravo SLU 
  * All Rights Reserved. 
  * Contributor(s):  ______________________________________.
  ************************************************************************
@@ -28,7 +28,7 @@
     <Sql>
       <![CDATA[
         SELECT DISTINCT M_PRODUCT_ID, PRODUCTNAME, M_ATTRIBUTESETINSTANCE_ID, DESCRIPTION, CLASS_OFFER,
-        OFFER_NAME, PRICESTD, LASTPRICESO, C_TAX_ID, NAMETAX, C_UOM_ID, UOMSYMBOL, '0' AS QTY, '' AS PRICELIMIT, '' AS PRICELIST, '' AS STDPRECISION, '' AS PRICEPRECISION FROM (
+        OFFER_NAME, PRICESTD, LASTPRICESO, C_TAX_ID, NAMETAX, C_UOM_ID, UOMSYMBOL, C_AUM, '' AS ID, '' AS NAME, C_AUMSYMBOL, C_DOCTYPE_ID, '0' AS AUMQTY, '0' AS QTY, '' AS PRICELIMIT, '' AS PRICELIST, '' AS STDPRECISION, '' AS PRICEPRECISION FROM (
         SELECT CL.M_PRODUCT_ID AS M_PRODUCT_ID, M.NAME AS PRODUCTNAME,
         MA.M_ATTRIBUTESETINSTANCE_ID AS M_ATTRIBUTESETINSTANCE_ID, MA.DESCRIPTION AS DESCRIPTION,
         (CASE coalesce(M_GET_OFFER(TO_DATE(NOW()), ?, CL.M_PRODUCT_ID),'-1') WHEN '-1' THEN '' ELSE '' END) AS CLASS_OFFER,
@@ -57,7 +57,10 @@
                                                                     AND C_ORDER.DOCSTATUS = 'CO') 
                                                                ELSE M_GET_OFFERS_PRICE(TO_DATE(NOW()), ?, CL.M_PRODUCT_ID,M_BOM_PRICESTD(CL.M_PRODUCT_ID, M_GET_PRICELIST_VERSION(?, TO_DATE(?))), 1 /*CL.QTYORDERED what should be here*/, C.M_PRICELIST_ID) 
                                                                 END) AS LASTPRICESO,
-        C_TAX.C_TAX_ID, C_TAX.NAME AS NAMETAX, C_UOM.C_UOM_ID, C_UOM.UOMSYMBOL
+        C_TAX.C_TAX_ID, C_TAX.NAME AS NAMETAX, C_UOM.C_UOM_ID, C_UOM.UOMSYMBOL,
+        (CASE WHEN CL.C_AUM IS NULL THEN M_GET_DEFAULT_AUM_FOR_DOCUMENT(CL.M_PRODUCT_ID, '01360D369B5F473686354A701A6EA559') ELSE CL.C_AUM END) AS C_AUM,
+        (CASE WHEN CL.C_AUM IS NULL THEN (SELECT UOMSYMBOL FROM C_UOM WHERE C_UOM_ID = M_GET_DEFAULT_AUM_FOR_DOCUMENT(CL.M_PRODUCT_ID, '01360D369B5F473686354A701A6EA559')) ELSE (SELECT UOMSYMBOL FROM C_UOM WHERE C_UOM_ID = CL.C_AUM) END) AS C_AUMSYMBOL,
+        C.C_DOCTYPE_ID
         FROM C_ORDER C JOIN m_pricelist pl ON c.m_pricelist_id = pl.m_pricelist_id,
             C_ORDERLINE CL LEFT JOIN (SELECT M_ATTRIBUTESETINSTANCE_ID , DESCRIPTION FROM M_ATTRIBUTESETINSTANCE) MA ON (CL.M_ATTRIBUTESETINSTANCE_ID = MA.M_ATTRIBUTESETINSTANCE_ID), M_PRODUCT M, C_UOM, C_TAX
         WHERE C.C_ORDER_ID = CL.C_ORDER_ID
@@ -72,7 +75,7 @@
         AND C.DATEORDERED >= NOW()-TO_NUMBER(?)
         AND C.DATEORDERED <NOW()+1
         GROUP BY CL.M_PRODUCT_ID, M.NAME, MA.M_ATTRIBUTESETINSTANCE_ID, 
-        MA.DESCRIPTION,M.M_PRODUCT_ID, C_TAX.C_TAX_ID, C_TAX.NAME, C_UOM.C_UOM_ID, C_UOM.UOMSYMBOL, C.M_PRICELIST_ID
+        MA.DESCRIPTION,M.M_PRODUCT_ID, C_TAX.C_TAX_ID, C_TAX.NAME, C_UOM.C_UOM_ID, C_UOM.UOMSYMBOL, C_AUM, C.M_PRICELIST_ID, C.C_DOCTYPE_ID
         )A
        ORDER BY PRODUCTNAME
       ]]>
@@ -124,11 +127,11 @@
         INSERT INTO C_ORDERLINE (C_ORDERLINE_ID, AD_CLIENT_ID, AD_ORG_ID, CREATED, CREATEDBY, UPDATED, UPDATEDBY,
             C_ORDER_ID, LINE, C_BPARTNER_ID, C_BPARTNER_LOCATION_ID, DATEORDERED, DATEPROMISED, M_PRODUCT_ID, M_WAREHOUSE_ID, C_UOM_ID,
             QTYORDERED, C_CURRENCY_ID, PRICELIST, PRICEACTUAL, PRICELIMIT, PRICESTD, DISCOUNT, C_TAX_ID, M_ATTRIBUTESETINSTANCE_ID,
-            grosspricelist, gross_unit_price, line_gross_amount, grosspricestd
+            grosspricelist, gross_unit_price, line_gross_amount, grosspricestd, C_AUM, AUMQTY
         ) VALUES (?,?,?,NOW(),?,NOW(),?,
                 ?,(SELECT (coalesce(Max(Line),0))+10 FROM C_OrderLine WHERE C_Order_id = ?),?,?,TO_DATE(?),TO_DATE(?),?,?,?,
                 TO_NUMBER(?),?,TO_NUMBER(?),TO_NUMBER(?),TO_NUMBER(?),TO_NUMBER(?),TO_NUMBER(?), ?, ?,
-            TO_NUMBER(?), TO_NUMBER(?), TO_NUMBER(?), TO_NUMBER(?)
+            TO_NUMBER(?), TO_NUMBER(?), TO_NUMBER(?), TO_NUMBER(?), ?, TO_NUMBER(?)
         )
       ]]>
     </Sql>
@@ -159,5 +162,32 @@
     <Parameter name="priceGross"/>
     <Parameter name="amtGross"/>
     <Parameter name="pricestdgross"/>
+    <Parameter name="cAum"/>
+    <Parameter name="aumQty"/>
+  </SqlMethod>
+  <SqlMethod name="selectAUM" type="preparedStatement" return="multiple">
+    <SqlMethodComment></SqlMethodComment>
+    <Sql>
+      <![CDATA[
+        SELECT M.C_UOM_ID AS ID, C.NAME AS NAME
+        FROM M_PRODUCT_AUM M, C_UOM C
+        WHERE M.M_PRODUCT_ID = ?
+        AND M.C_UOM_ID = C.C_UOM_ID
+      ]]>
+    </Sql>
+    <Parameter name="productId"/>
+  </SqlMethod>
+  <SqlMethod name="selectAUMDefault" type="preparedStatement" return="multiple">
+    <SqlMethodComment></SqlMethodComment>
+    <Sql>
+      <![CDATA[
+        SELECT M_GET_DEFAULT_AUM_FOR_DOCUMENT(?, ?) AS ID, 
+          (SELECT UOMSYMBOL FROM C_UOM WHERE C_UOM_ID = M_GET_DEFAULT_AUM_FOR_DOCUMENT(?, ?)) AS NAME FROM DUAL
+      ]]>
+    </Sql>
+    <Parameter name="productId"/>
+    <Parameter name="docTypeId"/>
+    <Parameter name="productId"/>
+    <Parameter name="docTypeId"/>
   </SqlMethod>
 </SqlClass>
--- a/src/org/openbravo/erpCommon/ad_actionButton/CopyFromPOOrder.java	Fri Nov 11 10:01:28 2016 +0100
+++ b/src/org/openbravo/erpCommon/ad_actionButton/CopyFromPOOrder.java	Fri Nov 11 10:06:34 2016 +0100
@@ -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-2014 Openbravo SLU 
+ * All portions are Copyright (C) 2001-2016 Openbravo SLU 
  * All Rights Reserved. 
  * Contributor(s):  ______________________________________.
  ************************************************************************
@@ -35,13 +35,16 @@
 import org.openbravo.base.secureApp.VariablesSecureApp;
 import org.openbravo.dal.core.OBContext;
 import org.openbravo.dal.service.OBDal;
+import org.openbravo.erpCommon.businessUtility.Preferences;
 import org.openbravo.erpCommon.businessUtility.Tax;
 import org.openbravo.erpCommon.reference.PInstanceProcessData;
 import org.openbravo.erpCommon.utility.DateTimeData;
 import org.openbravo.erpCommon.utility.OBError;
+import org.openbravo.erpCommon.utility.PropertyException;
 import org.openbravo.erpCommon.utility.SequenceIdData;
 import org.openbravo.erpCommon.utility.Utility;
 import org.openbravo.financial.FinancialUtils;
+import org.openbravo.materialmgmt.CentralBroker;
 import org.openbravo.model.ad.process.ProcessInstance;
 import org.openbravo.model.common.order.Order;
 import org.openbravo.service.db.CallProcess;
@@ -117,6 +120,23 @@
       }
       int lineCount = 0;
       for (i = 0; data != null && i < data.length; i++) {
+
+        String propertyValue = CentralBroker.getInstance().isUomManagementEnabled();
+        if (propertyValue.equalsIgnoreCase("Y") && data[i].mProductUomId.isEmpty()) {
+          if (data[i].cAum.isEmpty() && data[i].aumqty.isEmpty()) {
+            String defaultAum = CentralBroker.getInstance().getDefaultAUMForDocument(
+                data[i].mProductId, order.getTransactionDocument().getId());
+            data[i].aumqty = data[i].qtyordered;
+            data[i].cAum = defaultAum;
+            data[i].mProductUomId = null;
+            if (!defaultAum.equals(data[i].cUomId)) {
+              data[i].qtyordered = CentralBroker.getInstance()
+                  .getConvertedQty(data[i].mProductId, new BigDecimal(data[i].aumqty), defaultAum)
+                  .toString();
+            }
+          }
+        }
+
         CopyFromPOOrderData[] data3 = CopyFromPOOrderData.selectPriceForProduct(this,
             data[i].mProductId,
             orderData[0].mPricelistId.equals("") ? CopyFromPOOrderData.defaultPriceList(this)
@@ -234,7 +254,8 @@
                 strPriceLimit, strCTaxID, strDiscount, data[i].mProductUomId, data[i].orderline,
                 data[i].mAttributesetinstanceId, strGrossPriceList, strGrossUnitPrice,
                 strGrossAmount, strGrossBaseUnitPrice, data[i].cProjectId, data[i].user1Id,
-                data[i].user2Id, data[i].cCostcenterId, data[i].aAssetId);
+                data[i].user2Id, data[i].cCostcenterId, data[i].aAssetId, data[i].cAum,
+                data[i].aumqty);
             lineCount++;
             if (data[i].explode.equals("Y")) {
               strOrderLineList.add(strCOrderlineID);
--- a/src/org/openbravo/erpCommon/ad_actionButton/CopyFromPOOrder_data.xsql	Fri Nov 11 10:01:28 2016 +0100
+++ b/src/org/openbravo/erpCommon/ad_actionButton/CopyFromPOOrder_data.xsql	Fri Nov 11 10:06:34 2016 +0100
@@ -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-2014 Openbravo SLU 
+ * All portions are Copyright (C) 2001-2016 Openbravo SLU 
  * All Rights Reserved. 
  * Contributor(s):  ______________________________________.
  ************************************************************************
@@ -30,7 +30,7 @@
         '' as stdprecision, '' as priceprecision, '' as enforcepricelimit, '' as pricelist, '' as pricelimit, '' as validfrom,
         '' AS DESCRIPTION, '' AS PRICESTD, '' AS M_OFFER_ID, '' as orderline, O.DATEPROMISED AS DATEPROMISED, O.DATEORDERED AS DATEORDERED,
         O.ISSOTRX AS ISSOTRX, '' AS M_ATTRIBUTESETINSTANCE_ID, '' as USER1_ID, '' as USER2_ID,
-        '' as C_COSTCENTER_ID, '' as A_ASSET_ID, '' AS EXPLODE, '' AS BOM_PARENT_ID
+        '' as C_COSTCENTER_ID, '' as A_ASSET_ID, '' AS EXPLODE, '' AS BOM_PARENT_ID, '' AS C_AUM, '' AS AUMQTY
         FROM C_ORDER O LEFT JOIN C_ORDERLINE OL ON O.C_ORDER_ID = OL.C_ORDER_ID
         WHERE O.C_ORDER_ID = ?
         GROUP BY O.C_BPARTNER_ID, O.C_BPARTNER_LOCATION_ID, O.M_WAREHOUSE_ID, O.C_CURRENCY_ID, O.C_PROJECT_ID,
@@ -50,7 +50,8 @@
         COALESCE(OL.USER1_ID, O.USER1_ID) AS USER1_ID,
         COALESCE(OL.USER2_ID, O.USER2_ID) AS USER2_ID,
         COALESCE(OL.C_COSTCENTER_ID, O.C_COSTCENTER_ID) AS C_COSTCENTER_ID,
-        COALESCE(OL.A_ASSET_ID, O.A_ASSET_ID) AS A_ASSET_ID, OL.EXPLODE, OL.BOM_PARENT_ID
+        COALESCE(OL.A_ASSET_ID, O.A_ASSET_ID) AS A_ASSET_ID, OL.EXPLODE, OL.BOM_PARENT_ID,
+        C_AUM, AUMQTY
         FROM C_ORDERLINE OL, C_ORDER O
         WHERE OL.C_ORDER_ID = ?
               AND OL.C_ORDER_ID = O.C_ORDER_ID
@@ -72,7 +73,7 @@
         C_CURRENCY_ID, PRICELIST, PRICEACTUAL, 
         PRICELIMIT, C_TAX_ID, DISCOUNT, M_PRODUCT_UOM_ID, PRICESTD, M_OFFER_ID, REF_ORDERLINE_ID, M_ATTRIBUTESETINSTANCE_ID,
           GROSSPRICELIST, GROSS_UNIT_PRICE, LINE_GROSS_AMOUNT, grosspricestd,
-          C_PROJECT_ID, USER1_ID, USER2_ID, C_COSTCENTER_ID, A_ASSET_ID) 
+          C_PROJECT_ID, USER1_ID, USER2_ID, C_COSTCENTER_ID, A_ASSET_ID, C_AUM, AUMQTY) 
         VALUES 
           (?,?,?,TO_DATE(NOW()),?,TO_DATE(NOW()),?,
            ?,TO_NUMBER(?),?,?,
@@ -81,7 +82,7 @@
            ?,TO_NUMBER(?),M_GET_OFFERS_PRICE(TO_DATE(now()), ?, ?, TO_NUMBER(?), TO_NUMBER(?), ?),
            TO_NUMBER(?),?,TO_NUMBER(?),?,TO_NUMBER(?),M_GET_OFFER(TO_DATE(now()), ?, ?),?,?,
            TO_NUMBER(?),TO_NUMBER(?),TO_NUMBER(?), TO_NUMBER(?),
-           ?, ?, ?, ?, ?)
+           ?, ?, ?, ?, ?, ?, TO_NUMBER(?))
       ]]>
     </Sql>
     <Parameter name="cOrderlineId"/>
@@ -126,6 +127,8 @@
     <Parameter name="user2Id"/>
     <Parameter name="cCostcenterId"/>
     <Parameter name="aAssetId"/>
+    <Parameter name="cAum"/>
+    <Parameter name="aumQty"/>
   </SqlMethod>
   <SqlMethod name="cBPartnerLocationId" type="preparedStatement" return="string">
     <SqlMethodComment>Names of the columns of the fields of a tab</SqlMethodComment>
--- a/src/org/openbravo/erpCommon/ad_actionButton/CreateFrom.java	Fri Nov 11 10:01:28 2016 +0100
+++ b/src/org/openbravo/erpCommon/ad_actionButton/CreateFrom.java	Fri Nov 11 10:06:34 2016 +0100
@@ -47,6 +47,7 @@
 import org.openbravo.erpCommon.utility.SequenceIdData;
 import org.openbravo.erpCommon.utility.Utility;
 import org.openbravo.financial.FinancialUtils;
+import org.openbravo.materialmgmt.CentralBroker;
 import org.openbravo.model.common.invoice.Invoice;
 import org.openbravo.model.common.order.Order;
 import org.openbravo.model.common.order.OrderLine;
@@ -530,6 +531,22 @@
       }
     }
 
+    for (int i = 0; i < data.length; i++) {
+      if (CentralBroker.getInstance().isUomManagementEnabled().equals("Y")) {
+        if (data[i].aumqty.isEmpty()) {
+          data[i].aumqty = data[i].qty;
+          if (!data[i].cAum.equals(data[i].cUomId)) {
+            data[i].qty = CentralBroker.getInstance()
+                .getConvertedQty(data[i].mProductId, new BigDecimal(data[i].aumqty), data[i].cAum)
+                .toString();
+          }
+        }
+        data[i].aumvisible = "table-cell";
+      } else {
+        data[i].aumvisible = "none";
+      }
+    }
+
     xmlDocument.setParameter("directory", "var baseDirectory = \"" + strReplaceWith + "/\";\n");
     xmlDocument.setParameter("language", "defaultLang=\"" + vars.getLanguage() + "\";");
     xmlDocument.setParameter("theme", vars.getTheme());
@@ -593,6 +610,13 @@
       }
     }
 
+    String preferenceUomEnabled = CentralBroker.getInstance().isUomManagementEnabled();
+    if (preferenceUomEnabled.equals("Y")) {
+      xmlDocument.setParameter("aumVisible", "table-cell");
+    } else {
+      xmlDocument.setParameter("aumVisible", "none");
+    }
+
     xmlDocument.setData("structure1", data);
     response.setContentType("text/html; charset=UTF-8");
     final PrintWriter out = response.getWriter();
@@ -739,6 +763,25 @@
     if (isSOTrx.equals("N")) {
       final CreateFromShipmentData[][] dataUOM = new CreateFromShipmentData[data.length][];
 
+      final String strUomPreference = CentralBroker.getInstance().isUomManagementEnabled();
+      boolean strHaveSecUom = false;
+      boolean strHaveAum = false;
+      for (int i = 0; i < data.length; i++) {
+        try {
+          if (!data[i].havesec.equals("0")) {
+            strHaveSecUom = true;
+          }
+          if (strUomPreference.equals("Y") && data[i].havesec.equals("0")) {
+            strHaveAum = true;
+          }
+          if (strHaveSecUom && strHaveAum) {
+            break;
+          }
+        } catch (NullPointerException e) {
+
+        }
+      }
+
       for (int i = 0; i < data.length; i++) {
         // Obtain the specific units for each product
 
@@ -748,12 +791,67 @@
 
         final String strhavesec = data[i].havesec;
 
-        if ("0".equals(strhavesec)) {
+        if (strHaveSecUom && strHaveAum) {
+          // UOM preference is Y and at least one line has secondary UOM
+          if (!data[i].havesec.equals("0")) {
+            data[i].havesec = "text";
+            data[i].haveuompreference = "hidden";
+          }
+          if (strUomPreference.equals("Y") && data[i].havesec.equals("0")) {
+            data[i].haveuompreference = "text";
+            data[i].havesec = "hidden";
+          }
+          xmlDocument.setParameter("uompreference", "");
+          xmlDocument.setParameter("havesecuom", "");
+          if (data[i].cAum.isEmpty() && data[i].aumqty.isEmpty()
+              && data[i].secProductUomId.isEmpty() && data[i].secqty.isEmpty()) {
+            CreateFromShipmentData[] defaultAumData = CreateFromShipmentData.selectAUMDefault(this,
+                data[i].mProductId, data[i].cDoctypeId);
+            String defaultAum = (defaultAumData.length > 0) ? defaultAumData[0].cAum
+                : data[i].cUomId;
+            data[i].aumqty = data[i].qty;
+            data[i].cAum = defaultAum;
+            data[i].aumname = (defaultAumData.length > 0) ? defaultAumData[0].aumname
+                : data[i].uomsymbol;
+            data[i].mProductUomId = null;
+            if (!defaultAum.equals(data[i].cUomId)) {
+              data[i].qty = CentralBroker
+                  .getInstance()
+                  .getConvertedQty(data[i].mProductId, new BigDecimal(data[i].aumqty), data[i].cAum)
+                  .toString();
+            }
+          }
+        } else if (strUomPreference.equals("Y") && "0".equals(strhavesec)) {
+          // UOM preference is Y and no line has secondary UOM
           data[i].havesec = "hidden";
           data[i].havesecuom = "none";
+          data[i].haveuompreference = "text";
+          xmlDocument.setParameter("uompreference", "");
+          xmlDocument.setParameter("havesecuom", "display:none;");
+          if (data[i].cAum.isEmpty() && data[i].aumqty.isEmpty()) {
+            CreateFromShipmentData[] defaultAumData = CreateFromShipmentData.selectAUMDefault(this,
+                data[i].mProductId, data[i].cDoctypeId);
+            String defaultAum = (defaultAumData.length > 0) ? defaultAumData[0].cAum
+                : data[i].cUomId;
+            data[i].aumqty = data[i].qty;
+            data[i].cAum = defaultAum;
+            data[i].aumname = (defaultAumData.length > 0) ? defaultAumData[0].aumname
+                : data[i].uomsymbol;
+            data[i].mProductUomId = null;
+            if (!defaultAum.equals(data[i].cUomId)) {
+              data[i].qty = CentralBroker
+                  .getInstance()
+                  .getConvertedQty(data[i].mProductId, new BigDecimal(data[i].aumqty), data[i].cAum)
+                  .toString();
+            }
+          }
         } else {
+          // UOM preference is N
           data[i].havesec = "text";
-          data[i].havesecuom = "block";
+          data[i].uompreference = "none";
+          data[i].haveuompreference = "hidden";
+          xmlDocument.setParameter("uompreference", "display:none;");
+          xmlDocument.setParameter("havesecuom", "");
         }
       }
       xmlDocument.setDataArray("reportM_Product_Uom_To_ID", "liststructure", dataUOM);
@@ -1535,6 +1633,23 @@
             else
               C_Tax_ID = CreateFromInvoiceData.getTax(this, data[i].cOrderlineId);
 
+            String propertyValue = CentralBroker.getInstance().isUomManagementEnabled();
+            if (propertyValue.equalsIgnoreCase("Y") && data[i].mProductUomId.isEmpty()) {
+              if (data[i].cAum.isEmpty() && data[i].aumqty.isEmpty()) {
+                String defaultAum = CentralBroker.getInstance().getDefaultAUMForDocument(
+                    data[i].mProductId, data[i].cDoctypeId);
+                data[i].aumqty = data[i].id;
+                data[i].cAum = defaultAum;
+                data[i].mProductUomId = null;
+                if (!defaultAum.equals(data[i].cUomId)) {
+                  data[i].id = CentralBroker
+                      .getInstance()
+                      .getConvertedQty(data[i].mProductId, new BigDecimal(data[i].aumqty),
+                          defaultAum).toString();
+                }
+              }
+            }
+
             final int curPrecision;
             if (strType.equals("SHIPMENT")) {
               curPrecision = Integer.valueOf(dataAux[0].priceprecision).intValue();
@@ -1651,7 +1766,7 @@
                   startingPeriodId, data[i].aAssetId, data[i].cProjectId, data[i].cCostcenterId,
                   data[i].user1Id, data[i].user2Id, data[i].explode,
                   data[i].mInoutlineId.equals("") || data[i].mInoutlineId == null ? data[i].isorder
-                      : "N");
+                      : "N", data[i].cAum, data[i].aumqty);
 
               if (!data[i].mInoutlineId.isEmpty() && strType.equals("SHIPMENT")) {
                 CreateFromInvoiceData.insertShipmentAcctDimension(conn, this, strSequence,
@@ -1743,6 +1858,7 @@
                 .selectFromPOUpdate(conn, this, vars.getLanguage(), ids[k]);
         }
         if (data != null) {
+          String uomManagementPreference = CentralBroker.getInstance().isUomManagementEnabled();
           for (int i = 0; i < data.length; i++) {
 
             // Obtain the values from the window
@@ -1755,8 +1871,29 @@
               strLineId = data[i].cOrderlineId;
             }
 
-            final String strMovementqty = vars.getRequiredNumericParameter("inpmovementqty"
-                + strLineId);
+            String strMovementqty = "";
+            String strAumQty = "";
+            if (uomManagementPreference.equals("Y") && data[i].mProductUomId.isEmpty()) {
+              try {
+                BigDecimal qtyAum = new BigDecimal(
+                    vars.getNumericParameter("inpaumqty" + strLineId));
+                strAumQty = qtyAum.toString();
+                strMovementqty = qtyAum.toString();
+                if (data[i].cAum.isEmpty()) {
+                  CreateFromShipmentData[] defaultAumData = CreateFromShipmentData
+                      .selectAUMDefault(this, data[i].mProductId, data[i].cDoctypeId);
+                  data[i].cAum = (defaultAumData.length > 0) ? defaultAumData[0].cAum
+                      : data[i].cUomId;
+                }
+                if (!data[i].cUomId.equals(data[i].cAum)) {
+                  strMovementqty = CentralBroker.getInstance()
+                      .getConvertedQty(data[i].mProductId, qtyAum, data[i].cAum).toString();
+                }
+              } catch (NumberFormatException e) {
+              }
+            } else {
+              strMovementqty = vars.getRequiredNumericParameter("inpmovementqty" + strLineId);
+            }
             String strQuantityorder = "";
             String strProductUomId = "";
             String strLocator = vars.getStringParameter("inpmLocatorId" + strLineId);
@@ -1848,7 +1985,7 @@
                   CreateFromShipmentData.insert(conn, this, strSequence, strKey, vars.getClient(),
                       data[i].adOrgId, vars.getUser(), data[i].description, data[i].mProductId,
                       data[i].cUomId, (qtyIsNegative ? "-" + strConversion : strConversion),
-                      data[i].cOrderlineId, strLocator,
+                      strAumQty, data[i].cAum, data[i].cOrderlineId, strLocator,
                       CreateFromShipmentData.isInvoiced(conn, this, data[i].cInvoicelineId),
                       (qtyIsNegative ? "-" + total : total), data[i].mProductUomId,
                       strmAttributesetinstanceId, data[i].aAssetId, data[i].cProjectId,
@@ -1880,7 +2017,8 @@
               try {
                 CreateFromShipmentData.insert(conn, this, strSequence, strKey, vars.getClient(),
                     data[i].adOrgId, vars.getUser(), data[i].description, data[i].mProductId,
-                    data[i].cUomId, strMovementqty, data[i].cOrderlineId, strLocator,
+                    data[i].cUomId, strMovementqty, strAumQty, data[i].cAum, data[i].cOrderlineId,
+                    strLocator,
                     CreateFromShipmentData.isInvoiced(conn, this, data[i].cInvoicelineId),
                     strQuantityorder, strProductUomId, strmAttributesetinstanceId,
                     data[i].aAssetId, data[i].cProjectId, data[i].cCostcenterId, data[i].user1Id,
@@ -2060,7 +2198,7 @@
                   CreateFromShipmentData.insert(conn, this, strSequence, strKey, vars.getClient(),
                       data[i].adOrgId, vars.getUser(), data[i].description, data[i].mProductId,
                       data[i].cUomId, (qtyIsNegative ? "-" + strConversion : strConversion),
-                      data[i].cOrderlineId, strLocator,
+                      data[i].aumqty, data[i].cAum, data[i].cOrderlineId, strLocator,
                       CreateFromShipmentData.isInvoiced(conn, this, data[i].cInvoicelineId),
                       (qtyIsNegative ? "-" + total : total), data[i].mProductUomId,
                       data[i].mAttributesetinstanceId, data[i].aAssetId, data[i].cProjectId,
@@ -2093,7 +2231,8 @@
               try {
                 CreateFromShipmentData.insert(conn, this, strSequence, strKey, vars.getClient(),
                     data[i].adOrgId, vars.getUser(), data[i].description, data[i].mProductId,
-                    data[i].cUomId, data[i].id, data[i].cOrderlineId, strLocator,
+                    data[i].cUomId, data[i].id, data[i].aumqty, data[i].cAum, data[i].cOrderlineId,
+                    strLocator,
                     CreateFromShipmentData.isInvoiced(conn, this, data[i].cInvoicelineId),
                     data[i].quantityorder, data[i].mProductUomId, data[i].mAttributesetinstanceId,
                     data[i].aAssetId, data[i].cProjectId, data[i].cCostcenterId, data[i].user1Id,
--- a/src/org/openbravo/erpCommon/ad_actionButton/CreateFrom_Invoice.html	Fri Nov 11 10:01:28 2016 +0100
+++ b/src/org/openbravo/erpCommon/ad_actionButton/CreateFrom_Invoice.html	Fri Nov 11 10:06:34 2016 +0100
@@ -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-2011 Openbravo SLU 
+ * All portions are Copyright (C) 2001-2016 Openbravo SLU 
  * All Rights Reserved. 
  * Contributor(s):  ______________________________________.
  ************************************************************************
@@ -435,6 +435,8 @@
                       <th width="175" class="DataGrid_Header_Cell">Quantity</th>
                       <th width="109" class="DataGrid_Header_Cell">Unit</th>
                       <th width="136" class="DataGrid_Header_Cell">Product</th>
+                      <th width="136" class="DataGrid_Header_Cell" id="paramAUMVisible" style="display:xx;">Quantity in Alternative UOM</th>
+                      <th width="136" class="DataGrid_Header_Cell" id="paramAUMVisible" style="display:xx;">Alternative UOM</th>
                       <th width="137" class="DataGrid_Header_Cell">Line</th>
                       <th width="100" class="DataGrid_Header_Cell">Order</th>
                       <th width="73"  class="DataGrid_Header_Cell">Shipment/Receipt</th>
@@ -448,6 +450,8 @@
                         <td class="DataGrid_Body_Cell" onmouseover="HoverCell(this);" onmouseout="unHoverCell(this);" id="fieldQuantity">xxQuantity</td>
                         <td class="DataGrid_Body_Cell" onmouseover="HoverCell(this);" onmouseout="unHoverCell(this);" id="fieldCuomid">xx</td>
                         <td class="DataGrid_Body_Cell" onmouseover="HoverCell(this);" onmouseout="unHoverCell(this);" id="fieldMproductid">xxUOM</td>
+                        <td class="DataGrid_Body_Cell" onmouseover="HoverCell(this);" onmouseout="unHoverCell(this);" id="fieldAUMQtyValue" style="display:xx;">xx</td>
+                        <td class="DataGrid_Body_Cell" onmouseover="HoverCell(this);" onmouseout="unHoverCell(this);" id="fieldAUMValue" style="display:xx;">xx</td>                        
                         <td class="DataGrid_Body_Cell" onmouseover="HoverCell(this);" onmouseout="unHoverCell(this);" id="fieldPurchaseorder">xxProduct</td>
                         <td class="DataGrid_Body_Cell" onmouseover="HoverCell(this);" onmouseout="unHoverCell(this);" id="fieldNameOrder">xxP</td>
                         <td class="DataGrid_Body_Cell" onmouseover="HoverCell(this);" onmouseout="unHoverCell(this);" id="fieldNameShipment">xx</td>
--- a/src/org/openbravo/erpCommon/ad_actionButton/CreateFrom_Invoice.xml	Fri Nov 11 10:01:28 2016 +0100
+++ b/src/org/openbravo/erpCommon/ad_actionButton/CreateFrom_Invoice.xml	Fri Nov 11 10:06:34 2016 +0100
@@ -33,11 +33,13 @@
     <PARAMETER id="paramWindowId" name="windowId" attribute="value"/>
     <PARAMETER id="paramTabName" name="tabName" attribute="value"/>
     <PARAMETER id="paramBPartnerId" name="cBpartnerId" attribute="value"/>
-  <PARAMETER id="keyMap" name="keyMap"/>
-  <PARAMETER id="messageBoxID" name="messageType" attribute="class" replace="yy" default="HIDDEN"/>
-  <PARAMETER id="messageBoxIDTitle" name="messageTitle" default=""/>
-  <PARAMETER id="messageBoxIDMessage" name="messageMessage" default=""/>
+    <PARAMETER id="keyMap" name="keyMap"/>
+    <PARAMETER id="messageBoxID" name="messageType" attribute="class" replace="yy" default="HIDDEN"/>
+    <PARAMETER id="messageBoxIDTitle" name="messageTitle" default=""/>
+    <PARAMETER id="messageBoxIDMessage" name="messageMessage" default=""/>
 
+	<PARAMETER id="paramAUMVisible" name="aumVisible" attribute="style" replace="xx">aumVisible</PARAMETER>
+	<PARAMETER id="paramAUMVisible" name="aumVisible" attribute="style" replace="xx">aumVisible</PARAMETER>
 
     <PARAMETER id="paramBPartnerDescription" name="BPartnerDescription" attribute="value"/>
     <PARAMETER id="paramPurchaseOrder" name="PurchaseOrder"/>
@@ -50,26 +52,29 @@
         <ARGUMENT name="parameterListSelected" withId="paramShipment"/>
     </SUBREPORT>
     <PARAMETER id="param2" name="param2" default="2"/>
-  <PARAMETER id="paramCheck" name="check" default="N"/>
+    <PARAMETER id="paramCheck" name="check" default="N"/>
+  
     <structure name="structure1">
-    <FIELD id="fieldRownum1">rownum</FIELD>
-    <FUNCTION id="funcEvenOddRowxx" name="MODULE" arg1="fieldRownum1" arg2="param2" format="integerEdition" attribute="class" replace="yy"/>
-
-    <FIELD id="funcEvenOddRowxx" attribute="id" replace="xx">rownum</FIELD>
-
-    <FIELD id="CheckNumxx" attribute="id" replace="xx">cOrderlineId</FIELD>
-    <FIELD id="CheckNumxx" attribute="value">cOrderlineId</FIELD>
-    <FIELD id="CheckNumxx" boolean="disabled" withId="paramCheck">isparent</FIELD>
-    <FIELD id="fieldBomParent" attribute="value">cOrderlineId</FIELD>
-    <FIELD id="fieldBomParent" attribute="name" replace="xx">bom_parent_id</FIELD>
-    
-    
-        <FIELD id="fieldQuantity" format="euroRelation">qty</FIELD>
-        <FIELD id="fieldCuomid" replaceCharacters="html">uomsymbol</FIELD>
-        <FIELD id="fieldMproductid" replaceCharacters="html">relationName</FIELD>
-        <FIELD id="fieldPurchaseorder">line</FIELD>
-        <FIELD id="fieldNameOrder" replaceCharacters="html">nameorder</FIELD>
-        <FIELD id="fieldNameShipment" replaceCharacters="html">nameshipment</FIELD>
-        <SECTION id="sectionDetail"/>
+	  <FIELD id="fieldRownum1">rownum</FIELD>
+	  <FUNCTION id="funcEvenOddRowxx" name="MODULE" arg1="fieldRownum1" arg2="param2" format="integerEdition" attribute="class" replace="yy"/>
+	
+	  <FIELD id="funcEvenOddRowxx" attribute="id" replace="xx">rownum</FIELD>
+	
+	  <FIELD id="CheckNumxx" attribute="id" replace="xx">cOrderlineId</FIELD>
+	  <FIELD id="CheckNumxx" attribute="value">cOrderlineId</FIELD>
+	  <FIELD id="CheckNumxx" boolean="disabled" withId="paramCheck">isparent</FIELD>
+	  <FIELD id="fieldBomParent" attribute="value">cOrderlineId</FIELD>
+	  <FIELD id="fieldBomParent" attribute="name" replace="xx">bom_parent_id</FIELD>
+	  <FIELD id="fieldQuantity" format="euroRelation">qty</FIELD>
+	  <FIELD id="fieldCuomid" replaceCharacters="html">uomsymbol</FIELD>
+	  <FIELD id="fieldMproductid" replaceCharacters="html">relationName</FIELD>
+	  <FIELD id="fieldPurchaseorder">line</FIELD>
+	  <FIELD id="fieldNameOrder" replaceCharacters="html">nameorder</FIELD>
+	  <FIELD id="fieldNameShipment" replaceCharacters="html">nameshipment</FIELD>
+	  <FIELD id="fieldAUMQtyValue" replaceCharacters="html">aumqty</FIELD>
+	  <FIELD id="fieldAUMQtyValue" attribute="style" replace="xx">aumVisible</FIELD>
+	  <FIELD id="fieldAUMValue" replaceCharacters="html">aumsymbol</FIELD>
+	  <FIELD id="fieldAUMValue" attribute="style" replace="xx">aumVisible</FIELD>
+	  <SECTION id="sectionDetail"/>
     </structure>
 </REPORT>
\ No newline at end of file
--- a/src/org/openbravo/erpCommon/ad_actionButton/CreateFrom_Invoice_data.xsql	Fri Nov 11 10:01:28 2016 +0100
+++ b/src/org/openbravo/erpCommon/ad_actionButton/CreateFrom_Invoice_data.xsql	Fri Nov 11 10:06:34 2016 +0100
@@ -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-2014 Openbravo SLU 
+ * All portions are Copyright (C) 2001-2016 Openbravo SLU 
  * All Rights Reserved. 
  * Contributor(s):  Cheli Pineda__________________________.
  ************************************************************************
@@ -36,11 +36,15 @@
        l.C_UOM_ID,uom.UOMSymbol, l.M_Product_ID,Ad_Column_Identifier(to_char('M_Product'), to_char(l.m_product_id), to_char(?)) AS RELATION_NAME, 
         l.C_OrderLine_ID,l.Line, l.ad_org_id, '' as STDPRECISION, 
         '' as M_InOutLine_ID, '' AS PriceActual, '' AS PriceList, '' AS PriceLimit, '' AS Description, '' as PriceStd,
-        '' AS QUANTITYORDER, '' AS M_Product_UOM_ID, '' AS M_ATTRIBUTESETINSTANCE_ID, '' AS M_Offer_ID, '' AS PricePrecision,
+        '' AS QUANTITYORDER, l.M_Product_UOM_ID, '' AS M_ATTRIBUTESETINSTANCE_ID, '' AS M_Offer_ID, '' AS PricePrecision,
         l.taxbaseamt, l.CancelPriceAD, '' AS Rate, '' AS gross_unit_price, '' AS grosspricelist, '' AS grosspricestd,
         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.explode, '' as isOrder, CASE WHEN l.Bom_parent_id is null then 'Y' else 'N' END as isparent, l.bom_parent_id
+        COALESCE(l.User1_ID, o.User1_ID) AS User1_ID, COALESCE(l.User2_ID, o.User2_ID) AS User2_ID, l.explode, '' as isOrder, CASE WHEN l.Bom_parent_id is null then 'Y' else 'N' END as isparent, l.bom_parent_id,
+        (CASE WHEN L.C_AUM IS NULL THEN M_GET_DEFAULT_AUM_FOR_DOCUMENT(L.M_PRODUCT_ID, o.C_DOCTYPE_ID) ELSE l.C_AUM END) AS C_AUM, 
+        l.AUMQTY, o.C_DOCTYPE_ID, 
+        (CASE WHEN L.C_AUM IS NOT NULL THEN (SELECT UOMSYMBOL FROM C_UOM WHERE C_UOM_ID = L.C_AUM) ELSE (SELECT UOMSYMBOL FROM C_UOM WHERE C_UOM_ID = M_GET_DEFAULT_AUM_FOR_DOCUMENT(L.M_PRODUCT_ID, o.C_DOCTYPE_ID)) END) AS AUMSYMBOL,
+        '' AS AUMVISIBLE
         FROM C_ORDERLINE l left join M_MATCHPO m on  l.C_OrderLine_ID=m.C_OrderLine_ID
                                                  AND m.C_InvoiceLine_ID IS NOT NULL, 
         C_ORDER o, C_UOM uom,  M_PRODUCT p
@@ -61,7 +65,7 @@
         GROUP BY o.C_ORDER_ID, o.DocumentNo, o.DateOrdered, o.GrandTotal, l.QtyOrdered,l.C_UOM_ID,
         uom.UOMSymbol,l.M_Product_ID,p.NAME,l.Line,l.C_OrderLine_ID, l.ad_org_id, l.taxbaseamt,l.CancelPriceAD,
         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.explode, l.bom_parent_id 
+        COALESCE(l.User1_ID, o.User1_ID), COALESCE(l.User2_ID, o.User2_ID), l.explode, l.bom_parent_id, l.M_Product_UOM_ID, l.AUMQTY, o.C_DOCTYPE_ID, c_aum
         HAVING ( (l.explode='Y') OR ((l.QtyOrdered-SUM(COALESCE(m.Qty,0))) <> 0)) 
         ORDER BY NAME, l.Line
       ]]>
@@ -113,7 +117,10 @@
         l.C_OrderLine_ID,l.Line, l.ad_Org_id, l.taxbaseamt,
         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.explode, l.Bom_parent_id, 
-         CASE WHEN l.Bom_parent_id is null then 'Y' else 'N' END as isparent
+         CASE WHEN l.Bom_parent_id is null then 'Y' else 'N' END as isparent,
+        (CASE WHEN L.C_AUM IS NULL THEN M_GET_DEFAULT_AUM_FOR_DOCUMENT(L.M_PRODUCT_ID, o.C_DOCTYPE_ID) ELSE l.C_AUM END) AS C_AUM, 
+        l.AUMQTY, o.C_DOCTYPE_ID, 
+        (CASE WHEN L.C_AUM IS NOT NULL THEN (SELECT UOMSYMBOL FROM C_UOM WHERE C_UOM_ID = L.C_AUM) ELSE (SELECT UOMSYMBOL FROM C_UOM WHERE C_UOM_ID = M_GET_DEFAULT_AUM_FOR_DOCUMENT(L.M_PRODUCT_ID, o.C_DOCTYPE_ID)) END) AS AUMSYMBOL
         FROM C_INVOICE_CANDIDATE_V ic, C_UOM uom, C_ORDER o, C_ORDERLINE l, M_PRODUCT p 
         WHERE l.C_UOM_ID=uom.C_UOM_ID
         AND o.C_ORDER_ID = ic.C_ORDER_ID 
@@ -125,7 +132,7 @@
         GROUP BY o.C_ORDER_ID, o.DocumentNo, o.DateOrdered, o.GrandTotal, l.QtyOrdered,
         l.C_UOM_ID,uom.UOMSymbol,l.M_Product_ID,p.NAME,l.Line,l.C_OrderLine_ID, l.QTYINVOICED, l.ad_org_id, l.taxbaseamt,
         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.explode, l.Bom_parent_id
+        COALESCE(l.User1_ID, o.User1_ID), COALESCE(l.User2_ID, o.User2_ID), l.explode, l.Bom_parent_id, c_aum, l.AUMQTY, o.C_DOCTYPE_ID
         ORDER BY NAME, l.Line
       ]]>
     </Sql>
@@ -173,7 +180,10 @@
         l.C_UOM_ID, COALESCE(uomt.UOMSYMBOL, uom.UOMSymbol) AS UOMSymbol, 
         l.M_Product_ID,Ad_Column_Identifier(to_char('M_Product'), to_char(l.m_product_id), to_char(?)) AS RELATION_NAME, l.C_OrderLine_ID,l.Line, l.taxbaseamt,
         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.User1_ID, o.User1_ID) AS User1_ID, COALESCE(l.User2_ID, o.User2_ID) AS User2_ID,
+        (CASE WHEN L.C_AUM IS NULL THEN M_GET_DEFAULT_AUM_FOR_DOCUMENT(L.M_PRODUCT_ID, o.C_DOCTYPE_ID) ELSE l.C_AUM END) AS C_AUM, 
+        l.AUMQTY, o.C_DOCTYPE_ID, 
+        (CASE WHEN L.C_AUM IS NOT NULL THEN (SELECT UOMSYMBOL FROM C_UOM WHERE C_UOM_ID = L.C_AUM) ELSE (SELECT UOMSYMBOL FROM C_UOM WHERE C_UOM_ID = M_GET_DEFAULT_AUM_FOR_DOCUMENT(L.M_PRODUCT_ID, o.C_DOCTYPE_ID)) END) AS AUMSYMBOL
         FROM C_UOM uom left join  C_UOM_TRL uomt on uom.C_UOM_ID = uomt.C_UOM_ID
                                                 and uomt.AD_Language = ?,
              C_ORDERLINE l left join M_MATCHPO m on l.C_OrderLine_ID=m.C_OrderLine_ID
@@ -196,7 +206,7 @@
         GROUP BY o.C_ORDER_ID, o.DocumentNo, o.DateOrdered, o.GrandTotal, l.QtyOrdered,l.C_UOM_ID,
         uom.UOMSymbol, uomt.UOMSYMBOL,l.M_Product_ID,p.NAME,l.Line,l.C_OrderLine_ID,
         l.taxbaseamt, 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.User1_ID, o.User1_ID), COALESCE(l.User2_ID, o.User2_ID), C_AUM, l.AUMQTY, o.C_DOCTYPE_ID
         HAVING (l.QtyOrdered-SUM(COALESCE(m.Qty,0))) <> 0
         ORDER BY NAME, l.Line
       ]]>
@@ -219,7 +229,10 @@
         l.QtyOrdered-COALESCE(l.QTYINVOICED,0) AS QTY, l.C_UOM_ID, COALESCE(uomt.UOMSymbol, uom.UOMSymbol) AS UOMSymbol, 
         l.M_Product_ID,Ad_Column_Identifier(to_char('M_Product'), to_char(l.m_product_id), to_char(?)) AS RELATION_NAME, l.C_OrderLine_ID,l.Line, l.taxbaseamt,
         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.User1_ID, o.User1_ID) AS User1_ID, COALESCE(l.User2_ID, o.User2_ID) AS User2_ID,
+        (CASE WHEN L.C_AUM IS NULL THEN M_GET_DEFAULT_AUM_FOR_DOCUMENT(L.M_PRODUCT_ID, o.C_DOCTYPE_ID) ELSE l.C_AUM END) AS C_AUM, 
+        l.AUMQTY, o.C_DOCTYPE_ID, 
+        (CASE WHEN L.C_AUM IS NOT NULL THEN (SELECT UOMSYMBOL FROM C_UOM WHERE C_UOM_ID = L.C_AUM) ELSE (SELECT UOMSYMBOL FROM C_UOM WHERE C_UOM_ID = M_GET_DEFAULT_AUM_FOR_DOCUMENT(L.M_PRODUCT_ID, o.C_DOCTYPE_ID)) END) AS AUMSYMBOL
         FROM C_UOM uom left join C_UOM_TRL uomt on uom.C_UOM_ID = uomt.C_UOM_ID
                                                and  uomt.AD_Language = ?, 
         C_INVOICE_CANDIDATE_V ic,   C_ORDER o, C_ORDERLINE l, M_PRODUCT p 
@@ -233,7 +246,7 @@
         GROUP BY o.C_ORDER_ID, o.DocumentNo, o.DateOrdered, o.GrandTotal, l.QtyOrdered,
         l.C_UOM_ID,uom.UOMSymbol, uomt.UOMSymbol,l.M_Product_ID,p.NAME,l.Line,l.C_OrderLine_ID, l.QTYINVOICED,
         l.taxbaseamt, 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.User1_ID, o.User1_ID), COALESCE(l.User2_ID, o.User2_ID), l.AUMQTY, o.C_DOCTYPE_ID, C_AUM
         ORDER BY NAME, l.Line
       ]]>
     </Sql>
@@ -255,7 +268,8 @@
       A.C_OrderLine_ID,A.Line, uom.stdprecision AS stdprecision, cur.priceprecision, 
       B.M_InOutLine_ID, A.Description, (CASE WHEN B.M_InOutLine_ID IS NULL THEN A.quantityOrder ELSE B.quantityOrder END) AS quantityOrder, 
       (CASE WHEN B.M_InOutLine_ID IS NULL THEN A.M_Product_UOM_ID ELSE B.M_Product_UOM_ID END) AS M_Product_UOM_ID, A.M_ATTRIBUTESETINSTANCE_ID, A.ad_org_id,
-      A.taxbaseamt, A.a_asset_id, A.c_project_id, A.c_costcenter_id, A.user1_id, A.user2_id, A.explode, 'Y' as isOrder
+      A.taxbaseamt, A.a_asset_id, A.c_project_id, A.c_costcenter_id, A.user1_id, A.user2_id, A.explode, 'Y' as isOrder,
+      (CASE WHEN B.C_AUM IS NULL THEN A.C_AUM ELSE B.C_AUM END) AS C_AUM, (CASE WHEN B.AUMQTY IS NULL THEN A.AUMQTY ELSE B.AUMQTY END) AS AUMQTY, A.C_DOCTYPE_ID
       FROM c_currency cur,C_UOM uom, M_PRODUCT p, 
       (SELECT 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.explode,l.ad_org_id,l.C_CURRENCY_ID,l.C_UOM_ID, l.M_Product_ID, l.Line, l.Description, l.C_OrderLine_ID, (l.QtyOrdered-SUM(COALESCE(mp.Qty,0))-
@@ -267,21 +281,22 @@
        FROM C_ORDERLINE CO LEFT JOIN C_INVOICELINE CI ON CI.C_ORDERLINE_ID = CO.C_ORDERLINE_ID
        WHERE  CI.C_INVOICE_ID=? AND CO.C_ORDERLINE_ID = l.c_orderline_id
        GROUP BY CI.C_orderline_id , CO.QtyORDERED),0)),l.QtyOrdered) as quantityOrder, 
-       l.M_Product_UOM_ID, l.M_ATTRIBUTESETINSTANCE_ID, l.taxbaseamt
+       l.M_Product_UOM_ID, l.M_ATTRIBUTESETINSTANCE_ID, l.taxbaseamt, l.C_AUM, l.AUMQTY, o.C_DOCTYPE_ID
         FROM C_ORDERLINE l left join M_MATCHPO mp on l.C_OrderLine_ID=mp.C_OrderLine_ID
                                                   and mp.C_InvoiceLine_ID IS NOT NULL
         LEFT JOIN C_Order o ON l.C_Order_ID = o.C_Order_ID
         GROUP BY l.ad_org_id,l.C_CURRENCY_ID,l.C_UOM_ID, l.M_Product_ID, l.Line, l.Description, l.C_OrderLine_ID, l.QtyOrdered, l.quantityOrder, l.M_Product_UOM_ID,
         l.M_ATTRIBUTESETINSTANCE_ID, l.taxbaseamt, 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.explode) A left join 
+        COALESCE(l.User1_ID, o.User1_ID), COALESCE(l.User2_ID, o.User2_ID), l.explode, o.C_DOCTYPE_ID, l.c_aum, l.aumqty, o.c_doctype_id) A left join 
       (SELECT il.M_InOutLine_ID, il.C_OrderLine_ID, (il.MovementQty-SUM(COALESCE(mi.Qty,0))) AS QTY,
-      il.quantityOrder*C_DIVIDE((il.MovementQty-SUM(COALESCE(mi.Qty,0))),(il.MovementQty)) as quantityOrder, il.M_Product_UOM_ID
+      il.quantityOrder*C_DIVIDE((il.MovementQty-SUM(COALESCE(mi.Qty,0))),(il.MovementQty)) as quantityOrder, il.M_Product_UOM_ID,
+      il.C_AUM, il.AUMQTY, io.C_DOCTYPE_ID
         FROM M_INOUTLINE il left join M_MATCHINV mi on il.M_InOutLine_ID=mi.M_InOutLine_ID,
              M_INOUT io
         WHERE il.C_OrderLine_ID IS NOT NULL
         AND io.M_InOut_ID = il.M_InOut_ID
         AND io.Processed = 'Y'
-        GROUP BY il.M_InOutLine_ID, il.C_OrderLine_ID, il.MovementQty, il.quantityOrder, il.M_Product_UOM_ID
+        GROUP BY il.M_InOutLine_ID, il.C_OrderLine_ID, il.MovementQty, il.quantityOrder, il.M_Product_UOM_ID, io.C_DOCTYPE_ID, il.C_AUM, il.AUMQTY
         HAVING (il.MovementQty-SUM(COALESCE(mi.Qty,0))) <> 0) B on A.C_OrderLine_ID=B.C_OrderLine_ID
       WHERE A.C_UOM_ID=uom.C_UOM_ID
       AND cur.C_CURRENCY_ID=A.C_CURRENCY_ID
@@ -304,7 +319,8 @@
         (CASE WHEN il.M_INOUTLINE_ID IS NULL THEN l.quantityOrder*C_DIVIDE((l.QtyOrdered-COALESCE(l.QTYINVOICED ,0)),(l.QtyOrdered)) ELSE il.quantityOrder END) AS quantityOrder, 
         (CASE WHEN il.M_INOUTLINE_ID IS NULL THEN l.M_Product_UOM_ID ELSE il.M_Product_UOM_ID END) AS M_Product_UOM_ID, il.M_ATTRIBUTESETINSTANCE_ID, l.ad_org_id,
         l.taxbaseamt, 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.explode, 'Y' as isOrder
+        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.explode, 'Y' as isOrder,
+        l.C_AUM, l.AUMQTY, o.C_DOCTYPE_ID
         FROM C_ORDERLINE l left join (SELECT M_InOutLine.* FROM M_InOutLine, M_InOut
                                       WHERE M_InOut.M_InOut_ID = M_InOutLine.M_InOut_ID
                                       AND M_InOutLine.IsInvoiced = 'N'
@@ -317,7 +333,7 @@
         l.QTYINVOICED, il.M_InOutLine_ID, il.MovementQty, l.Description, l.quantityOrder, il.quantityOrder, 
         l.M_Product_UOM_ID, il.M_Product_UOM_ID, il.M_ATTRIBUTESETINSTANCE_ID, l.ad_org_id, cur.priceprecision,
         l.taxbaseamt, 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.explode
+        COALESCE(l.User1_ID, o.User1_ID), COALESCE(l.User2_ID, o.User2_ID), l.explode, o.C_DOCTYPE_ID, l.C_AUM, l.AUMQTY
         HAVING ( (l.explode='Y') OR ((l.QtyOrdered-COALESCE(l.QTYINVOICED ,0)) <> 0)) 
         ORDER BY l.Line
       ]]>
@@ -337,7 +353,10 @@
         COALESCE(l.A_Asset_ID, s.A_Asset_ID) AS A_Asset_ID, COALESCE(l.C_Project_ID, s.C_Project_ID) AS C_Project_ID, 
         COALESCE(l.C_Costcenter_ID, s.C_Costcenter_ID) AS C_Costcenter_ID,
         COALESCE(l.User1_ID, s.User1_ID) AS User1_ID, COALESCE(l.User2_ID, s.User2_ID) AS User2_ID, l.explode, l.Bom_parent_id, 
-        CASE WHEN l.Bom_parent_id is null then 'Y' else 'N' END as isparent
+        CASE WHEN l.Bom_parent_id is null then 'Y' else 'N' END as isparent,
+        (CASE WHEN L.C_AUM IS NULL THEN M_GET_DEFAULT_AUM_FOR_DOCUMENT(L.M_PRODUCT_ID, s.C_DOCTYPE_ID) ELSE l.C_AUM END) AS C_AUM, 
+        l.AUMQTY, s.C_DOCTYPE_ID,  
+        (CASE WHEN L.C_AUM IS NOT NULL THEN (SELECT UOMSYMBOL FROM C_UOM WHERE C_UOM_ID = L.C_AUM) ELSE (SELECT UOMSYMBOL FROM C_UOM WHERE C_UOM_ID = M_GET_DEFAULT_AUM_FOR_DOCUMENT(L.M_PRODUCT_ID, s.C_DOCTYPE_ID)) END) AS AUMSYMBOL
         FROM M_INOUTLINE l left join M_ATTRIBUTESETINSTANCE ma on l.M_ATTRIBUTESETINSTANCE_ID = ma.M_ATTRIBUTESETINSTANCE_ID
                            left join M_MATCHINV mi             on l.M_InOutLine_ID=mi.M_InOutLine_ID
                            left join c_orderline ol on l.c_orderline_id = ol.c_orderline_id
@@ -356,7 +375,7 @@
         GROUP BY s.M_InOut_ID, s.DocumentNo, s.MovementDate, l.MovementQty,l.C_UOM_ID,uom.UOMSymbol,
         l.M_Product_ID,ma.serno,p.NAME, l.M_InOutLine_ID,l.Line,l.C_OrderLine_ID,
         COALESCE(l.A_Asset_ID, s.A_Asset_ID), COALESCE(l.C_Project_ID, s.C_Project_ID), COALESCE(l.C_Costcenter_ID, s.C_Costcenter_ID),
-        COALESCE(l.User1_ID, s.User1_ID), COALESCE(l.User2_ID, s.User2_ID), l.explode, l.bom_parent_id
+        COALESCE(l.User1_ID, s.User1_ID), COALESCE(l.User2_ID, s.User2_ID), l.explode, l.bom_parent_id, l.C_AUM, l.AUMQTY, s.C_DOCTYPE_ID
         HAVING  (((l.MovementQty-SUM(COALESCE(mi.Qty,0))) <> 0) OR (l.explode='Y'))
         ORDER BY NAME, l.Line
       ]]>
@@ -413,7 +432,10 @@
         COALESCE(l.A_Asset_ID, s.A_Asset_ID) AS A_Asset_ID, COALESCE(l.C_Project_ID, s.C_Project_ID) AS C_Project_ID, 
         COALESCE(l.C_Costcenter_ID, s.C_Costcenter_ID) AS C_Costcenter_ID,
         COALESCE(l.User1_ID, s.User1_ID) AS User1_ID, COALESCE(l.User2_ID, s.User2_ID) AS User2_ID, l.explode, l.Bom_parent_id, 
-        CASE WHEN l.Bom_parent_id is null then 'Y' else 'N' END as isparent
+        CASE WHEN l.Bom_parent_id is null then 'Y' else 'N' END as isparent,
+        (CASE WHEN L.C_AUM IS NULL THEN M_GET_DEFAULT_AUM_FOR_DOCUMENT(L.M_PRODUCT_ID, s.C_DOCTYPE_ID) ELSE l.C_AUM END) AS C_AUM, 
+        l.AUMQTY, s.C_DOCTYPE_ID, 
+        (CASE WHEN L.C_AUM IS NOT NULL THEN (SELECT UOMSYMBOL FROM C_UOM WHERE C_UOM_ID = L.C_AUM) ELSE (SELECT UOMSYMBOL FROM C_UOM WHERE C_UOM_ID = M_GET_DEFAULT_AUM_FOR_DOCUMENT(L.M_PRODUCT_ID, s.C_DOCTYPE_ID)) END) AS AUMSYMBOL        
         FROM M_INOUTLINE l
                 left join M_ATTRIBUTESETINSTANCE ma on l.M_ATTRIBUTESETINSTANCE_ID = ma.M_ATTRIBUTESETINSTANCE_ID
                 left join c_orderline ol on l.c_orderline_id = ol.c_orderline_id
@@ -434,7 +456,7 @@
         GROUP BY s.M_InOut_ID, s.DocumentNo, s.MovementDate, l.MovementQty,l.C_UOM_ID,uom.UOMSymbol,
         l.M_Product_ID,p.NAME, ma.serno, l.M_InOutLine_ID,l.Line,l.C_OrderLine_ID,
         COALESCE(l.A_Asset_ID, s.A_Asset_ID), COALESCE(l.C_Project_ID, s.C_Project_ID), COALESCE(l.C_Costcenter_ID, s.C_Costcenter_ID),
-        COALESCE(l.User1_ID, s.User1_ID), COALESCE(l.User2_ID, s.User2_ID), l.explode, l.Bom_parent_id
+        COALESCE(l.User1_ID, s.User1_ID), COALESCE(l.User2_ID, s.User2_ID), l.explode, l.Bom_parent_id, l.C_AUM, l.AUMQTY, s.C_DOCTYPE_ID
         HAVING (l.movementqty >= 0 AND l.movementqty > SUM(COALESCE(CASE WHEN i.docstatus = 'CO' THEN il.qtyinvoiced ELSE 0 END, 0)))
            OR (l.movementqty < 0 AND l.movementqty < SUM(COALESCE(CASE WHEN i.docstatus = 'CO' THEN il.qtyinvoiced ELSE 0 END, 0)))
            OR (l.explode='Y')
@@ -502,7 +524,10 @@
         l.M_Product_ID,Ad_Column_Identifier(to_char('M_Product'), to_char(l.m_product_id), to_char(?))||' '||(CASE WHEN ma.serno IS NOT NULL THEN TO_CHAR('('||' '||ma.serno||' '||')') ELSE TO_CHAR('')  END) AS RELATION_NAME, l.M_InOutLine_ID,l.Line, l.M_InOutLine_ID as C_OrderLine_ID,
         COALESCE(l.A_Asset_ID, s.A_Asset_ID) AS A_Asset_ID, COALESCE(l.C_Project_ID, s.C_Project_ID) AS C_Project_ID, 
         COALESCE(l.C_Costcenter_ID, s.C_Costcenter_ID) AS C_Costcenter_ID,
-        COALESCE(l.User1_ID, s.User1_ID) AS User1_ID, COALESCE(l.User2_ID, s.User2_ID) AS User2_ID
+        COALESCE(l.User1_ID, s.User1_ID) AS User1_ID, COALESCE(l.User2_ID, s.User2_ID) AS User2_ID,
+        (CASE WHEN L.C_AUM IS NULL THEN M_GET_DEFAULT_AUM_FOR_DOCUMENT(L.M_PRODUCT_ID, s.C_DOCTYPE_ID) ELSE l.C_AUM END) AS C_AUM, 
+        l.AUMQTY, s.C_DOCTYPE_ID,  
+        (CASE WHEN L.C_AUM IS NOT NULL THEN (SELECT UOMSYMBOL FROM C_UOM WHERE C_UOM_ID = L.C_AUM) ELSE (SELECT UOMSYMBOL FROM C_UOM WHERE C_UOM_ID = M_GET_DEFAULT_AUM_FOR_DOCUMENT(L.M_PRODUCT_ID, s.C_DOCTYPE_ID)) END) AS AUMSYMBOL
         FROM M_INOUTLINE l
                 left join M_ATTRIBUTESETINSTANCE ma on l.M_ATTRIBUTESETINSTANCE_ID = ma.M_ATTRIBUTESETINSTANCE_ID
                 left join M_MATCHINV mi             on l.M_InOutLine_ID=mi.M_InOutLine_ID
@@ -524,7 +549,7 @@
         GROUP BY s.M_InOut_ID, s.DocumentNo, s.MovementDate, l.MovementQty,l.C_UOM_ID,uom.UOMSymbol, uomt.UOMSymbol,
         l.M_Product_ID,p.NAME, ma.serno, l.M_InOutLine_ID,l.Line,l.C_OrderLine_ID,
         COALESCE(l.A_Asset_ID, s.A_Asset_ID), COALESCE(l.C_Project_ID, s.C_Project_ID), COALESCE(l.C_Costcenter_ID, s.C_Costcenter_ID),
-        COALESCE(l.User1_ID, s.User1_ID), COALESCE(l.User2_ID, s.User2_ID)
+        COALESCE(l.User1_ID, s.User1_ID), COALESCE(l.User2_ID, s.User2_ID), l.C_AUM, l.AUMQTY, s.C_DOCTYPE_ID
         HAVING  (l.MovementQty-SUM(COALESCE(mi.Qty,0))) <> 0
         ORDER BY NAME, l.Line
       ]]>
@@ -548,7 +573,10 @@
         l.M_Product_ID,Ad_Column_Identifier(to_char('M_Product'), to_char(l.m_product_id), to_char(?))||' '|| (CASE WHEN ma.serno IS NOT NULL THEN TO_CHAR('('||' '||ma.serno||' '||')') ELSE TO_CHAR('')  END) AS RELATION_NAME, l.M_InOutLine_ID,l.Line, l.M_InOutLine_ID as C_OrderLine_ID, 
         COALESCE(l.A_Asset_ID, s.A_Asset_ID) AS A_Asset_ID, COALESCE(l.C_Project_ID, s.C_Project_ID) AS C_Project_ID, 
         COALESCE(l.C_Costcenter_ID, s.C_Costcenter_ID) AS C_Costcenter_ID,
-        COALESCE(l.User1_ID, s.User1_ID) AS User1_ID, COALESCE(l.User2_ID, s.User2_ID) AS User2_ID
+        COALESCE(l.User1_ID, s.User1_ID) AS User1_ID, COALESCE(l.User2_ID, s.User2_ID) AS User2_ID,
+        (CASE WHEN L.C_AUM IS NULL THEN M_GET_DEFAULT_AUM_FOR_DOCUMENT(L.M_PRODUCT_ID, s.C_DOCTYPE_ID) ELSE l.C_AUM END) AS C_AUM, 
+        l.AUMQTY, s.C_DOCTYPE_ID,  
+        (CASE WHEN L.C_AUM IS NOT NULL THEN (SELECT UOMSYMBOL FROM C_UOM WHERE C_UOM_ID = L.C_AUM) ELSE (SELECT UOMSYMBOL FROM C_UOM WHERE C_UOM_ID = M_GET_DEFAULT_AUM_FOR_DOCUMENT(L.M_PRODUCT_ID, s.C_DOCTYPE_ID)) END) AS AUMSYMBOL
         FROM M_INOUTLINE l
               left join M_ATTRIBUTESETINSTANCE ma on l.M_ATTRIBUTESETINSTANCE_ID = ma.M_ATTRIBUTESETINSTANCE_ID
               left join c_orderline ol on l.c_orderline_id = ol.c_orderline_id
@@ -571,7 +599,7 @@
         GROUP BY s.M_InOut_ID, s.DocumentNo, s.MovementDate, l.MovementQty,l.C_UOM_ID,uom.UOMSymbol, uomt.UOMSymbol,
         l.M_Product_ID,p.NAME,ma.serno, l.M_InOutLine_ID,l.Line,l.C_OrderLine_ID,
         COALESCE(l.A_Asset_ID, s.A_Asset_ID), COALESCE(l.C_Project_ID, s.C_Project_ID), COALESCE(l.C_Costcenter_ID, s.C_Costcenter_ID),
-        COALESCE(l.User1_ID, s.User1_ID), COALESCE(l.User2_ID, s.User2_ID)
+        COALESCE(l.User1_ID, s.User1_ID), COALESCE(l.User2_ID, s.User2_ID), l.C_AUM, l.AUMQTY, s.C_DOCTYPE_ID
         HAVING (l.movementqty >= 0 AND l.movementqty > SUM(COALESCE(CASE WHEN i.docstatus = 'CO' THEN il.qtyinvoiced ELSE 0 END, 0)))
           OR (l.movementqty < 0 AND l.movementqty < SUM(COALESCE(CASE WHEN i.docstatus = 'CO' THEN il.qtyinvoiced ELSE 0 END, 0)))
         ORDER BY NAME, l.Line
@@ -596,7 +624,8 @@
       COALESCE(l.A_Asset_ID, s.A_Asset_ID) AS A_Asset_ID, COALESCE(l.C_Project_ID, s.C_Project_ID) AS C_Project_ID, 
       COALESCE(l.C_Costcenter_ID, s.C_Costcenter_ID) AS C_Costcenter_ID,
       COALESCE(l.User1_ID, s.User1_ID) AS User1_ID, COALESCE(l.User2_ID, s.User2_ID) AS User2_ID,
-      l.explode, 'N' as isOrder
+      l.explode, 'N' as isOrder,
+      l.C_AUM, l.AUMQTY, s.C_DOCTYPE_ID
       FROM M_INOUTLINE l left join M_MATCHINV mi on l.M_InOutLine_ID=mi.M_InOutLine_ID
             left join C_ORDERLINE co ON co.C_ORDERLINE_ID=l.C_ORDERLINE_ID,
       C_UOM uom,  M_PRODUCT p, M_InOut s
@@ -605,7 +634,7 @@
       AND l.M_Product_ID=p.M_Product_ID
       GROUP BY l.MovementQty,l.C_UOM_ID,uom.UOMSymbol,l.M_Product_ID,p.NAME, l.M_InOutLine_ID,l.Line,l.C_OrderLine_ID, l.Description,l.quantityOrder, l.M_Product_UOM_ID, l.M_ATTRIBUTESETINSTANCE_ID, l.ad_org_id, co.taxbaseamt,co.qtyordered,
       COALESCE(l.A_Asset_ID, s.A_Asset_ID), COALESCE(l.C_Project_ID, s.C_Project_ID), COALESCE(l.C_Costcenter_ID, s.C_Costcenter_ID),
-      COALESCE(l.User1_ID, s.User1_ID), COALESCE(l.User2_ID, s.User2_ID),l.explode
+      COALESCE(l.User1_ID, s.User1_ID), COALESCE(l.User2_ID, s.User2_ID),l.explode, s.C_DOCTYPE_ID, l.C_AUM, l.AUMQTY
       ORDER BY l.Line
       ]]>
     </Sql>
@@ -625,7 +654,8 @@
         COALESCE(l.A_Asset_ID, s.A_Asset_ID) AS A_Asset_ID, COALESCE(l.C_Project_ID, s.C_Project_ID) AS C_Project_ID, 
         COALESCE(l.C_Costcenter_ID, s.C_Costcenter_ID) AS C_Costcenter_ID,
         COALESCE(l.User1_ID, s.User1_ID) AS User1_ID, COALESCE(l.User2_ID, s.User2_ID) AS User2_ID, 
-        l.explode, 'N' as isOrder
+        l.explode, 'N' as isOrder,
+        l.C_AUM, l.AUMQTY, s.C_DOCTYPE_ID
         FROM C_UOM uom, M_INOUTLINE l
           left join c_invoiceline il on l.m_inoutline_id = il.m_inoutline_id
           left join c_invoice i on il.c_invoice_id = i.c_invoice_id 
@@ -635,7 +665,7 @@
         AND l.M_Product_ID=p.M_Product_ID 
         GROUP BY l.MovementQty,l.C_UOM_ID,uom.UOMSymbol,l.M_Product_ID,p.NAME, l.M_InOutLine_ID,l.Line,l.C_OrderLine_ID, l.Description, l.quantityOrder, l.M_Product_UOM_ID, l.M_ATTRIBUTESETINSTANCE_ID, l.ad_org_id, l.m_inout_id,
         COALESCE(l.A_Asset_ID, s.A_Asset_ID), COALESCE(l.C_Project_ID, s.C_Project_ID), COALESCE(l.C_Costcenter_ID, s.C_Costcenter_ID),
-        COALESCE(l.User1_ID, s.User1_ID), COALESCE(l.User2_ID, s.User2_ID), l.explode
+        COALESCE(l.User1_ID, s.User1_ID), COALESCE(l.User2_ID, s.User2_ID), l.explode, s.C_DOCTYPE_ID, l.C_AUM, l.AUMQTY
         HAVING (l.movementqty >= 0 AND l.movementqty > SUM(COALESCE(CASE WHEN i.docstatus = 'CO' THEN il.qtyinvoiced ELSE 0 END, 0)))
           OR (l.movementqty < 0 AND l.movementqty < SUM(COALESCE(CASE WHEN i.docstatus = 'CO' THEN il.qtyinvoiced ELSE 0 END, 0)))
           OR(l.explode='Y') 
@@ -715,7 +745,8 @@
         gross_unit_price, line_gross_amount, grosspricelist, grosspricestd,
         isdeferred, defplantype, periodnumber, c_period_id,
         a_asset_id, c_project_id, c_costcenter_id, user1_id, user2_id, explode, 
-        BOM_Parent_id
+        BOM_Parent_id,
+        C_AUM, AUMQTY
         )
       VALUES 
         (?, ?, ?, ?, 'Y', 
@@ -740,7 +771,7 @@
                 and m_inoutline_id = (SELECT BOM_parent_id 
                                       FROM m_inoutline 
                                       WHERE m_inoutline_id = ?)) END
-         )
+         ), ?, TO_NUMBER(?)
         )
     </Sql>
     <Parameter name="cInvoicelineId"/>
@@ -786,6 +817,8 @@
     <Parameter name="cOrderlineId"/>
     <Parameter name="cInvoiceId"/>
     <Parameter name="mInoutlineId"/>
+    <Parameter name="cAum"/>
+    <Parameter name="aumQty"/>
   </SqlMethod>
   <SqlMethod name="insertAcctDimension" type="preparedStatement" connection="true" return="rowCount">
     <SqlMethodComment>Copies the order line accounting dimensions to invoice lines</SqlMethodComment>
--- a/src/org/openbravo/erpCommon/ad_actionButton/CreateFrom_ShipmentPO.html	Fri Nov 11 10:01:28 2016 +0100
+++ b/src/org/openbravo/erpCommon/ad_actionButton/CreateFrom_ShipmentPO.html	Fri Nov 11 10:06:34 2016 +0100
@@ -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-2014 Openbravo SLU 
+ * All portions are Copyright (C) 2001-2016 Openbravo SLU 
  * All Rights Reserved. 
  * Contributor(s):  ______________________________________.
  ************************************************************************
@@ -39,7 +39,7 @@
   <script language="JavaScript" type="text/javascript">
     window.onunload = reloadOpener; // reloads opener on closing
 
-    function closeThisPage() {
+    function closeThisPage() { 
       closePage();
       return true;
     }
@@ -61,7 +61,6 @@
     }
   </script>
   <script language="JavaScript" type="text/javascript">
-
     function debugSearch(strClave, strTexto, gCampoClave) {
       submitCommandForm("REFRESH_INVOICES", false, null, null, "frameOcultoButton");
       return true;
@@ -91,52 +90,85 @@
     function enableLocalShortcuts(){
       keyArray[keyArray.length] = new keyArrayItem("ENTER", "openSearch(null, null, '../info/BusinessPartner.html', 'SELECTOR_BUSINESS', true, 'frmMain', 'inpcBpartnerId', 'inpBpartnerId_DES', document.frmMain.inpBpartnerId_DES.value, 'Command', 'KEY');", "inpBpartnerId_DES", "null");
       keyArray[keyArray.length] = new keyArrayItem("ENTER", "openSearch(null, null, '../info/Locator.html', null, false, 'frmMain', 'inpmLocatorId', 'inpmLocatorId_DES', document.frmMain.inpmLocatorId_DES.value, 'Command', 'KEY', 'WindowID', document.frmMain.inpWindowId.value);", "inpmLocatorId_DES", "null");
-}
+	}
 
-function enableLocatorShortcut(id) {
-  keyArray[keyArray.length] = new keyArrayItem("ENTER", "openSearch(null, null, '../info/Locator.html', null, false, 'frmMain', 'inpmLocatorId"+id+"', 'inpmLocatorId_DES"+id+"', document.frmMain.inpmLocatorId_DES"+id+".value, 'Command', 'KEY', 'WindowID', document.frmMain.inpWindowId.value);", "inpmLocatorId_DES"+id, "null");
-  activeElementFocus();
-}
+	function enableLocatorShortcut(id) {
+	  keyArray[keyArray.length] = new keyArrayItem("ENTER", "openSearch(null, null, '../info/Locator.html', null, false, 'frmMain', 'inpmLocatorId"+id+"', 'inpmLocatorId_DES"+id+"', document.frmMain.inpmLocatorId_DES"+id+".value, 'Command', 'KEY', 'WindowID', document.frmMain.inpWindowId.value);", "inpmLocatorId_DES"+id, "null");
+	  activeElementFocus();
+	}
 
 
-function calloutSL_CreateLines_Conversion_UOM(varId) {
-submitCommandFormParameter('DEFAULT', frmMain.inpOrderlineId, varId, false, null, '../ad_callouts/SL_CreateLines_Conversion_UOM.html', 'frameOcultoButton',false,false,true);
-return true;
-}
+	function calloutSL_CreateLines_Conversion_UOM(varId) {
+	  submitCommandFormParameter('DEFAULT', frmMain.inpOrderlineId, varId, false, null, '../ad_callouts/SL_CreateLines_Conversion_UOM.html', 'frameOcultoButton',false,false,true);
+	  return true;
+	}
 
-function updateData(clave, marcar) {
-    if (marcar==null) marcar=false;
-    var frm = document.frmMain;
-    frm.elements["inpmovementqty" + clave].disabled=!marcar; 
-    frm.elements["inpquantityorder" + clave].disabled=!marcar;
-    frm.elements["inpmProductUomId" + clave].disabled=!marcar;
-    return true;
-}
+	function updateData(clave, marcar) {
+	  if (marcar==null) marcar=false;
+	  var frm = document.frmMain;
+	  if(frm.elements["inpmProductUomId" + clave].value != '' || frm.elements["inpUomPreference" + clave].value == 'none'){
+	    frm.elements["inpmovementqty" + clave].disabled=!marcar;
+	  }
+	  if(frm.elements["inpmProductUomId" + clave].value != ''){
+	    frm.elements["inpquantityorder" + clave].disabled=!marcar;
+		frm.elements["inpmProductUomId" + clave].disabled=!marcar;
+	  }
+	  else if(frm.elements["inpaumqty" + clave].value != '' && frm.elements["inpmProductUomId" + clave].value == ''){
+	    frm.elements["inpaumqty" + clave].disabled=!marcar;
+	  }
+	  return true;
+	}
 
-function checkAllCreateLines(chk, bolCheck)
-{
-  if (bolCheck==null) bolCheck = false;
-  if (!chk) return false;
-  else if (!chk.length){
-      chk.checked = bolCheck;
-      var frm = document.frmMain;
-      frm.elements["inpmovementqty" + chk.value].disabled=!bolCheck; 
-      frm.elements["inpquantityorder" + chk.value].disabled=!bolCheck;
-      frm.elements["inpmProductUomId" + chk.value].disabled=!bolCheck;
-  }
-  else {
-    var total = chk.length;
-    for (var i=0;i<total;i++) {
-    chk[i].checked = bolCheck;
-    var frm = document.frmMain;
-    frm.elements["inpmovementqty" + chk[i].value].disabled=!bolCheck; 
-    frm.elements["inpquantityorder" + chk[i].value].disabled=!bolCheck;
-    frm.elements["inpmProductUomId" + chk[i].value].disabled=!bolCheck;
-    }
-  }
-  return true;
-    }
+	function checkAllCreateLines(chk, bolCheck)
+	{
+	  if (bolCheck==null) bolCheck = false;
+	  if (!chk) return false;
+	  else if (!chk.length){
+	      chk.checked = bolCheck;
+	      var frm = document.frmMain;
+	      if(frm.elements["inpmProductUomId" + chk.value].value != '' || frm.elements["inpUomPreference" + chk.value].value == 'none'){
+	      	frm.elements["inpmovementqty" + chk.value].disabled=!bolCheck;
+	      }
+	      if(frm.elements["inpmProductUomId" + chk.value].value != ''){
+	      	frm.elements["inpquantityorder" + chk.value].disabled=!bolCheck;
+		    frm.elements["inpmProductUomId" + chk.value].disabled=!bolCheck;
+	      }
+	      if(frm.elements["inpaumqty" + chk.value].value != '' && frm.elements["inpmProductUomId" + chk.value].value == ''){
+	        frm.elements["inpaumqty" + chk.value].disabled=!bolCheck;
+	      }
+	  }
+	  else {
+	    var total = chk.length;
+	    for (var i=0;i<total;i++) {
+		    chk[i].checked = bolCheck;
+		    var frm = document.frmMain;
+		    if(frm.elements["inpmProductUomId" + chk[i].value].value != '' || frm.elements["inpUomPreference" + chk[i].value].value == 'none'){
+		      frm.elements["inpmovementqty" + chk[i].value].disabled=!bolCheck;
+		    }
+		    if(frm.elements["inpmProductUomId" + chk[i].value].value != ''){
+		      frm.elements["inpquantityorder" + chk[i].value].disabled=!bolCheck;
+		      frm.elements["inpmProductUomId" + chk[i].value].disabled=!bolCheck;
+		    }
+		    if(frm.elements["inpaumqty" + chk[i].value].value != '' && frm.elements["inpmProductUomId" + chk[i].value].value == ''){
+		      frm.elements["inpaumqty" + chk[i].value].disabled=!bolCheck;
+		    }
+	    }
+	  }
+	  return true;
+	}
 
+	function updateQty(selKey) {
+	  var frm = document.frmMain;
+	  callback = function (response, data, request) {
+	    frm.elements["inpmovementqty" + selKey].value = data.qty;
+	  };
+	  	
+	  window.parent.parent.parent.OB.RemoteCallManager.call('org.openbravo.common.actionhandler.GetConvertedQtyActionHandler', {
+	    mProductId: frm.elements["inpmProductId" + selKey].value,
+	    qty: frm.elements["inpaumqty" + selKey].value,
+	    toUOM: frm.elements["inpCAUM" + selKey].value
+	  }, {}, callback);
+	}
   </script>
 
   <script language="JavaScript" type="text/javascript">
@@ -480,115 +512,220 @@
       <td>
         <div class="Popup_ContentPane_Client" style="overflow: auto; display: none;" id="client_middle">
           <table cellspacing="0" cellpadding="0" width="100%" class="DataGrid_Header_Table DataGrid_Body_Table" style="table-layout: auto;">
+				<tr class="Popup_Client_Selector_DataGrid_HeaderRow">
+					<th width="29"
+						class="DataGrid_Header_LineNoCell DataGrid_Body_Cell_CheckBox">
+						<span class="Checkbox_container_NOT_Focused"><input
+							type="checkbox" name="inpTodos"
+							onclick="checkAllCreateLines(document.frmMain.inpId, this.checked);return true;"></input></span>
+					</th>
+					<th width="70" class="DataGrid_Header_Cell">Quantity</th>
+					<th width="70" class="DataGrid_Header_Cell">Unit</th>
+					<th width="71" class="DataGrid_Header_Cell" id="headerAumQty"
+						style="xx">Quantity in Alternative UOM</th>
+					<th width="71" class="DataGrid_Header_Cell" id="headerAum"
+						style="xx">Alternative UOM</th>
+					<th width="71" class="DataGrid_Header_Cell" id="headerSecQty"
+						style="xx">Secondary Quantity</th>
+					<th width="71" class="DataGrid_Header_Cell" id="headerSecUom"
+						style="xx">Secondary Unit</th>
+					<th width="129" class="DataGrid_Header_Cell">Product</th>
+					<th width="127" class="DataGrid_Header_Cell">Line</th>
+					<th width="124" class="DataGrid_Header_Cell">Storage Bin</th>
+					<th width="124" class="DataGrid_Header_Cell">Attribute</th>
+				</tr>
+				<div id="sectionDetail">
+					<tr class="DataGrid_Body_Row DataGrid_Body_Row_yy"
+						onclick="selectActual(this); return true;"
+						ondblclick="checkActual(this); return true;"
+						id="funcEvenOddRowxx">
+						<td
+							class="DataGrid_Body_LineNoCell DataGrid_Body_Cell_CheckBox">
+							<span class="Checkbox_container_NOT_Focused"><input
+								type="checkbox" id="inpfieldIDxx" name="inpId"
+								onclick="updateData(this.value, this.checked);checkchilds(document.frmMain['inpBomParent'+this.value], this.checked)"
+								value=""></input><input type="hidden" id="fieldBomParent"
+								name="inpBomParentxx" value=""></input></span>
+						</td>
+						<td class="DataGrid_Body_Cell"><input type="text"
+							id="fieldQuantity"
+							class="dojoValidateValid TextBox_btn_OneCell_width number"
+							required="false" value="" maxlength="10"
+							name="inpmovementqtyxx" disabled="true" onkeyup=""
+							onkeypress="changeToEditingMode();"></input></td>
+						<td class="DataGrid_Body_Cell" onmouseover="HoverCell(this);"
+							onmouseout="unHoverCell(this);" id="fieldCuomName" value="">xxUOM</td>
+						<input type="hidden" id="fieldCuomId" name="inpcUomIdxx"
+							value="0"></input>
+						<td class="DataGrid_Body_Cell" id="showFieldAUMQuantity"
+							style="display: xx;"><input type="zzz"
+							id="fieldAUMQuantity"
+							class="dojoValidateValid TextBox_btn_OneCell_width number"
+							required="false" value="" maxlength="10" name="inpaumqtyxx"
+							disabled="true" onkeyup="updateQty('ff');"
+							onkeypress="changeToEditingMode();"></input></td>
+						<td class="DataGrid_Body_Cell" id="fieldAumUnit"
+							style="display: xx;">xxSelUnit</td>
+						<input type="hidden" id="fieldCAUM" name="inpCAUMxx" value=""></input>
+						<input type="hidden" name="inpUomPreferencexx"
+							id="fieldPreference" value=""></input>
+						<input type="hidden" name="inpHaveSecUOMxx"
+							id="fieldHaveSecUOM" value=""></input>
+						<td class="DataGrid_Body_Cell" id="showFieldSecQuantity"
+							style="display: xx;"><input type="zzz"
+							id="fieldSecQuantity"
+							class="dojoValidateValid TextBox_btn_OneCell_width number"
+							required="false" value="" maxlength="10"
+							name="inpquantityorderxx" disabled="true" onkeyup=""
+							onkeypress="changeToEditingMode();"
+							onchange="logChanges(this);calloutSL_CreateLines_Conversion_UOM('ff');return true;"></input>
+						</td>
+						<td class="DataGrid_Body_Cell" id="showFieldSecUom"
+							style="display: xx;"><select class="DataGrid_Body_Cell"
+							style="display: yyy;" name="inpmProductUomIdxx"
+							id="fieldSecUom" disabled="true"
+							onchange="logChanges(this);calloutSL_CreateLines_Conversion_UOM('ff');return true;"><div
+									id="reportM_Product_Uom_To_ID"></div></select></td>
+						<td class="DataGrid_Body_Cell" onmouseover="HoverCell(this);"
+							onmouseout="unHoverCell(this);" id="fieldMproductid">xxProduct</td>
+						<td class="DataGrid_Body_Cell" onmouseover="HoverCell(this);"
+							onmouseout="unHoverCell(this);" id="fieldPurchaseorder">xxPurchase
+							Order</td>
+						<td class="DataGrid_Body_Cell">
+							<table>
+								<td><input type="text"
+									onfocus="enableLocatorShortcut('xx');"
+									class="dojoValidateValid TextBox_btn_TwoCells_width"
+									required="false" maxlength="22" name="inpmLocatorId_DESxx"
+									id="fieldM_Locator_ID_DES"></input></td>
+								<td><a id="fieldLocatorDES" class="FieldButtonLink"
+									href="#"
+									onfocus="setWindowElementFocus(this); window.status='Locator'; return true;"
+									onblur=" window.status=''; return true;"
+									onkeypress="this.className='FieldButtonLink_active'; return true;"
+									onkeyup="this.className='FieldButtonLink_focus'; return true;"
+									onclick="openSearch(null, null, '../info/Locator.html', null, false, 'frmMain', 'inpmLocatorIdyyy', 'inpmLocatorId_DESvvv', document.frmMain.inpmLocatorId_DESxxx.value, 'WindowID', document.frmMain.inpWindowId.value);return false;">
+										<table class="FieldButton"
+											onmouseout="this.className='FieldButton';window.status='';return true;"
+											onmouseover="this.className='FieldButton_hover';window.status='Locator';return true;"
+											onmousedown="this.className='FieldButton_active';return true;"
+											onmouseup="this.className='FieldButton';return true;">
+											<td class="FieldButton_bg"><img alt="Locator"
+												class="FieldButton_Icon FieldButton_Icon_Locator"
+												title="Locator" src="../../../../../web/images/blank.gif"
+												border="0" id="buttonLocator"></img></td>
 
-            <tr class="Popup_Client_Selector_DataGrid_HeaderRow"> 
-                      <th width="29" class="DataGrid_Header_LineNoCell DataGrid_Body_Cell_CheckBox"> <span class="Checkbox_container_NOT_Focused"><input type="checkbox" name="inpTodos" onclick="checkAllCreateLines(document.frmMain.inpId, this.checked);return true;"></input></span></th>
-                      <th width="70" class="DataGrid_Header_Cell">Quantity</th>
-                      <th width="70" class="DataGrid_Header_Cell">Unit</th>
-                      <th width="71" class="DataGrid_Header_Cell">Secondary Quantity</th>
-                      <th width="71" class="DataGrid_Header_Cell">Secondary Unit</th>
-                      <th width="129" class="DataGrid_Header_Cell">Product</th>
-                      <th width="127" class="DataGrid_Header_Cell">Line</th>
-                      <th width="124" class="DataGrid_Header_Cell">Storage Bin</th>
-                      <th width="124" class="DataGrid_Header_Cell">Attribute</th>
-                    </tr>
-                    <div id="sectionDetail">
-                      <tr class="DataGrid_Body_Row DataGrid_Body_Row_yy" onclick="selectActual(this); return true;" ondblclick="checkActual(this); return true;" id="funcEvenOddRowxx">
-                        <td class="DataGrid_Body_LineNoCell DataGrid_Body_Cell_CheckBox"> <span class="Checkbox_container_NOT_Focused"><input type="checkbox" id="inpfieldIDxx" name="inpId" onclick="updateData(this.value, this.checked);checkchilds(document.frmMain['inpBomParent'+this.value], this.checked)" value=""></input><input type="hidden" id="fieldBomParent" name="inpBomParentxx" value=""></input></span></td>
-                        <td class="DataGrid_Body_Cell">
-                        <input  type="text" id="fieldQuantity" class="dojoValidateValid TextBox_btn_OneCell_width number" required="false" value="" maxlength="10" name="inpmovementqtyxx" disabled="true" onkeyup="" onkeypress="changeToEditingMode();"></input>
-                        </td>
-                        <td class="DataGrid_Body_Cell" onmouseover="HoverCell(this);" onmouseout="unHoverCell(this);" id="fieldCuomName" value="">xxUOM</td>
-                        <input type="hidden" id="fieldCuomId" name="inpcUomIdxx" value="0"></input>
-                        <td class="DataGrid_Body_Cell">
-                        <input type="zzz" id="fieldSecQuantity" class="dojoValidateValid TextBox_btn_OneCell_width number" required="false" value="" maxlength="10" name="inpquantityorderxx" disabled="true" onkeyup="" onkeypress="changeToEditingMode();" onchange="logChanges(this);calloutSL_CreateLines_Conversion_UOM('ff');return true;"></input>
-                        </td>
-                        <td  class="DataGrid_Body_Cell">
-                        <select class="DataGrid_Body_Cell" style="display:yyy;" name="inpmProductUomIdxx" id="fieldSecUom" disabled="true" onchange="logChanges(this);calloutSL_CreateLines_Conversion_UOM('ff');return true;"><div id="reportM_Product_Uom_To_ID"></div></select>
-                        </td>
-                        <td class="DataGrid_Body_Cell" onmouseover="HoverCell(this);" onmouseout="unHoverCell(this);" id="fieldMproductid">xxProduct</td>
-                        <td class="DataGrid_Body_Cell" onmouseover="HoverCell(this);" onmouseout="unHoverCell(this);" id="fieldPurchaseorder">xxPurchase Order</td>
-                        <td class="DataGrid_Body_Cell"> 
-                        <table>
-                        <td>
-                        <input type="text" onfocus="enableLocatorShortcut('xx');" class="dojoValidateValid TextBox_btn_TwoCells_width" required="false" maxlength="22" name="inpmLocatorId_DESxx" id="fieldM_Locator_ID_DES"></input>
-                        </td>
-                        <td>
-                        <a id="fieldLocatorDES" class="FieldButtonLink" href="#" onfocus="setWindowElementFocus(this); window.status='Locator'; return true;" onblur=" window.status=''; return true;" onkeypress="this.className='FieldButtonLink_active'; return true;" onkeyup="this.className='FieldButtonLink_focus'; return true;"  onclick="openSearch(null, null, '../info/Locator.html', null, false, 'frmMain', 'inpmLocatorIdyyy', 'inpmLocatorId_DESvvv', document.frmMain.inpmLocatorId_DESxxx.value, 'WindowID', document.frmMain.inpWindowId.value);return false;" >
-                        <table class="FieldButton"onmouseout="this.className='FieldButton';window.status='';return true;" onmouseover="this.className='FieldButton_hover';window.status='Locator';return true;" onmousedown="this.className='FieldButton_active';return true;" onmouseup="this.className='FieldButton';return true;">
-                            <td class="FieldButton_bg">
-                              <img alt="Locator" class="FieldButton_Icon FieldButton_Icon_Locator" title="Locator" src="../../../../../web/images/blank.gif" border="0" id="buttonLocator"></img>
-                            </td>
-                          
-                        </table>
-                        </a>
-                        </td>
-                        <input type="hidden" name="inpmLocatorIdxx" id="fieldM_Locator_ID" value="">
-                        </table>
-                        </td>
-                        <input style="display:none;" type="text" name="inpmProductIdxxxx_LOC" id="M_Product_ID_LOC" value=""></input>
-                        <input type="text" style="display:none;" name="inpmProductIdyyyy_ATR" id="M_Product_ID_ATR" value=""></input>
-                        <input type="text" style="display:none;" name="inpmProductIdzzzz" id="M_Product_ID" value=""></input>
-                        <td class="TextBox_btn_ContentCell" id="M_AttributeSetInstance_ID_inp_td">
-                          <input type="hidden" name="inpmAttributesetinstanceIdxxx" id="M_AttributeSetInstance_ID" value="" onchange="logChanges(this);return true;"></input>
-                          <table border="0" cellspacing="0" cellpadding="0" summary="" class="">
-                            <tr>
-                              <td class="TextBox_ContentCell">
-                              <table style="border:0px;border-collapse:collapse;">
-                                <tr>
-                                  <td style="padding-top: 0px;">
-                                    
-                                    <input type="text" class="dojoValidateValid readonly TextBox_btn_OneCell_width" tabindex="1" maxlength="22"  name="inpmAttributesetinstanceId_Rxxx" id="M_AttributeSetInstance_ID_R" value="" required="false" onkeypress="changeToEditingMode();" onchange="validateTextBox(this.id);" readonly=true></input>
-                                  </td>
-                                </tr>
-                              </table>
-                          <span class="TextBox_MsgContainer_span" style="display: none;" id="M_AttributeSetInstance_ID_RinvalidSpan">
-                            <table class="TextBox_MsgContainer_table">
-                              <tr class="TextBox_MsgContainer_tr">
-                                <td class="TextBox_MsgContainer_td"><div class="TextBox_MsgContainer_div"></div></td><td></td>
-                              </tr>
-                              <tr>
-                                <td colspan="2" class="invalid"><div class="TextBox_MsgContainer_div2" id="M_AttributeSetInstance_ID_RinvalidSpanText">* The value entered is not valid.</div></td>
-                              </tr>
-                            </table>
-                          </span>
-                          <span class="TextBox_MsgContainer_span" style="display: none;" id="M_AttributeSetInstance_ID_RmissingSpan">
-                            <table class="TextBox_MsgContainer_table">
-                              <tr class="TextBox_MsgContainer_tr">
-                                <td class="TextBox_MsgContainer_td"><div class="TextBox_MsgContainer_div"></div></td><td></td>
-                              </tr>
-                              <tr>
-                                <td colspan="2" class="missing"><div class="TextBox_MsgContainer_div2" id="M_AttributeSetInstance_ID_RmissingSpanText">* This value is required.</div></td>
-                              </tr>
-                            </table>
-                          </span>
-                          <span class="TextBox_MsgContainer_span" style="display: none;" id="M_AttributeSetInstance_ID_RrangeSpan">
-                            <table class="TextBox_MsgContainer_table">
-                              <tr class="TextBox_MsgContainer_tr">
-                                <td class="TextBox_MsgContainer_td"><div class="TextBox_MsgContainer_div"></div></td><td></td>
-                              </tr>
-                              <tr>
-                                <td colspan="2" class="range"><div class="TextBox_MsgContainer_div2" id="M_AttributeSetInstance_ID_RrangeSpanText">* This value is out of range.</div></td>
-                              </tr>
-                            </table>
-                          </span>
-                              </td>
-                              <td class="FieldButton_ContentCell"><a id="fieldAttributeseinstance" class="FieldButtonLink" href="#" onfocus="setWindowElementFocus(this); window.status='Attribute Set Value'; return true;" onblur="window.status=''; return true;" onkeypress="this.className='FieldButtonLink_active'; return true;" onkeyup="this.className='FieldButtonLink_focus'; return true;" 
-                              onclick="openPAttribute(null, null, '../info/AttributeSetInstance.html', null, false, 'frmMain', 'inpmAttributesetinstanceIdxxx', 'inpmAttributesetinstanceId_Ryyy', inputValue(document.frmMain.inpmAttributesetinstanceId_Rvvv), 'inpIDValue', inputValue(document.frmMain.inpmAttributesetinstanceIdwww), 'WindowID', inputValue(document.frmMain.inpwindowId), 'inpKeyValue', inputValue(document.frmMain.inpmAttributesetinstanceIduuu), 'inpwindowId', inputValue(document.frmMain.inpwindowId), 'inpProduct', inputValue(document.frmMain.inpmProductIdzzz));return false;">
-                          <table class="FieldButton" onmousedown="this.className='FieldButton_active'; return true;" onmouseup="this.className='FieldButton'; return true;" onmouseover="this.className='FieldButton_hover'; window.status='Attribute Set Value'; return true;" onmouseout="this.className='FieldButton'; window.status=''; return true;" id="M_AttributeSetInstance_IDlinkAttributeSetInstance">
-                            <tr>
-                              <td class="FieldButton_bg">
-                                <img alt="Attribute Set Value" class="FieldButton_Icon FieldButton_Icon_AttributeSetInstance" title="Attribute Set Value" src="../../../../../web/images/blank.gif" border="0" id="buttonAttributeSetInstance"></img>
-                              </td>
-                            </tr>
-                          </table>
-                        </a>
-                        </td>
-                            </tr>
-                          </table>
-              </tr>
-            </div>
-          </table>
+										</table>
+								</a></td>
+								<input type="hidden" name="inpmLocatorIdxx"
+									id="fieldM_Locator_ID" value="">
+							</table>
+						</td>
+						<input style="display: none;" type="text"
+							name="inpmProductIdxxxx_LOC" id="M_Product_ID_LOC" value=""></input>
+						<input type="text" style="display: none;"
+							name="inpmProductIdyyyy_ATR" id="M_Product_ID_ATR" value=""></input>
+						<input type="text" style="display: none;"
+							name="inpmProductIdzzzz" id="M_Product_ID" value=""></input>
+						<td class="TextBox_btn_ContentCell"
+							id="M_AttributeSetInstance_ID_inp_td"><input
+							type="hidden" name="inpmAttributesetinstanceIdxxx"
+							id="M_AttributeSetInstance_ID" value=""
+							onchange="logChanges(this);return true;"></input>
+							<table border="0" cellspacing="0" cellpadding="0" summary=""
+								class="">
+								<tr>
+									<td class="TextBox_ContentCell">
+										<table style="border: 0px; border-collapse: collapse;">
+											<tr>
+												<td style="padding-top: 0px;"><input type="text"
+													class="dojoValidateValid readonly TextBox_btn_OneCell_width"
+													tabindex="1" maxlength="22"
+													name="inpmAttributesetinstanceId_Rxxx"
+													id="M_AttributeSetInstance_ID_R" value=""
+													required="false" onkeypress="changeToEditingMode();"
+													onchange="validateTextBox(this.id);" readonly=true></input>
+												</td>
+											</tr>
+										</table> <span class="TextBox_MsgContainer_span"
+										style="display: none;"
+										id="M_AttributeSetInstance_ID_RinvalidSpan">
+											<table class="TextBox_MsgContainer_table">
+												<tr class="TextBox_MsgContainer_tr">
+													<td class="TextBox_MsgContainer_td"><div
+															class="TextBox_MsgContainer_div"></div></td>
+													<td></td>
+												</tr>
+												<tr>
+													<td colspan="2" class="invalid"><div
+															class="TextBox_MsgContainer_div2"
+															id="M_AttributeSetInstance_ID_RinvalidSpanText">*
+															The value entered is not valid.</div></td>
+												</tr>
+											</table>
+									</span> <span class="TextBox_MsgContainer_span"
+										style="display: none;"
+										id="M_AttributeSetInstance_ID_RmissingSpan">
+											<table class="TextBox_MsgContainer_table">
+												<tr class="TextBox_MsgContainer_tr">
+													<td class="TextBox_MsgContainer_td"><div
+															class="TextBox_MsgContainer_div"></div></td>
+													<td></td>
+												</tr>
+												<tr>
+													<td colspan="2" class="missing"><div
+															class="TextBox_MsgContainer_div2"
+															id="M_AttributeSetInstance_ID_RmissingSpanText">*
+															This value is required.</div></td>
+												</tr>
+											</table>
+									</span> <span class="TextBox_MsgContainer_span"
+										style="display: none;"
+										id="M_AttributeSetInstance_ID_RrangeSpan">
+											<table class="TextBox_MsgContainer_table">
+												<tr class="TextBox_MsgContainer_tr">
+													<td class="TextBox_MsgContainer_td"><div
+															class="TextBox_MsgContainer_div"></div></td>
+													<td></td>
+												</tr>
+												<tr>
+													<td colspan="2" class="range"><div
+															class="TextBox_MsgContainer_div2"
+															id="M_AttributeSetInstance_ID_RrangeSpanText">*
+															This value is out of range.</div></td>
+												</tr>
+											</table>
+									</span>
+									</td>
+									<td class="FieldButton_ContentCell"><a
+										id="fieldAttributeseinstance" class="FieldButtonLink"
+										href="#"
+										onfocus="setWindowElementFocus(this); window.status='Attribute Set Value'; return true;"
+										onblur="window.status=''; return true;"
+										onkeypress="this.className='FieldButtonLink_active'; return true;"
+										onkeyup="this.className='FieldButtonLink_focus'; return true;"
+										onclick="openPAttribute(null, null, '../info/AttributeSetInstance.html', null, false, 'frmMain', 'inpmAttributesetinstanceIdxxx', 'inpmAttributesetinstanceId_Ryyy', inputValue(document.frmMain.inpmAttributesetinstanceId_Rvvv), 'inpIDValue', inputValue(document.frmMain.inpmAttributesetinstanceIdwww), 'WindowID', inputValue(document.frmMain.inpwindowId), 'inpKeyValue', inputValue(document.frmMain.inpmAttributesetinstanceIduuu), 'inpwindowId', inputValue(document.frmMain.inpwindowId), 'inpProduct', inputValue(document.frmMain.inpmProductIdzzz));return false;">
+											<table class="FieldButton"
+												onmousedown="this.className='FieldButton_active'; return true;"
+												onmouseup="this.className='FieldButton'; return true;"
+												onmouseover="this.className='FieldButton_hover'; window.status='Attribute Set Value'; return true;"
+												onmouseout="this.className='FieldButton'; window.status=''; return true;"
+												id="M_AttributeSetInstance_IDlinkAttributeSetInstance">
+												<tr>
+													<td class="FieldButton_bg"><img
+														alt="Attribute Set Value"
+														class="FieldButton_Icon FieldButton_Icon_AttributeSetInstance"
+														title="Attribute Set Value"
+														src="../../../../../web/images/blank.gif" border="0"
+														id="buttonAttributeSetInstance"></img></td>
+												</tr>
+											</table>
+									</a></td>
+								</tr>
+							</table>
+					</tr>
+				</div>
+			</table>
         </div>
       </td>
     </tr>
--- a/src/org/openbravo/erpCommon/ad_actionButton/CreateFrom_ShipmentPO.xml	Fri Nov 11 10:01:28 2016 +0100
+++ b/src/org/openbravo/erpCommon/ad_actionButton/CreateFrom_ShipmentPO.xml	Fri Nov 11 10:06:34 2016 +0100
@@ -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-2014 Openbravo SLU 
+ * All portions are Copyright (C) 2001-2016 Openbravo SLU 
  * All Rights Reserved. 
  * Contributor(s):  ______________________________________.
  ************************************************************************
@@ -53,7 +53,12 @@
   <PARAMETER id="messageBoxID" name="messageType" attribute="class" replace="yy" default="HIDDEN"/>
   <PARAMETER id="messageBoxIDTitle" name="messageTitle" default=""/>
   <PARAMETER id="messageBoxIDMessage" name="messageMessage" default=""/>
-
+  
+  <PARAMETER id="headerAumQty" name="uompreference" attribute="style" replace="xx"/>
+  <PARAMETER id="headerAum" name="uompreference" attribute="style" replace="xx"/>
+  <PARAMETER id="headerSecQty" name="havesecuom" attribute="style" replace="xx"/>
+  <PARAMETER id="headerSecUom" name="havesecuom" attribute="style" replace="xx"/>
+  
     <PARAMETER id="param2" name="param2" default="2"/>
     <PARAMETER id="paramCheck" name="check" default="N"/>
     <structure name="structure1">
@@ -69,6 +74,13 @@
         <FIELD id="fieldBomParent" attribute="name" replace="xx">bom_parent_id</FIELD>
         <FIELD id="fieldQuantity" attribute="value" format="qtyEdition">qty</FIELD>
         <FIELD id="fieldQuantity" attribute="name" replace="xx">id</FIELD>
+        <FIELD id="fieldAUMQuantity" attribute="value" format="qtyEdition">aumqty</FIELD>
+        <FIELD id="fieldAUMQuantity" attribute="name" replace="xx">id</FIELD>
+        <FIELD id="fieldAUMQuantity" attribute="onkeyup" replace="ff">id</FIELD>
+        <FIELD id="fieldAUMQuantity" attribute="type" replace="zzz">haveuompreference</FIELD>
+        <FIELD id="fieldAumUnit" replaceCharacters="html">aumname</FIELD>
+        <FIELD id="fieldCAUM" attribute="name" replace="xx">id</FIELD>
+        <FIELD id="fieldCAUM" attribute="value">cAum</FIELD>
         <FIELD id="fieldSecQuantity" attribute="value" format="qtyEdition">secqty</FIELD>
         <FIELD id="fieldSecQuantity" attribute="name" replace="xx">id</FIELD>
         <FIELD id="fieldSecQuantity" attribute="type" replace="zzz">havesec</FIELD>
@@ -76,6 +88,16 @@
         <FIELD id="fieldCuomName" replaceCharacters="html">uomsymbol</FIELD>
         <FIELD id="fieldCuomId" attribute="name" replace="xx">id</FIELD>
         <FIELD id="fieldCuomId" attribute="value">cUomId</FIELD>
+        <!-- Show/hidde Aum and Sec columns -->
+        <FIELD id="showFieldAUMQuantity" attribute="style" replace="xx">uompreference</FIELD>
+        <FIELD id="fieldAumUnit" attribute="style" replace="xx">uompreference</FIELD>
+        <FIELD id="showFieldSecQuantity" attribute="style" replace="xx">havesecuom</FIELD>
+        <FIELD id="showFieldSecUom" attribute="style" replace="xx">havesecuom</FIELD>
+        <FIELD id="fieldPreference" attribute="name" replace="xx">id</FIELD>
+        <FIELD id="fieldPreference" attribute="value" >uompreference</FIELD>
+        <FIELD id="fieldHaveSecUOM" attribute="name" replace="xx">id</FIELD>
+        <FIELD id="fieldHaveSecUOM" attribute="value" >havesecuom</FIELD>
+        <!-- Show/hidde Aum and Sec column -->
         <FIELD id="fieldMproductid" replaceCharacters="html">relationName</FIELD>
         <FIELD id="fieldPurchaseorder">line</FIELD>
         <FIELD id="fieldSecUom" attribute="name" replace="xx">id</FIELD>
--- a/src/org/openbravo/erpCommon/ad_actionButton/CreateFrom_Shipment_data.xsql	Fri Nov 11 10:01:28 2016 +0100
+++ b/src/org/openbravo/erpCommon/ad_actionButton/CreateFrom_Shipment_data.xsql	Fri Nov 11 10:06:34 2016 +0100
@@ -35,6 +35,7 @@
         l.C_OrderLine_ID AS ID, '' AS C_Invoice_ID, l.DESCRIPTION AS DESCRIPTION,
         (l.quantityorder - C_UOM_CONVERT(SUM(COALESCE(m.Qty,0)), l.C_UOM_ID, mpu.C_UOM_ID, 'Y'))
         as SECQTY, l.M_PRODUCT_UOM_ID as SEC_PRODUCT_UOM_ID,
+        l.AUMQTY AS AUMQTY, l.C_AUM AS C_AUM, (SELECT UOMSYMBOL FROM C_UOM WHERE C_UOM_ID = l.C_AUM) AS AUMNAME, '' AS UOMPREFERENCE, '' AS HAVEUOMPREFERENCE,
         (SELECT M_ATTRIBUTESETINSTANCE.DESCRIPTION FROM M_ATTRIBUTESETINSTANCE WHERE 
         l.M_ATTRIBUTESETINSTANCE_ID = M_ATTRIBUTESETINSTANCE.M_ATTRIBUTESETINSTANCE_ID) as ATTRIBUTESETINSTANCENAME, 
         (SELECT C_UOM.NAME FROM M_PRODUCT_UOM, C_UOM WHERE M_PRODUCT_UOM_ID = l.M_PRODUCT_UOM_ID AND M_PRODUCT_UOM.C_UOM_ID = C_UOM.C_UOM_ID) as SECUOMSYMBOL,
@@ -43,7 +44,7 @@
         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, l.bom_parent_id, CASE WHEN l.Bom_parent_id is null then 'Y' else 'N' END as isparent, 
-        '' as isorder
+        '' 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 mpu on mpu.M_PRODUCT_UOM_ID =l.M_PRODUCT_UOM_ID,  
@@ -59,9 +60,9 @@
         AND l.M_Product_ID=p.M_Product_ID
         AND l.C_Order_ID = ? 
         GROUP BY o.C_ORDER_ID, o.DocumentNo, o.DateOrdered, o.GrandTotal, l.QtyOrdered,l.qtydelivered, 
-        l.C_UOM_ID,uom.UOMSymbol,l.M_Product_ID,p.NAME,l.Line,l.C_OrderLine_ID, l.ad_org_id, l.DESCRIPTION, l.QUANTITYORDER, 
+        l.C_UOM_ID, l.AUMQTY, l.C_AUM, uom.UOMSymbol,l.M_Product_ID,p.NAME,l.Line,l.C_OrderLine_ID, l.ad_org_id, l.DESCRIPTION, l.QUANTITYORDER, 
         l.M_PRODUCT_UOM_ID, l.M_ATTRIBUTESETINSTANCE_ID, 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) ,mpu.C_UOM_ID, l.explode, l.bom_parent_id
+        coalesce(l.user1_id,o.user1_id), coalesce(l.user2_id,o.user2_id), coalesce (l.c_bpartner_id,o.c_bpartner_id) ,mpu.C_UOM_ID, l.explode, l.bom_parent_id, o.C_DOCTYPE_ID, uom.C_UOM_ID
         HAVING ((l.explode='Y')  OR ((l.QtyOrdered-SUM(COALESCE(m.Qty,0)))<>0)) 
         ORDER BY NAME, l.Line
       ]]>
@@ -110,7 +111,8 @@
         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.Bom_parent_id, CASE WHEN l.Bom_parent_id is null then 'Y' else 'N' END as isparent
+		coalesce (l.c_bpartner_id,o.c_bpartner_id) as c_bpartner_id, l.Bom_parent_id, CASE WHEN l.Bom_parent_id is null then 'Y' else 'N' END as isparent,
+		l.AUMQTY 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 M_INOUT_CANDIDATE_V ic, C_ORDER o, C_UOM uom, C_ORDERLINE l, M_PRODUCT p 
         WHERE o.C_ORDER_ID = l.C_ORDER_ID
         AND o.C_ORDER_ID = ic.C_ORDER_ID 
@@ -124,7 +126,7 @@
         l.C_UOM_ID,uom.UOMSymbol,l.M_Product_ID,p.NAME,l.Line,l.C_OrderLine_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.Bom_parent_id
+		l.Bom_parent_id, l.AUMQTY, l.C_AUM
         ORDER BY NAME, l.Line
       ]]>
     </Sql>
@@ -186,7 +188,8 @@
         l.M_ATTRIBUTESETINSTANCE_ID = M_ATTRIBUTESETINSTANCE.M_ATTRIBUTESETINSTANCE_ID) as ATTRIBUTESETINSTANCENAME,
         (SELECT C_UOM.NAME FROM M_PRODUCT_UOM, C_UOM WHERE M_PRODUCT_UOM_ID = l.M_PRODUCT_UOM_ID 
         AND M_PRODUCT_UOM.C_UOM_ID = C_UOM.C_UOM_ID) as SECUOMSYMBOL,
-        COALESCE(l.M_PRODUCT_UOM_ID,null,'0') as HAVESEC,'' AS LOCATOR
+        COALESCE(l.M_PRODUCT_UOM_ID,null,'0') as HAVESEC,'' AS LOCATOR,
+        l.AUMQTY 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_UOM uom left join C_UOM_TRL uomt on uom.C_UOM_ID = uomt.C_UOM_ID
                                                 and uomt.AD_Language  = ?,
               C_ORDERLINE l left join M_MATCHPO m  on l.C_OrderLine_ID=m.C_OrderLine_ID
@@ -201,7 +204,7 @@
         AND l.M_Product_ID=p.M_Product_ID
         AND l.C_Order_ID = ? 
         GROUP BY o.C_ORDER_ID, o.DocumentNo, o.DateOrdered, o.GrandTotal, l.QtyOrdered,l.qtydelivered, 
-        l.C_UOM_ID,uom.UOMSymbol, uomt.UOMSymbol,l.M_Product_ID,p.NAME,l.Line,l.C_OrderLine_ID, l.DESCRIPTION, l.QUANTITYORDER, l.M_PRODUCT_UOM_ID, l.M_ATTRIBUTESETINSTANCE_ID
+        l.C_UOM_ID,uom.UOMSymbol, l.AUMQTY, l.C_AUM, uomt.UOMSymbol,l.M_Product_ID,p.NAME,l.Line,l.C_OrderLine_ID, l.DESCRIPTION, l.QUANTITYORDER, l.M_PRODUCT_UOM_ID, l.M_ATTRIBUTESETINSTANCE_ID
         HAVING (l.QtyOrdered-SUM(COALESCE(m.Qty,0))) <> 0
         ORDER BY NAME, l.Line
       ]]>
@@ -220,7 +223,8 @@
       <![CDATA[
         SELECT o.C_ORDER_ID, Ad_Column_Identifier(TO_CHAR('C_Order'), TO_CHAR(o.c_order_id), TO_CHAR(?)) AS NAME, 
         l.QtyOrdered-COALESCE(l.qtydelivered,0) AS QTY, l.C_UOM_ID, COALESCE(uomt.UOMSymbol, uom.UOMSymbol) AS UOMSymbol, 
-        l.M_Product_ID,Ad_Column_Identifier(TO_CHAR('M_Product'), TO_CHAR(l.m_product_id), TO_CHAR(?)) AS RELATION_NAME, l.C_OrderLine_ID, l.Line, l.C_OrderLine_ID AS ID, l.DESCRIPTION AS DESCRIPTION
+        l.M_Product_ID,Ad_Column_Identifier(TO_CHAR('M_Product'), TO_CHAR(l.m_product_id), TO_CHAR(?)) AS RELATION_NAME, l.C_OrderLine_ID, l.Line, l.C_OrderLine_ID AS ID, l.DESCRIPTION AS DESCRIPTION,
+        l.AUMQTY 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_UOM uom left join C_UOM_TRL uomt on uom.C_UOM_ID = uomt.C_UOM_ID
                                                 and uomt.AD_Language = ?,
         M_INOUT_CANDIDATE_V ic, C_ORDER o,   C_ORDERLINE l, M_PRODUCT p 
@@ -233,7 +237,8 @@
         AND ic.C_Order_ID = ?
         AND l.QtyOrdered <> COALESCE(l.qtydelivered,0)
         GROUP BY o.C_ORDER_ID, o.DocumentNo, o.DateOrdered, o.GrandTotal, l.QtyOrdered,l.qtydelivered, 
-        l.C_UOM_ID,uom.UOMSymbol,uomt.UOMSymbol,l.M_Product_ID,p.NAME,l.Line,l.C_OrderLine_ID, l.DESCRIPTION
+        l.C_UOM_ID,uom.UOMSymbol,uomt.UOMSymbol,l.M_Product_ID,p.NAME,l.Line,l.C_OrderLine_ID, l.DESCRIPTION,
+        l.AUMQTY, l.C_AUM
         ORDER BY NAME, l.Line
       ]]>
     </Sql>
@@ -249,7 +254,7 @@
     <SqlMethodComment></SqlMethodComment>
     <Sql>
       <![CDATA[
-      SELECT l.QtyOrdered-SUM(COALESCE(m.Qty,0)) AS ID, l.C_UOM_ID,uom.UOMSymbol, l.M_Product_ID,Ad_Column_Identifier(to_char('M_Product'), to_char(l.m_product_id), to_char(?)) AS NAME, l.C_OrderLine_ID,
+      SELECT l.QtyOrdered-SUM(COALESCE(m.Qty,0)) AS ID, l.C_UOM_ID, l.AUMQTY, l.C_AUM, uom.UOMSymbol, l.M_Product_ID,Ad_Column_Identifier(to_char('M_Product'), to_char(l.m_product_id), to_char(?)) AS NAME, l.C_OrderLine_ID,
       l.Line, '' as C_InvoiceLine_ID, '' as M_InOutLine_ID, COALESCE(uom1.BREAKDOWN, 'N') AS BREAKDOWN, 
       MAX(mu.C_UOM_ID) AS C_UOM_ID_Conversion, MAX(uom1.STDPRECISION) AS STDPRECISION, 
       l.QUANTITYORDER*C_DIVIDE((l.QtyOrdered-SUM(COALESCE(m.Qty,0))),(l.QtyOrdered)) AS quantityOrder, l.M_Product_UOM_ID,
@@ -266,7 +271,7 @@
       WHERE l.C_UOM_ID=uom.C_UOM_ID
       AND l.M_Product_ID=p.M_Product_ID
       AND o.C_ORDER_ID = l.C_ORDER_ID 
-      GROUP BY l.QtyOrdered,l.qtydelivered,l.C_UOM_ID,uom.UOMSymbol,l.M_Product_ID,p.NAME,l.Line,l.C_OrderLine_ID, 
+      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 
@@ -281,7 +286,7 @@
     <SqlMethodComment></SqlMethodComment>
     <Sql>
       <![CDATA[
-      SELECT l.QtyOrdered - COALESCE(l.QTYDELIVERED,0) AS ID, l.C_UOM_ID,uom.UOMSymbol, l.M_Product_ID,Ad_Column_Identifier(to_char('M_Product'), to_char(l.m_product_id), to_char(?)) AS NAME, 
+      SELECT l.QtyOrdered - COALESCE(l.QTYDELIVERED,0) AS ID, l.C_UOM_ID, l.AUMQTY, l.C_AUM, uom.UOMSymbol, l.M_Product_ID,Ad_Column_Identifier(to_char('M_Product'), to_char(l.m_product_id), to_char(?)) AS NAME, 
       l.C_OrderLine_ID, l.Line, '' as C_InvoiceLine_ID, '' as M_InOutLine_ID, COALESCE(uom1.BREAKDOWN, 'N') AS BREAKDOWN, 
       MAX(mu.C_UOM_ID) AS C_UOM_ID_Conversion, MAX(uom1.STDPRECISION) AS STDPRECISION, 
       l.QUANTITYORDER*C_DIVIDE((l.QtyOrdered - COALESCE(l.QTYDELIVERED,0)),(l.QtyOrdered)) as quantityOrder, l.M_Product_UOM_ID,
@@ -296,7 +301,7 @@
       WHERE l.C_UOM_ID=uom.C_UOM_ID
       AND o.C_ORDER_ID = l.C_ORDER_ID    
       AND l.M_Product_ID=p.M_Product_ID
-      GROUP BY l.QtyOrdered,l.qtydelivered,l.C_UOM_ID,uom.UOMSymbol,l.M_Product_ID,p.NAME,l.Line,l.C_OrderLine_ID, 
+      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
@@ -328,7 +333,8 @@
         (SELECT C_UOM.NAME FROM M_PRODUCT_UOM, C_UOM WHERE M_PRODUCT_UOM_ID = l.M_PRODUCT_UOM_ID AND M_PRODUCT_UOM.C_UOM_ID = C_UOM.C_UOM_ID) as SECUOMSYMBOL,
         COALESCE(l.M_PRODUCT_UOM_ID,null,'0') as HAVESEC,'' as HAVESECUOM,'' AS LOCATOR,l.M_ATTRIBUTESETINSTANCE_ID AS M_ATTRIBUTESETINSTANCE_ID,
         (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
+        CASE WHEN l.Bom_parent_id is null then 'Y' else 'N' END as isparent,
+        l.AUMQTY 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_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 
@@ -342,6 +348,7 @@
         GROUP BY i.C_Invoice_ID, i.DocumentNo, DateInvoiced, GrandTotal, l.QtyInvoiced, 
         l.C_UOM_ID,uom.UOMSymbol,l.M_Product_ID,p.NAME, l.C_InvoiceLine_ID,l.Line,l.C_OrderLine_ID, l.DESCRIPTION,l.QUANTITYORDER,
         l.M_PRODUCT_UOM_ID,l.M_ATTRIBUTESETINSTANCE_ID,  coalesce(l.a_asset_id,i.a_asset_id), coalesce(l.c_project_id,i.c_project_id), 
+        l.AUMQTY, l.C_AUM, 
         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, l.bom_parent_id
         HAVING ((l.explode='Y')  OR (l.QtyInvoiced-SUM(COALESCE(mi.Qty,0))<>0))   
@@ -366,7 +373,8 @@
         l.DESCRIPTION AS DESCRIPTION,
         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, l.Bom_parent_id,
-        CASE  WHEN l.Bom_parent_id is null then 'Y' else 'N' END as isparent
+        CASE  WHEN l.Bom_parent_id is null then 'Y' else 'N' END as isparent,
+        l.AUMQTY 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_INOUTLINE mi on l.M_INOUTLINE_ID = mi.M_INOUTLINE_ID,
         C_INVOICE i, C_UOM uom,  M_PRODUCT p
         WHERE i.C_INVOICE_ID = l.C_INVOICE_ID 
@@ -378,6 +386,7 @@
         AND l.C_Invoice_ID = ?
         GROUP BY i.C_Invoice_ID, i.DocumentNo, DateInvoiced, GrandTotal, l.QtyInvoiced, 
         l.C_UOM_ID,uom.UOMSymbol,l.M_Product_ID,p.NAME, l.C_InvoiceLine_ID,l.Line,l.C_OrderLine_ID, l.DESCRIPTION,
+        l.AUMQTY, l.C_AUM,
         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, l.Bom_parent_id
         HAVING ((l.explode='Y')  OR ((l.QtyInvoiced-SUM(COALESCE(mi.MOVEMENTQTY,0))) <> 0))  
@@ -470,7 +479,8 @@
         COALESCE(l.M_PRODUCT_UOM_ID,null,'0') as HAVESEC,'' as HAVESECUOM,'' AS LOCATOR,
         l.M_ATTRIBUTESETINSTANCE_ID AS M_ATTRIBUTESETINSTANCE_ID,
         (SELECT M_ATTRIBUTESETINSTANCE.DESCRIPTION FROM M_ATTRIBUTESETINSTANCE 
-        WHERE l.M_ATTRIBUTESETINSTANCE_ID = M_ATTRIBUTESETINSTANCE.M_ATTRIBUTESETINSTANCE_ID) as ATTRIBUTESETINSTANCENAME
+        WHERE l.M_ATTRIBUTESETINSTANCE_ID = M_ATTRIBUTESETINSTANCE.M_ATTRIBUTESETINSTANCE_ID) as ATTRIBUTESETINSTANCENAME,
+        l.AUMQTY 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_UOM uom left join C_UOM_TRL uomt on uom.C_UOM_ID = uomt.C_UOM_ID
                                                AND uomt.AD_Language  = ?,
              C_INVOICELINE l left join M_MATCHINV mi on l.C_InvoiceLine_ID=mi.C_InvoiceLine_ID,
@@ -485,6 +495,7 @@
         AND l.C_Invoice_ID = ? 
         GROUP BY i.C_Invoice_ID, i.DocumentNo, DateInvoiced, GrandTotal, l.QtyInvoiced, 
         l.C_UOM_ID,uom.UOMSymbol, uomt.UOMSymbol,l.M_Product_ID,p.NAME, l.C_InvoiceLine_ID,l.Line,l.C_OrderLine_ID, 
+        l.AUMQTY, l.C_AUM,
         l.DESCRIPTION, l.QUANTITYORDER, l.M_PRODUCT_UOM_ID,l.M_ATTRIBUTESETINSTANCE_ID
         HAVING (l.QtyInvoiced-SUM(COALESCE(mi.Qty,0))) <> 0 
         ORDER BY NAME, l.Line
@@ -510,7 +521,8 @@
       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,
+      l.AUMQTY 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 
                            left join C_UOM uom1 on mu.C_UOM_ID = uom1.C_UOM_ID 
                            left join M_MATCHINV mi on l.C_InvoiceLine_ID=mi.C_InvoiceLine_ID,
@@ -520,7 +532,7 @@
       AND i.C_INVOICE_ID = l.C_INVOICE_ID 
       GROUP BY l.QtyInvoiced,
       l.C_UOM_ID,uom.UOMSymbol,l.M_Product_ID,p.NAME, l.C_InvoiceLine_ID,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, l.C_INVOICE_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
       HAVING ((l.explode='Y')  OR (l.QtyInvoiced-SUM(COALESCE(mi.Qty,0))<>0))   
@@ -542,7 +554,8 @@
       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,
+      l.AUMQTY 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 
                            left join C_UOM uom1 on mu.C_UOM_ID = uom1.C_UOM_ID 
                            left join M_INOUTLINE mi on l.M_INOUTLINE_ID=mi.M_INOUTLINE_ID,
@@ -553,6 +566,7 @@
       AND l.M_Product_ID=p.M_Product_ID 
       GROUP BY l.QtyInvoiced,
       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,
       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
@@ -596,7 +610,7 @@
         (M_InOutLine_ID,M_InOut_ID, AD_Client_ID,AD_Org_ID,
          IsActive,Created,CreatedBy,Updated, UpdatedBy, 
          Line,Description, M_Product_ID,
-         C_UOM_ID,MovementQty,C_OrderLine_ID,
+         C_UOM_ID,MovementQty,AUMQTY,C_AUM,C_OrderLine_ID,
          M_Locator_ID,IsInvoiced, QUANTITYORDER, 
       M_PRODUCT_UOM_ID, M_ATTRIBUTESETINSTANCE_ID,
       A_ASSET_ID, C_PROJECT_ID, C_COSTCENTER_ID,
@@ -605,7 +619,7 @@
         (?, ?, ?, ?, 
          'Y', now(), ?, now(), ?, 
          (SELECT (COALESCE(Max(Line),0))+10 FROM M_InOutLine WHERE M_InOut_ID=?), ?, ?, 
-         ?, TO_NUMBER(?), ?, 
+         ?, TO_NUMBER(?), TO_NUMBER(?), ?, ?, 
          ?, ?, TO_NUMBER(?), 
          ?, ?,
          ?, ?, ?,
@@ -631,6 +645,8 @@
     <Parameter name="mProductId"/>
     <Parameter name="cUomId"/>
     <Parameter name="movementqty"/>
+    <Parameter name="aumqty"/>
+    <Parameter name="cAum"/>
     <Parameter name="cOrderlineId"/>
     <Parameter name="mLocatorId"/>
     <Parameter name="isinvoiced"/>
@@ -866,4 +882,28 @@
     <Field name="rownum" value="count"/>
     <Parameter name="mInoutId"/>
     </SqlMethod>
+    <SqlMethod name="hasSecondaryUOM" type="preparedStatement" return="string">
+      <SqlMethodComment></SqlMethodComment>
+      <Sql><![CDATA[
+        SELECT (CASE COUNT(*) WHEN 0 THEN 0 ELSE 1 END)
+        FROM M_PRODUCT_UOM
+        WHERE M_PRODUCT_ID = ?
+        AND ISACTIVE = 'Y'
+      ]]></Sql>
+      <Parameter name="mProductId"></Parameter>
+   </SqlMethod>
+   <SqlMethod name="selectAUMDefault" type="preparedStatement" return="multiple">
+     <SqlMethodComment></SqlMethodComment>
+     <Sql>
+       <![CDATA[
+         SELECT M_GET_DEFAULT_AUM_FOR_DOCUMENT(?, ?) AS C_AUM, 
+           (SELECT UOMSYMBOL FROM C_UOM WHERE C_UOM_ID = M_GET_DEFAULT_AUM_FOR_DOCUMENT(?, ?)) AS AUMNAME
+         FROM DUAL  
+       ]]>
+     </Sql>
+     <Parameter name="mProductId"/>
+     <Parameter name="cDoctypeId"/>
+     <Parameter name="mProductId"/>
+     <Parameter name="cDoctypeId"/>
+   </SqlMethod>
 </SqlClass>
--- a/src/org/openbravo/erpCommon/ad_callouts/SL_InOutLine_Product.java	Fri Nov 11 10:01:28 2016 +0100
+++ b/src/org/openbravo/erpCommon/ad_callouts/SL_InOutLine_Product.java	Fri Nov 11 10:06:34 2016 +0100
@@ -24,10 +24,14 @@
 import org.openbravo.dal.core.OBContext;
 import org.openbravo.dal.service.OBDal;
 import org.openbravo.data.FieldProvider;
+import org.openbravo.erpCommon.businessUtility.Preferences;
 import org.openbravo.erpCommon.utility.ComboTableData;
+import org.openbravo.erpCommon.utility.PropertyException;
 import org.openbravo.erpCommon.utility.Utility;
+import org.openbravo.materialmgmt.CentralBroker;
 import org.openbravo.model.common.plm.AttributeSet;
 import org.openbravo.model.common.plm.Product;
+import org.openbravo.model.materialmgmt.transaction.ShipmentInOut;
 
 public class SL_InOutLine_Product extends SimpleCallout {
 
@@ -92,6 +96,17 @@
     String strQtyOrder = info.vars.getNumericParameter("inpmProductId_PQTY");
     String strmInoutlineId = info.vars.getStringParameter("inpmInoutlineId");
     String strQty = info.vars.getNumericParameter("inpmProductId_QTY");
+    String strHasSecondaryUOM = SLOrderProductData.hasSecondaryUOM(this, strMProductID);
+    String propertyValue = "N";
+    String strUOMProduct = info.vars.getStringParameter("inpmProductUomId");
+
+    try {
+      propertyValue = Preferences.getPreferenceValue("UomManagement", true, OBContext
+          .getOBContext().getCurrentClient(), OBContext.getOBContext().getCurrentOrganization(),
+          OBContext.getOBContext().getUser(), OBContext.getOBContext().getRole(), null);
+    } catch (PropertyException e) {
+      log4j.debug("Preference UomManagement not found", e);
+    }
 
     // This 'if' is used when the delivery note is created based in a
     // sale-order, to make it not ask for the quantity of the delivery-note
@@ -102,43 +117,62 @@
     if (fromOrder.equals("0")) {
       info.addResult("inpquantityorder", StringUtils.isEmpty(strQtyOrder) ? "\"\""
           : (Object) strQtyOrder);
+      if (strHasSecondaryUOM.equals("1")
+          && (!propertyValue.equalsIgnoreCase("Y") || (propertyValue.equalsIgnoreCase("Y") && !""
+              .equals(strUOMProduct)))) {
+        info.addResult("inpquantityorder", StringUtils.isEmpty(strQtyOrder) ? "\"\""
+           : (Object) strQtyOrder);
+      }
       info.addResult("inpmovementqty", StringUtils.isEmpty(strQty) ? "\"\"" : (Object) strQty);
     }
 
+    if (propertyValue.equalsIgnoreCase("Y") && "".equals(strUOMProduct)) {
+      // Set AUM based on default
+
+      ShipmentInOut mInOut = OBDal.getInstance().get(ShipmentInOut.class,
+          info.vars.getStringParameter("inpmInoutId"));
+      String finalAUM = CentralBroker.getInstance().getDefaultAUMForDocument(strMProductID,
+          mInOut.getDocumentType().getId());
+      if (finalAUM != null) {
+        info.addResult("inpcAum", finalAUM);
+      }
+    }
+
     // Secondary UOM
 
+    if (strHasSecondaryUOM.equals("1")
+      && (!propertyValue.equalsIgnoreCase("Y") || (propertyValue.equalsIgnoreCase("Y") && !""
+          .equals(strUOMProduct)))) {
     String strPUOM = info.vars.getStringParameter("inpmProductId_PUOM");
-
-    String strHasSecondaryUOM = SLOrderProductData.hasSecondaryUOM(this, strMProductID);
     info.addResult("inphasseconduom", (Object) strHasSecondaryUOM);
 
     if (strPUOM.startsWith("\"")) {
       strPUOM = strPUOM.substring(1, strPUOM.length() - 1);
     }
+      FieldProvider[] tld = null;
+      try {
+        ComboTableData comboTableData = new ComboTableData(info.vars, this, "TABLE", "",
+            "M_Product_UOM", "", Utility.getContext(this, info.vars, "#AccessibleOrgTree",
+                "SLOrderProduct"), Utility.getContext(this, info.vars, "#User_Client",
+                "SLOrderProduct"), 0);
+        Utility.fillSQLParameters(this, info.vars, null, comboTableData, "SLOrderProduct", "");
+        tld = comboTableData.select(false);
+        comboTableData = null;
+      } catch (Exception ex) {
+        throw new ServletException(ex);
+      }
 
-    FieldProvider[] tld = null;
-    try {
-      ComboTableData comboTableData = new ComboTableData(info.vars, this, "TABLE", "",
-          "M_Product_UOM", "", Utility.getContext(this, info.vars, "#AccessibleOrgTree",
-              "SLOrderProduct"), Utility.getContext(this, info.vars, "#User_Client",
-              "SLOrderProduct"), 0);
-      Utility.fillSQLParameters(this, info.vars, null, comboTableData, "SLOrderProduct", "");
-      tld = comboTableData.select(false);
-      comboTableData = null;
-    } catch (Exception ex) {
-      throw new ServletException(ex);
-    }
-
-    if (tld != null && tld.length > 0) {
-      info.addSelect("inpmProductUomId");
-      for (int i = 0; i < tld.length; i++) {
-        info.addSelectResult(tld[i].getField("id"), tld[i].getField("name"), tld[i].getField("id")
-            .equalsIgnoreCase(strPUOM));
-      }
-      info.endSelect();
-    } else {
-      info.addResult("inpmProductUomId", null);
-    }
+      if (tld != null && tld.length > 0) {
+        info.addSelect("inpmProductUomId");
+        for (int i = 0; i < tld.length; i++) {
+          info.addSelectResult(tld[i].getField("id"), tld[i].getField("name"), tld[i]
+              .getField("id").equalsIgnoreCase(strPUOM));
+        }
+        info.endSelect();
+      } else {
+        info.addResult("inpmProductUomId", null);
+     }
+   }
 
     // UOM
 
--- a/src/org/openbravo/erpCommon/ad_callouts/SL_Invoice_Product.java	Fri Nov 11 10:01:28 2016 +0100
+++ b/src/org/openbravo/erpCommon/ad_callouts/SL_Invoice_Product.java	Fri Nov 11 10:06:34 2016 +0100
@@ -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-2013 Openbravo SLU 
+ * All portions are Copyright (C) 2001-2016 Openbravo SLU 
  * All Rights Reserved. 
  * Contributor(s):  ______________________________________.
  ************************************************************************
@@ -35,11 +35,14 @@
 import org.openbravo.data.FieldProvider;
 import org.openbravo.erpCommon.businessUtility.PAttributeSet;
 import org.openbravo.erpCommon.businessUtility.PAttributeSetData;
+import org.openbravo.erpCommon.businessUtility.Preferences;
 import org.openbravo.erpCommon.businessUtility.PriceAdjustment;
 import org.openbravo.erpCommon.businessUtility.Tax;
 import org.openbravo.erpCommon.utility.AccDefUtility;
 import org.openbravo.erpCommon.utility.ComboTableData;
+import org.openbravo.erpCommon.utility.PropertyException;
 import org.openbravo.erpCommon.utility.Utility;
+import org.openbravo.materialmgmt.CentralBroker;
 import org.openbravo.model.common.enterprise.Organization;
 import org.openbravo.model.common.invoice.Invoice;
 import org.openbravo.model.common.plm.Product;
@@ -74,6 +77,7 @@
       String strWindowId = vars.getStringParameter("inpwindowId");
       String strIsSOTrx = Utility.getContext(this, vars, "isSOTrx", strWindowId);
       String strWharehouse = Utility.getContext(this, vars, "#M_Warehouse_ID", strWindowId);
+      String strUOMProduct = vars.getStringParameter("inpmProductUomId");
       String strWarehouseOrg = SLOrderProductData.getWarehouseOrg(this, strWharehouse);
       String strWarehouseForOrg = "";
       final OrganizationStructureProvider osp = OBContext.getOBContext()
@@ -93,7 +97,8 @@
 
       try {
         printPage(response, vars, strUOM, strPriceList, strPriceStd, strPriceLimit, strCurrency,
-            strMProductID, strADOrgID, strCInvoiceID, strIsSOTrx, strWharehouse, strTabId, strQty);
+            strMProductID, strADOrgID, strCInvoiceID, strIsSOTrx, strWharehouse, strTabId, strQty,
+            strUOMProduct);
       } catch (ServletException ex) {
         pageErrorCallOut(response);
       }
@@ -104,7 +109,8 @@
   private void printPage(HttpServletResponse response, VariablesSecureApp vars, String strUOM,
       String strPriceList, String strPriceStd, String strPriceLimit, String strCurrency,
       String strMProductID, String strADOrgID, String strCInvoiceID, String strIsSOTrx,
-      String strWharehouse, String strTabId, String strQty) throws IOException, ServletException {
+      String strWharehouse, String strTabId, String strQty, String strUOMProduct)
+      throws IOException, ServletException {
     if (log4j.isDebugEnabled())
       log4j.debug("Output: dataSheet");
     XmlDocument xmlDocument = xmlEngine.readXmlTemplate(
@@ -235,37 +241,60 @@
       resultado.append(", new Array(\"inpcPeriodId\", \"" + cPeriodId + "\")");
 
     }
-    resultado.append(", new Array(\"inpmProductUomId\", ");
-    // if (strUOM.startsWith("\""))
-    // strUOM=strUOM.substring(1,strUOM.length()-1);
-    // String strmProductUOMId =
-    // SLOrderProductData.strMProductUOMID(this,strMProductID,strUOM);
 
-    FieldProvider[] tld = null;
+    String propertyValue = "N";
     try {
-      ComboTableData comboTableData = new ComboTableData(vars, this, "TABLE", "", "M_Product_UOM",
-          "", Utility.getContext(this, vars, "#AccessibleOrgTree", "SLOrderProduct"),
-          Utility.getContext(this, vars, "#User_Client", "SLOrderProduct"), 0);
-      Utility.fillSQLParameters(this, vars, null, comboTableData, "SLOrderProduct", "");
-      tld = comboTableData.select(false);
-      comboTableData = null;
-    } catch (Exception ex) {
-      throw new ServletException(ex);
+      propertyValue = Preferences.getPreferenceValue("UomManagement", true, OBContext
+          .getOBContext().getCurrentClient(), OBContext.getOBContext().getCurrentOrganization(),
+          OBContext.getOBContext().getUser(), OBContext.getOBContext().getRole(), null);
+    } catch (PropertyException e) {
+      log4j.debug("Preference UomManagement not found", e);
+    }
+    if (propertyValue.equalsIgnoreCase("Y") && "".equals(strUOMProduct)) {
+      // Set AUM based on default
+      String finalAUM = CentralBroker.getInstance().getDefaultAUMForDocument(strMProductID,
+          invoice.getTransactionDocument().getId());
+      if (finalAUM != null) {
+        resultado.append(", new Array(\"inpcAum\", \"" + finalAUM + "\")");
+      }
+    }
+    if (strHasSecondaryUOM.equals("1")
+        && (!propertyValue.equalsIgnoreCase("Y") || (propertyValue.equalsIgnoreCase("Y") && !""
+            .equals(strUOMProduct)))) {
+      resultado.append(", new Array(\"inpmProductUomId\", ");
+      // if (strUOM.startsWith("\""))
+      // strUOM=strUOM.substring(1,strUOM.length()-1);
+      // String strmProductUOMId =
+      // SLOrderProductData.strMProductUOMID(this,strMProductID,strUOM);
+
+      FieldProvider[] tld = null;
+      try {
+        ComboTableData comboTableData = new ComboTableData(vars, this, "TABLE", "",
+            "M_Product_UOM", "", Utility.getContext(this, vars, "#AccessibleOrgTree",
+                "SLOrderProduct"),
+            Utility.getContext(this, vars, "#User_Client", "SLOrderProduct"), 0);
+        Utility.fillSQLParameters(this, vars, null, comboTableData, "SLOrderProduct", "");
+        tld = comboTableData.select(false);
+        comboTableData = null;
+      } catch (Exception ex) {
+        throw new ServletException(ex);
+      }
+
+      if (tld != null && tld.length > 0) {
+        resultado.append("new Array(");
+        for (int i = 0; i < tld.length; i++) {
+          resultado.append("new Array(\"" + tld[i].getField("id") + "\", \""
+              + FormatUtilities.replaceJS(tld[i].getField("name")) + "\", \"false\")");
+          if (i < tld.length - 1)
+            resultado.append(",\n");
+        }
+        resultado.append("\n)");
+      } else
+        resultado.append("null");
+      resultado.append("\n)");
     }
 
-    if (tld != null && tld.length > 0) {
-      resultado.append("new Array(");
-      for (int i = 0; i < tld.length; i++) {
-        resultado.append("new Array(\"" + tld[i].getField("id") + "\", \""
-            + FormatUtilities.replaceJS(tld[i].getField("name")) + "\", \"false\")");
-        if (i < tld.length - 1)
-          resultado.append(",\n");
-      }
-      resultado.append("\n)");
-    } else
-      resultado.append("null");
-    resultado.append("\n),");
-    resultado.append("new Array(\"EXECUTE\", \"displayLogic();\")\n");
+    resultado.append(", new Array(\"EXECUTE\", \"displayLogic();\")\n");
 
     resultado.append(");");
     xmlDocument.setParameter("array", resultado.toString());
--- a/src/org/openbravo/erpCommon/ad_callouts/SL_Order_Product.java	Fri Nov 11 10:01:28 2016 +0100
+++ b/src/org/openbravo/erpCommon/ad_callouts/SL_Order_Product.java	Fri Nov 11 10:06:34 2016 +0100
@@ -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-2013 Openbravo SLU 
+ * All portions are Copyright (C) 2001-2016 Openbravo SLU 
  * All Rights Reserved. 
  * Contributor(s):  ______________________________________.
  ************************************************************************
@@ -29,14 +29,18 @@
 
 import org.openbravo.base.secureApp.HttpSecureAppServlet;
 import org.openbravo.base.secureApp.VariablesSecureApp;
+import org.openbravo.dal.core.OBContext;
 import org.openbravo.dal.service.OBDal;
 import org.openbravo.data.FieldProvider;
 import org.openbravo.erpCommon.businessUtility.PAttributeSet;
 import org.openbravo.erpCommon.businessUtility.PAttributeSetData;
+import org.openbravo.erpCommon.businessUtility.Preferences;
 import org.openbravo.erpCommon.businessUtility.PriceAdjustment;
 import org.openbravo.erpCommon.businessUtility.Tax;
 import org.openbravo.erpCommon.utility.ComboTableData;
+import org.openbravo.erpCommon.utility.PropertyException;
 import org.openbravo.erpCommon.utility.Utility;
+import org.openbravo.materialmgmt.CentralBroker;
 import org.openbravo.model.common.order.Order;
 import org.openbravo.model.common.plm.Product;
 import org.openbravo.utils.FormatUtilities;
@@ -71,23 +75,25 @@
       String strWindowId = vars.getStringParameter("inpwindowId");
       String strIsSOTrx = Utility.getContext(this, vars, "isSOTrx", strWindowId);
       String cancelPriceAd = vars.getStringParameter("inpcancelpricead");
+      String strUOMProduct = vars.getStringParameter("inpmProductUomId");
 
       try {
         printPage(response, vars, strUOM, strPriceList, strPriceStd, strPriceLimit, strCurrency,
             strMProductID, strCBPartnerLocationID, strADOrgID, strMWarehouseID, strCOrderId,
-            strIsSOTrx, strQty, cancelPriceAd);
+            strIsSOTrx, strQty, cancelPriceAd, strUOMProduct);
       } catch (ServletException ex) {
         pageErrorCallOut(response);
       }
     } else
       pageError(response);
   }
-
+  
   private void printPage(HttpServletResponse response, VariablesSecureApp vars, String _strUOM,
       String strPriceList, String _strPriceStd, String _strPriceLimit, String strCurrency,
       String strMProductID, String strCBPartnerLocationID, String strADOrgID,
       String strMWarehouseID, String strCOrderId, String strIsSOTrx, String strQty,
-      String cancelPriceAd) throws IOException, ServletException {
+      String cancelPriceAd, String strUOMProduct) throws IOException, ServletException {
+    
     log4j.debug("Output: dataSheet");
     XmlDocument xmlDocument = xmlEngine.readXmlTemplate(
         "org/openbravo/erpCommon/ad_callouts/CallOut").createXmlDocument();
@@ -128,12 +134,12 @@
               new BigDecimal(strPriceStd.equals("") ? "0" : strPriceStd)).toString();
           strGrossPriceList = "0";
         }
-     } else {
+      } else {
         if (isTaxIncludedPriceList)
           strPriceActual = strGrossBaseUnitPrice;
         else
           strPriceActual = strPriceList;
-     }
+      }
     } else {
       strUOM = strNetPriceList = strGrossPriceList = strPriceLimit = strPriceStd = "";
     }
@@ -227,68 +233,94 @@
       resultado.append("new Array(\"inpcTaxId\", \"" + strCTaxID + "\"),\n");
     }
 
-    resultado.append("new Array(\"inpmProductUomId\", ");
-    // if (strUOM.startsWith("\""))
-    // strUOM=strUOM.substring(1,strUOM.length()-1);
-    // String strmProductUOMId =
-    // SLOrderProductData.strMProductUOMID(this,strMProductID,strUOM);
-    if (vars.getLanguage().equals("en_US")) {
-      FieldProvider[] tld = null;
-      try {
-        ComboTableData comboTableData = new ComboTableData(vars, this, "TABLE", "",
-            "M_Product_UOM", "", Utility.getContext(this, vars, "#AccessibleOrgTree",
-                "SLOrderProduct"),
-            Utility.getContext(this, vars, "#User_Client", "SLOrderProduct"), 0);
-        Utility.fillSQLParameters(this, vars, null, comboTableData, "SLOrderProduct", "");
-        tld = comboTableData.select(false);
-        comboTableData = null;
-      } catch (Exception ex) {
-        throw new ServletException(ex);
+    strHasSecondaryUOM = SLOrderProductData.hasSecondaryUOM(this, strMProductID);
+    String propertyValue = "N";
+    try {
+      propertyValue = Preferences.getPreferenceValue("UomManagement", true,
+          OBContext.getOBContext().getCurrentClient(),
+          OBContext.getOBContext().getCurrentOrganization(), OBContext.getOBContext().getUser(),
+          OBContext.getOBContext().getRole(), null);
+      
+    } catch (PropertyException e) {
+      log4j.debug("Preference UomManagement not found", e);
+    }
+    
+    if (propertyValue.equalsIgnoreCase("Y")  && "".equals(strUOMProduct)) {
+      // Set AUM based on default
+      Order order = OBDal.getInstance().get(Order.class, strCOrderId);
+      String finalAUM = CentralBroker.getInstance().getDefaultAUMForDocument(strMProductID,
+          order.getTransactionDocument().getId());
+      if (finalAUM != null) {
+        resultado.append("new Array(\"inpcAum\", \"" + finalAUM + "\"),\n");
       }
+    }
 
-      if (tld != null && tld.length > 0) {
-        resultado.append("new Array(");
-        for (int i = 0; i < tld.length; i++) {
-          resultado.append("new Array(\"" + tld[i].getField("id") + "\", \""
-              + FormatUtilities.replaceJS(tld[i].getField("name")) + "\", \"false\")");
-          if (i < tld.length - 1) {
-            resultado.append(",\n");
+    if (strHasSecondaryUOM.equals("1") && (!propertyValue.equalsIgnoreCase("Y")
+        || (propertyValue.equalsIgnoreCase("Y") && !"".equals(strUOMProduct)))) {
+      resultado.append("new Array(\"inpmProductUomId\", ");
+      // if (strUOM.startsWith("\""))
+      // strUOM=strUOM.substring(1,strUOM.length()-1);
+      // String strmProductUOMId =
+      // SLOrderProductData.strMProductUOMID(this,strMProductID,strUOM);
+      if (vars.getLanguage().equals("en_US")) {
+        FieldProvider[] tld = null;
+        try {
+          ComboTableData comboTableData = new ComboTableData(vars, this, "TABLE", "",
+              "M_Product_UOM", "",
+              Utility.getContext(this, vars, "#AccessibleOrgTree", "SLOrderProduct"),
+              Utility.getContext(this, vars, "#User_Client", "SLOrderProduct"), 0);
+          Utility.fillSQLParameters(this, vars, null, comboTableData, "SLOrderProduct", "");
+          tld = comboTableData.select(false);
+          comboTableData = null;
+        } catch (Exception ex) {
+          throw new ServletException(ex);
+        }
+
+        if (tld != null && tld.length > 0) {
+          resultado.append("new Array(");
+          for (int i = 0; i < tld.length; i++) {
+            resultado.append("new Array(\"" + tld[i].getField("id") + "\", \""
+                + FormatUtilities.replaceJS(tld[i].getField("name")) + "\", \"false\")");
+            if (i < tld.length - 1) {
+              resultado.append(",\n");
+            }
           }
+          resultado.append("\n)");
+        } else {
+          resultado.append("null");
         }
-        resultado.append("\n)");
+        resultado.append("\n),");
       } else {
-        resultado.append("null");
+        FieldProvider[] tld = null;
+        try {
+          ComboTableData comboTableData = new ComboTableData(vars, this, "TABLE", "",
+              "M_Product_UOM", "",
+              Utility.getContext(this, vars, "#AccessibleOrgTree", "SLOrderProduct"),
+              Utility.getContext(this, vars, "#User_Client", "SLOrderProduct"), 0);
+          Utility.fillSQLParameters(this, vars, null, comboTableData, "SLOrderProduct", "");
+          tld = comboTableData.select(false);
+          comboTableData = null;
+        } catch (Exception ex) {
+          throw new ServletException(ex);
+        }
+
+        if (tld != null && tld.length > 0) {
+          resultado.append("new Array(");
+          for (int i = 0; i < tld.length; i++) {
+            resultado.append("new Array(\"" + tld[i].getField("id") + "\", \""
+                + FormatUtilities.replaceJS(tld[i].getField("name")) + "\", \"false\")");
+            if (i < tld.length - 1) {
+              resultado.append(",\n");
+            }
+          }
+          resultado.append("\n)");
+        } else {
+          resultado.append("null");
+        }
+        resultado.append("\n),");
       }
-      resultado.append("\n),");
-    } else {
-      FieldProvider[] tld = null;
-      try {
-        ComboTableData comboTableData = new ComboTableData(vars, this, "TABLE", "",
-            "M_Product_UOM", "", Utility.getContext(this, vars, "#AccessibleOrgTree",
-                "SLOrderProduct"),
-            Utility.getContext(this, vars, "#User_Client", "SLOrderProduct"), 0);
-        Utility.fillSQLParameters(this, vars, null, comboTableData, "SLOrderProduct", "");
-        tld = comboTableData.select(false);
-        comboTableData = null;
-      } catch (Exception ex) {
-        throw new ServletException(ex);
-      }
+    }
 
-      if (tld != null && tld.length > 0) {
-        resultado.append("new Array(");
-        for (int i = 0; i < tld.length; i++) {
-          resultado.append("new Array(\"" + tld[i].getField("id") + "\", \""
-              + FormatUtilities.replaceJS(tld[i].getField("name")) + "\", \"false\")");
-          if (i < tld.length - 1) {
-            resultado.append(",\n");
-          }
-        }
-        resultado.append("\n)");
-      } else {
-        resultado.append("null");
-      }
-      resultado.append("\n),");
-    }
     resultado.append("new Array(\"EXECUTE\", \"displayLogic();\"),\n");
     // Para posicionar el cursor en el campo de cantidad
     resultado.append("new Array(\"CURSOR_FIELD\", \"inpqtyordered\")\n");
--- a/src/org/openbravo/erpCommon/ad_callouts/SL_RequisitionLine_Product.java	Fri Nov 11 10:01:28 2016 +0100
+++ b/src/org/openbravo/erpCommon/ad_callouts/SL_RequisitionLine_Product.java	Fri Nov 11 10:06:34 2016 +0100
@@ -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) 2008-2012 Openbravo SLU 
+ * All portions are Copyright (C) 2008-2016 Openbravo SLU 
  * All Rights Reserved. 
  * Contributor(s):  ______________________________________.
  ************************************************************************
@@ -21,20 +21,27 @@
 import java.io.IOException;
 import java.io.PrintWriter;
 import java.math.BigDecimal;
+import java.util.List;
 
 import javax.servlet.ServletConfig;
 import javax.servlet.ServletException;
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
 
+import org.hibernate.criterion.Restrictions;
 import org.openbravo.base.secureApp.HttpSecureAppServlet;
 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.data.FieldProvider;
+import org.openbravo.erpCommon.businessUtility.Preferences;
 import org.openbravo.erpCommon.utility.ComboTableData;
 import org.openbravo.erpCommon.utility.DateTimeData;
+import org.openbravo.erpCommon.utility.PropertyException;
 import org.openbravo.erpCommon.utility.Utility;
+import org.openbravo.materialmgmt.CentralBroker;
+import org.openbravo.model.common.enterprise.DocumentType;
 import org.openbravo.model.common.plm.AttributeSet;
 import org.openbravo.model.common.plm.Product;
 import org.openbravo.model.pricing.pricelist.PriceList;
@@ -64,10 +71,11 @@
       String strPriceListId = vars.getStringParameter("inpmPricelistId");
       String strAttributeSetInstance = vars.getStringParameter("inpmProductId_ATR");
       String strUOM = vars.getStringParameter("inpmProductId_UOM");
+      String strUOMProduct = vars.getStringParameter("inpmProductUomId");
 
       try {
         printPage(response, vars, strMProductID, strWindowId, strTabId, strAttributeSetInstance,
-            strUOM, strRequisition, strPriceListId, strChanged);
+            strUOM, strRequisition, strPriceListId, strChanged, strUOMProduct);
       } catch (ServletException ex) {
         pageErrorCallOut(response);
       }
@@ -77,8 +85,8 @@
 
   private void printPage(HttpServletResponse response, VariablesSecureApp vars,
       String strMProductID, String strWindowId, String strTabId, String strAttribute,
-      String strUOM, String strRequisition, String strPriceListId, String strChanged)
-      throws IOException, ServletException {
+      String strUOM, String strRequisition, String strPriceListId, String strChanged,
+      String strUOMProduct) throws IOException, ServletException {
     String localStrPriceListId = strPriceListId;
     String localStrAttribute = strAttribute;
     if (log4j.isDebugEnabled())
@@ -162,6 +170,32 @@
       }
     }
 
+    String strHasSecondaryUOM = SLRequisitionLineProductData.hasSecondaryUOM(this, strMProductID);
+    String propertyValue = "N";
+    try {
+      propertyValue = Preferences.getPreferenceValue("UomManagement", true, OBContext
+          .getOBContext().getCurrentClient(), OBContext.getOBContext().getCurrentOrganization(),
+          OBContext.getOBContext().getUser(), OBContext.getOBContext().getRole(), null);
+    } catch (PropertyException e) {
+      log4j.debug("Preference UomManagement not found", e);
+    }
+    if (propertyValue.equalsIgnoreCase("Y") && "".equals(strUOMProduct)) {
+      // Set AUM based on default
+      // As Requisition is a purchase document, the document type 'Purchase Order' is used to get
+      // the
+      // default AUM
+      OBCriteria<DocumentType> dtCriteria = OBDal.getInstance().createCriteria(DocumentType.class);
+      dtCriteria.add(Restrictions.eq("documentCategory", "POO"));
+      List<DocumentType> dtList = dtCriteria.list();
+      if (dtList.size() > 0) {
+        String finalAUM = CentralBroker.getInstance().getDefaultAUMForDocument(strMProductID,
+            dtList.get(0).getId());
+        if (finalAUM != null) {
+          strResult.append("new Array(\"inpcAum\", \"" + finalAUM + "\"),\n");
+        }
+      }
+    }
+
     if (strChanged.equals("inpmProductId")) {
       strResult.append("new Array(\"inpcUomId\", "
           + (strUOM.equals("") ? "\"\"" : "\"" + strUOM + "\"") + "),\n");
@@ -192,34 +226,38 @@
       strResult.append("new Array(\"inpattrsetvaluetype\", \""
           + (strAttrSetValueType == null || strAttrSetValueType.equals("") ? "" : FormatUtilities
               .replaceJS(strAttrSetValueType)) + "\"),\n");
-      String strHasSecondaryUOM = SLRequisitionLineProductData.hasSecondaryUOM(this, strMProductID);
       strResult.append("new Array(\"inphasseconduom\", " + strHasSecondaryUOM + "),\n");
-      strResult.append("new Array(\"inpmProductUomId\", ");
-      FieldProvider[] tld = null;
-      try {
-        ComboTableData comboTableData = new ComboTableData(vars, this, "TABLEDIR",
-            "M_Product_UOM_ID", "", "M_Product_UOM_ID", Utility.getContext(this, vars,
-                "#AccessibleOrgTree", "SLRequisitionLineProduct"), Utility.getContext(this, vars,
-                "#User_Client", "SLRequisitionLineProduct"), 0);
-        Utility.fillSQLParameters(this, vars, null, comboTableData, strTabId, "");
-        tld = comboTableData.select(false);
-        comboTableData = null;
-      } catch (Exception ex) {
-        throw new ServletException(ex);
+      if (strHasSecondaryUOM.equals("1")
+          && (!propertyValue.equalsIgnoreCase("Y") || (propertyValue.equalsIgnoreCase("Y") && !""
+              .equals(strUOMProduct)))) {
+        strResult.append("new Array(\"inpmProductUomId\", ");
+        FieldProvider[] tld = null;
+        try {
+          ComboTableData comboTableData = new ComboTableData(vars, this, "TABLEDIR",
+              "M_Product_UOM_ID", "", "M_Product_UOM_ID", Utility.getContext(this, vars,
+                  "#AccessibleOrgTree", "SLRequisitionLineProduct"), Utility.getContext(this, vars,
+                  "#User_Client", "SLRequisitionLineProduct"), 0);
+          Utility.fillSQLParameters(this, vars, null, comboTableData, strTabId, "");
+          tld = comboTableData.select(false);
+          comboTableData = null;
+        } catch (Exception ex) {
+          throw new ServletException(ex);
+        }
+
+        if (tld != null && tld.length > 0) {
+          strResult.append("new Array(");
+          for (int i = 0; i < tld.length; i++) {
+            strResult.append("\n\tnew Array(\"" + tld[i].getField("id") + "\", \""
+                + FormatUtilities.replaceJS(tld[i].getField("name")) + "\", \"false\")");
+            if (i < tld.length - 1)
+              strResult.append(",");
+          }
+          strResult.append(")");
+        } else
+          strResult.append("null");
+        strResult.append("),\n");
       }
 
-      if (tld != null && tld.length > 0) {
-        strResult.append("new Array(");
-        for (int i = 0; i < tld.length; i++) {
-          strResult.append("\n\tnew Array(\"" + tld[i].getField("id") + "\", \""
-              + FormatUtilities.replaceJS(tld[i].getField("name")) + "\", \"false\")");
-          if (i < tld.length - 1)
-            strResult.append(",");
-        }
-        strResult.append(")");
-      } else
-        strResult.append("null");
-      strResult.append("),\n");
       // To set the cursor focus in the amount field
       if (!strMProductID.equals("")) {
         strResult.append("new Array(\"CURSOR_FIELD\", \"inpqty\"),\n");
--- a/src/org/openbravo/erpCommon/ad_forms/MaterialReceiptPending.html	Fri Nov 11 10:01:28 2016 +0100
+++ b/src/org/openbravo/erpCommon/ad_forms/MaterialReceiptPending.html	Fri Nov 11 10:06:34 2016 +0100
@@ -84,11 +84,22 @@
               showJSMessage(1);
               return false;
             }
-            if (document.getElementsByName("inpQtyordered"+frm.inpOrder[i].value)[0].value==null ||
-                document.getElementsByName("inpQtyordered"+frm.inpOrder[i].value)[0].value=="") {
-              setWindowElementFocus(document.getElementsByName("inpQtyordered"+frm.inpOrder[i].value)[0]);
-              showJSMessage(1);
-              return false;
+            if (frm.elements["inpIsUomEnabled"].value == 'N') {
+              if (document.getElementsByName("inpQtyordered"+frm.inpOrder[i].value)[0].value==null ||
+                  document.getElementsByName("inpQtyordered"+frm.inpOrder[i].value)[0].value=="" ||
+                  !isValidNumber(document.getElementsByName("inpQtyordered"+frm.inpOrder[i].value)[0])) {
+                setWindowElementFocus(document.getElementsByName("inpQtyordered"+frm.inpOrder[i].value)[0]);
+                showJSMessage(1);
+                return false;
+              }
+            }else {
+              if (document.getElementsByName("inpAumQty"+frm.inpOrder[i].value)[0].value==null ||
+                  document.getElementsByName("inpAumQty"+frm.inpOrder[i].value)[0].value=="" ||
+                  !isValidNumber(document.getElementsByName("inpAumQty"+frm.inpOrder[i].value)[0])) {
+                setWindowElementFocus(document.getElementsByName("inpAumQty"+frm.inpOrder[i].value)[0]);
+                showJSMessage(1);
+                return false;
+              }
             }
           }
         }
@@ -116,15 +127,27 @@
 function updateData(key, mark) {
 	if (mark==null) mark=false;
 	var frm = document.frmMain;
-	frm.elements["inpQtyordered" + key].disabled=!mark;
+	if(frm.elements["inpIsUomEnabled"].value == 'N'){
+	  frm.elements["inpQtyordered" + key].disabled=!mark;
+	}else{
+	  frm.elements["inpAumQty" + key].disabled=!mark;
+	}
 	frm.elements["inpmLocatorId_D" + key].disabled=!mark;
 
   if (mark)
   {
-    frm.elements["inpQtyordered" + key].className = frm.elements["inpQtyordered" + key].className.replace(' readonly', '');
+	if(frm.elements["inpIsUomEnabled"].value == 'N'){
+      frm.elements["inpQtyordered" + key].className = frm.elements["inpQtyordered" + key].className.replace(' readonly', '');
+	}else{
+	  frm.elements["inpAumQty" + key].className = frm.elements["inpAumQty" + key].className.replace(' readonly', '');
+	}
     frm.elements["inpmLocatorId_D" + key].className = frm.elements["inpmLocatorId_D" + key].className.replace(' readonly', '');
   } else {
-    frm.elements["inpQtyordered" + key].className += " readonly";
+	if(frm.elements["inpIsUomEnabled"].value == 'N'){
+      frm.elements["inpQtyordered" + key].className += " readonly";
+	}else{
+	  frm.elements["inpAumQty" + key].className += " readonly";
+	}
     frm.elements["inpmLocatorId_D" + key].className += " readonly";
   }
 	return true;
@@ -177,6 +200,32 @@
         }
     }
 	</script>
+    <script language="JavaScript" type="text/javascript">
+      function updateQty(selKey) {
+        var frm = document.frmMain;
+        if(frm.elements["inpcUOMId" + selKey].value != frm.elements["inpcAUMId" + selKey].value){
+          callback = function (response, data, request) {
+    	    frm.elements["inpQtyordered" + selKey].value = data.qty;
+   	      };
+   	
+          window.parent.parent.OB.RemoteCallManager.call('org.openbravo.common.actionhandler.GetConvertedQtyActionHandler', {
+            mProductId: frm.elements["inpProductId" + selKey].value,
+            qty: frm.elements["inpAumQty" + selKey].value,
+            toUOM: frm.elements["inpcAUMId" + selKey].value
+          }, {}, callback);
+        }else {
+    	  frm.elements["inpQtyordered" + selKey].value = frm.elements["inpAumQty" + selKey].value;
+        }
+      }
+      
+      function isValidNumber(input) {
+        var isValid = validateNumber(input.value, true, true);
+        if (!isValid) {
+          return false;
+        }
+        return true;
+      } 
+    </script>
 </head>
 <body onload="onLoadDo();" onresize="onResizeDo();" leftmargin="0" topmargin="0" marginwidth="0" marginheight="0" id="paramMessage">
 <form method="post" action="MaterialReceiptPending.html" name="frmMain" >
@@ -184,6 +233,7 @@
 <input type="hidden" name="inpcOrderId"></input>
 <input type="hidden" name="inpParamValue" value="" id="paramValue"></input> 
 <input type="hidden" name="inpissotrx" value="Y"></input>
+<input type="hidden" name="inpIsUomEnabled" value="xx" id="paramIsUomEnabled"></input>
 <table height="100%" border="0" cellpadding="0" cellspacing="0" id="main">
     <tr>
       <td valign="top" id="tdleftTabs"></td>
@@ -434,10 +484,10 @@
         <br></br>
         <table cellspacing="0" cellpadding="0" width="100%" class="DataGrid_Header_Table DataGrid_Body_Table" style="table-layout: auto;">
           <tr class="DataGrid_Body_Row"> 
-            <th width="20" class="DataGrid_Header_Cell" colspan="3" class="DataGrid_Header_Cell" id="fieldPartnerName"></th>
+            <th width="20" class="DataGrid_Header_Cell" class="DataGrid_Header_Cell" id="paramBPartner" colspan="xx"><span id="fieldPartnerName"></span></th>
             <th class="DataGrid_Header_Cell"><span>Lines</span>&nbsp;<span id="fieldCount"></span></th>
             <th class="DataGrid_Header_Cell"> <span>Reception date</span></th>
-            <th class="DataGrid_Header_Cell">
+            <th class="DataGrid_Header_Cell" id="paramCalendar" colspan="xx">
                     <table border="0" cellspacing="0" cellpadding="0" summary="" style="padding-top: 0px;">
                       <tr>
 					      <td class="TextBox_ContentCell">
@@ -507,11 +557,19 @@
 		  <div id="sectionDocumentno"> 
 
               <tr class="DataGrid_Body_Row"> 
-                <th class="DataGrid_Header_Cell" colspan="4"> <a href="#" onclick="openGoodsReceipt('xx');return false;" onmouseover="window.status='Purchase order';return true;" onmouseout="window.status='';return true;" class="LabelLink" id="idfieldCOrderId"> 
+                <th id="paramDocument" class="DataGrid_Header_Cell" colspan="xx"> <a href="#" onclick="openGoodsReceipt('xx');return false;" onmouseover="window.status='Purchase order';return true;" onmouseout="window.status='';return true;" class="LabelLink" id="idfieldCOrderId"> 
                   <span>Document No.</span>&nbsp;<span id="fieldDocumentno"></span></a></th>
-                <th class="DataGrid_Header_Cell" colspan="2"><span>Date</span>&nbsp;<span id="fieldDateordered"></span></th>
+                <th id="paramDate" class="DataGrid_Header_Cell" colspan="xx"><span>Date</span>&nbsp;<span id="fieldDateordered"></span></th>
               </tr>
-
+              <tr class="DataGrid_Body_Row">
+                <th class="DataGrid_Header_Cell" colspan="2">Product</th>
+                <th class="DataGrid_Header_Cell">Description</th>
+                <th class="DataGrid_Header_Cell">Quantity</th>
+                <th class="DataGrid_Header_Cell">Movement Quantity</th>
+                <th class="DataGrid_Header_Cell" id="paramAumVisible" style="display:xx;">Quantity in Alternative UOM</th>
+                <th class="DataGrid_Header_Cell" id="paramAumVisible" style="display:xx;">Alternative UOM</th>
+                <th class="DataGrid_Header_Cell">Warehouse</th>
+              </tr>
               <div id="sectionDetail"> 
 
                 <tr id="funcEvenOddRow" class="DataGrid_Body_Row DataGrid_Body_Row_xx"> 
@@ -520,8 +578,14 @@
                   <td width="409" class="DataGrid_Body_Cell" id="fieldProductName">xx</td>
                   <td width="198" class="DataGrid_Body_Cell" id="fieldDescription">xx</td>
                   <td width="146" class="DataGrid_Body_Cell" id="fieldTotalQty">xx</td>
-                  <td width="131" class="DataGrid_Body_Cell"> <input name="inpQtyorderedxx" type="text" id="fieldQtyordered" size="5" style="width:80px" value="0" outputformat="qtyEdition" class="dojoValidateValid readonly required" required="true" disabled onfocus="numberInputEvent('onfocus', this);" onblur="numberInputEvent('onblur', this);" onkeydown="numberInputEvent('onkeydown', this, event);" onchange="numberInputEvent('onchange', this);" ></input>
+                  <td width="131" class="DataGrid_Body_Cell"> <input name="inpQtyorderedxx" type="text" id="fieldQtyordered" size="5" style="width:80px" value="0" outputformat="qtyEdition" class="dojoValidateValid readonly required" required="true" disabled onfocus="numberInputEvent('onfocus', this);" onblur="numberInputEvent('onblur', this);" onkeydown="numberInputEvent('onkeydown', this, event);" onchange="numberInputEvent('onchange', this);" ></input></td>
+                  <td width="131" class="DataGrid_Body_Cell" id="paramAumVisible" style="display:xx;">
+                    <input name="inpAumQtyxx" type="text" id="fieldAumQty" size="5" style="width:80px" value="0" outputformat="qtyEdition" class="dojoValidateValid readonly required" required="true" disabled onfocus="numberInputEvent('onfocus', this);" onblur="numberInputEvent('onblur', this);" onkeydown="numberInputEvent('onkeydown', this, event);" onchange="numberInputEvent('onchange', this);" onkeyup="updateQty('yy');"></input>
+                    <input name="inpProductIdxx" type="hidden" id="fieldProductId" value="0"></input>
+                    <input name="inpHiddenQtyOrderedxx" type="hidden" id="fieldHiddenQtyordered" value="0"></input>
+                    <input name="inpcUOMIdxx" type="hidden" id="fieldUomId" value="0"></input>
                   </td>
+                  <td width="131" class="DataGrid_Body_Cell" id="paramAumVisible" style="display:xx;"><select class="DataGrid_Body_Cell" name="inpcAUMIdxx" id="fieldAumCombo" disabled="true" onchange="updateQty('yy');return true;"><div id="reportAUM_ID"></div></select></td>
                   <td class="DataGrid_Body_Cell">
                     <table border="0" cellspacing="0" cellpadding="0" summary=""  style="padding-top: 0px;">
                       <tr>
--- a/src/org/openbravo/erpCommon/ad_forms/MaterialReceiptPending.java	Fri Nov 11 10:01:28 2016 +0100
+++ b/src/org/openbravo/erpCommon/ad_forms/MaterialReceiptPending.java	Fri Nov 11 10:06:34 2016 +0100
@@ -54,6 +54,7 @@
 import org.openbravo.erpCommon.utility.SequenceIdData;
 import org.openbravo.erpCommon.utility.ToolBar;
 import org.openbravo.erpCommon.utility.Utility;
+import org.openbravo.materialmgmt.CentralBroker;
 import org.openbravo.model.common.enterprise.Locator;
 import org.openbravo.model.common.enterprise.OrgWarehouse;
 import org.openbravo.model.common.enterprise.Organization;
@@ -150,6 +151,31 @@
           DateTimeData.nDaysAfter(this, strDateTo, "1"), strC_BPartner_ID, strDocumentNo);
     }
 
+    String preference = CentralBroker.getInstance().isUomManagementEnabled();
+    xmlDocument.setParameter("paramIsUomEnabled", preference);
+    if (preference.equals("Y")) {
+      xmlDocument.setParameter("aumVisible", "table-cell");
+      xmlDocument.setParameter("paramColSpanDocument", "5");
+      xmlDocument.setParameter("paramColSpanDate", "3");
+      xmlDocument.setParameter("paramColSpanBPartner", "4");
+      xmlDocument.setParameter("paramColSpanCalendar", "2");
+    } else {
+      xmlDocument.setParameter("aumVisible", "none");
+      xmlDocument.setParameter("paramColSpanDocument", "4");
+      xmlDocument.setParameter("paramColSpanDate", "2");
+      xmlDocument.setParameter("paramColSpanBPartner", "3");
+      xmlDocument.setParameter("paramColSpanCalendar", "1");
+    }
+    
+    MaterialReceiptPendingData[][] dataAum = new MaterialReceiptPendingData[data.length][];
+    for (int i = 0; i < data.length; i++) {
+      dataAum[i] = MaterialReceiptPendingData.selectAUM(this, data[i].mProductId);
+      if (dataAum[i].length == 0) {
+        dataAum[i] = MaterialReceiptPendingData.selectAUMDefault(this, data[i].mProductId,
+            data[i].cDoctypeId);
+      }
+    }
+    
     ToolBar toolbar = new ToolBar(this, vars.getLanguage(), "MaterialReceiptPending", false, "",
         "", "", false, "ad_forms", strReplaceWith, false, true);
     toolbar.prepareSimpleToolBarTemplate();
@@ -250,13 +276,14 @@
     }
 
     xmlDocument.setData("structure1", data);
+    xmlDocument.setDataArray("reportAUM_ID", "liststructure", dataAum);
     out.println(xmlDocument.print());
     out.close();
   }
 
-  private OBError processPurchaseOrder(VariablesSecureApp vars, String strcOrderLineId)
+  private OBError processPurchaseOrder(VariablesSecureApp vars, String strcOrderLineIdParam)
       throws IOException, ServletException {
-    String localStrcOrderLineId = strcOrderLineId;
+    String localStrcOrderLineId = strcOrderLineIdParam;
     String strMessageResult = "";
     String strMessageType = "Success";
     String strWindowName = WindowTabsData.selectWindowInfo(this, vars.getLanguage(), "184");
@@ -426,6 +453,17 @@
               }
             }
           }
+          String propertyValue = CentralBroker.getInstance().isUomManagementEnabled();
+          if (propertyValue.equalsIgnoreCase("Y") && dataLine[0].mProductUomId.isEmpty()) {
+            dataLine[0].aumqty = vars.getStringParameter("inpAumQty" + strOrderlineId);
+            strQtyordered = dataLine[0].aumqty;
+            String defaultAum = vars.getStringParameter("inpcAUMId" + strOrderlineId);
+            dataLine[0].cAum = defaultAum;
+            if (!defaultAum.equals(dataLine[0].cUomId)) {
+              strQtyordered = CentralBroker.getInstance().getConvertedQty(dataLine[0].mProductId,
+                  new BigDecimal(dataLine[0].aumqty), defaultAum).toString();
+            }
+          }
           try {
             MaterialReceiptPendingLinesData.insert(conn, this, strSequenceLine, vars.getClient(),
                 dataLine[0].adOrgId, "Y", vars.getUser(), vars.getUser(), String.valueOf(line),
@@ -434,7 +472,7 @@
                 new BigDecimal(strQtyordered).toString(), "N", dataLine[0].mAttributesetinstanceId,
                 "N", qtyorder, dataLine[0].mProductUomId, dataLine[0].cProjectId,
                 dataLine[0].user1Id, dataLine[0].user2Id, dataLine[0].cCostcenterId,
-                dataLine[0].aAssetId);
+                dataLine[0].aAssetId, dataLine[0].cAum, dataLine[0].aumqty);
             MaterialReceiptPendingLinesData.updateInvoiceOrder(conn, this, strSequenceLine,
                 strOrderlineId);
           } catch (ServletException ex) {
--- a/src/org/openbravo/erpCommon/ad_forms/MaterialReceiptPending.xml	Fri Nov 11 10:01:28 2016 +0100
+++ b/src/org/openbravo/erpCommon/ad_forms/MaterialReceiptPending.xml	Fri Nov 11 10:06:34 2016 +0100
@@ -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-2015 Openbravo SLU 
+ * All portions are Copyright (C) 2001-2016 Openbravo SLU 
  * All Rights Reserved. 
  * Contributor(s):  ______________________________________.
  ************************************************************************
@@ -48,6 +48,7 @@
   </SUBREPORT>
   <PARAMETER id="param2" name="param2" default="2"/>
   <PARAMETER id="paramScript" name="script"/>
+  
   <structure name="structure1">
     <FIELD id="fieldRownum">rownum</FIELD>
     <FUNCTION id="funcEvenOddRow" name="MODULE" arg1="fieldRownum" arg2="param2" format="integerEdition" attribute="class" replace="xx"/>
@@ -84,6 +85,33 @@
     <FIELD id="fieldLocatorId" attribute="onclick" replace="zz">id</FIELD>
     <FIELD id="fieldLocatorId" attribute="onclick" replace="ss">id</FIELD>
     <FIELD id="fieldLocatorId" attribute="onclick" replace="xx">id</FIELD>
+    <FIELD id="fieldAumQty" attribute="style" replace="xx">aumvisible</FIELD>
+    <FIELD id="fieldAum" attribute="style" replace="xx">aumvisible</FIELD>
+    <FIELD id="fieldAumValue" attribute="value">cAum</FIELD>
+    <FIELD id="fieldAumCombo" attribute="name" replace="xx">id</FIELD>
+    <FIELD id="fieldAumCombo" attribute="onchange" replace="yy">id</FIELD>
+    
+    <PARAMETER id="paramAumVisible" name="aumVisible" attribute="style" replace="xx"/>
+    <PARAMETER id="paramDocument" name="paramColSpanDocument" attribute="colspan" replace="xx"/>
+    <PARAMETER id="paramDate" name="paramColSpanDate" attribute="colspan" replace="xx"/>
+    <PARAMETER id="paramBPartner" name="paramColSpanBPartner" attribute="colspan" replace="xx"/>
+    <PARAMETER id="paramCalendar" name="paramColSpanCalendar" attribute="colspan" replace="xx"/>
+    <PARAMETER id="paramIsUomEnabled" name="paramIsUomEnabled" attribute="value" replace="xx"/>
+    
+    <FIELD id="fieldAumQty" attribute="value" format="euroEdition">aumqty</FIELD>
+    <FIELD id="fieldAumQty" attribute="name" replace="xx">id</FIELD>
+    <FIELD id="fieldAumQty" attribute="onkeyup" replace="yy">id</FIELD>
+    <FIELD id="fieldProductId" attribute="value">mProductId</FIELD>
+    <FIELD id="fieldProductId" attribute="name" replace="xx">id</FIELD>
+    <FIELD id="fieldUomId" attribute="value">cUomId</FIELD>
+    <FIELD id="fieldUomId" attribute="name" replace="xx">id</FIELD>
+    <FIELD id="fieldHiddenQtyordered" attribute="value" format="euroEdition">qtyordered</FIELD>
+    <FIELD id="fieldHiddenQtyordered" attribute="name" replace="xx">id</FIELD>
+    
+    <SUBREPORT id="reportAUM_ID" name="reportAUM_ID" report="org/openbravo/erpCommon/reference/List">
+      <ARGUMENT name="parameterListSelected"  withId="fieldAumValue"/>
+    </SUBREPORT>
+    
     <FUNCTION id="fieldCount" name="COUNT">documentno</FUNCTION>
     <SECTION id="sectionPartner" field="partnerName"/>
     <SECTION id="sectionDocumentno" field="documentno"/>
--- a/src/org/openbravo/erpCommon/ad_forms/MaterialReceiptPendingLines_data.xsql	Fri Nov 11 10:01:28 2016 +0100
+++ b/src/org/openbravo/erpCommon/ad_forms/MaterialReceiptPendingLines_data.xsql	Fri Nov 11 10:06:34 2016 +0100
@@ -42,7 +42,8 @@
              COALESCE(OL.USER1_ID, O.USER1_ID) AS USER1_ID,
              COALESCE(OL.USER2_ID, O.USER2_ID) AS USER2_ID,
              COALESCE(OL.C_COSTCENTER_ID, O.C_COSTCENTER_ID) AS C_COSTCENTER_ID,
-             COALESCE(OL.A_ASSET_ID, O.A_ASSET_ID) AS A_ASSET_ID
+             COALESCE(OL.A_ASSET_ID, O.A_ASSET_ID) AS A_ASSET_ID,
+             OL.C_AUM, OL.AUMQTY, O.C_DOCTYPE_ID
       FROM C_ORDERLINE OL, C_ORDER O
       WHERE OL.C_ORDER_ID = O.C_ORDER_ID 
             AND OL.C_ORDERLINE_ID = ?
@@ -59,13 +60,13 @@
          CREATED, CREATEDBY, UPDATED, UPDATEDBY, 
          LINE, DESCRIPTION, M_INOUT_ID, C_ORDERLINE_ID, M_LOCATOR_ID, M_PRODUCT_ID, C_UOM_ID, 
          MOVEMENTQTY, ISINVOICED, M_ATTRIBUTESETINSTANCE_ID, ISDESCRIPTION, QUANTITYORDER, M_PRODUCT_UOM_ID,
-         C_PROJECT_ID, USER1_ID, USER2_ID, C_COSTCENTER_ID, A_ASSET_ID)
+         C_PROJECT_ID, USER1_ID, USER2_ID, C_COSTCENTER_ID, A_ASSET_ID, C_AUM, AUMQTY)
       VALUES
         (?,?,?,?,
          now(),?,now(),?,
          TO_NUMBER(?),?,?,?,?,?,?,
          TO_NUMBER(?),?,?,?,TO_NUMBER(?),?,
-         ?,?,?,?,?)
+         ?,?,?,?,?,?,TO_NUMBER(?))
       ]]></Sql>
       <Parameter name="mInoutlineId"/>
       <Parameter name="adClientId"/>
@@ -91,6 +92,8 @@
       <Parameter name="user2Id"/>
       <Parameter name="cCostcenterId"/>
       <Parameter name="aAssetId"/>
+      <Parameter name="cAum"/>
+      <Parameter name="aumQty"/>
   </SqlMethod>
   <SqlMethod name="updateInvoiceOrder" type="preparedStatement" connection="true" return="rowCount">
     <SqlMethodComment></SqlMethodComment>
--- a/src/org/openbravo/erpCommon/ad_forms/MaterialReceiptPending_data.xsql	Fri Nov 11 10:01:28 2016 +0100
+++ b/src/org/openbravo/erpCommon/ad_forms/MaterialReceiptPending_data.xsql	Fri Nov 11 10:06:34 2016 +0100
@@ -41,7 +41,8 @@
              C_ORDER.DROPSHIP_LOCATION_ID, C_ORDER.DROPSHIP_USER_ID, C_ORDER.ISSELFSERVICE, C_ORDER.AD_ORGTRX_ID,
              C_ORDER.USER1_ID, C_ORDER.USER2_ID, C_ORDER.DELIVERYNOTES, C_ORDER.C_INCOTERMS_ID, C_ORDER.INCOTERMSDESCRIPTION,
              C_ORDER.GENERATETEMPLATE, C_ORDER.C_COSTCENTER_ID, C_ORDER.A_ASSET_ID,
-             '' AS ID, '' AS PARTNER_NAME, '' AS PRODUCT_NAME, '' AS TOTAL_QTY, '' AS QTYORDERED, '' AS DATE_FORMAT
+             '' AS ID, '' AS PARTNER_NAME, '' AS PRODUCT_NAME, '' AS TOTAL_QTY, '' AS QTYORDERED, '' AS DATE_FORMAT,
+             C_AUM, AUMQTY, '' AS NAME, C_ORDERLINE.M_PRODUCT_ID, C_ORDERLINE.C_UOM_ID
       FROM C_ORDER, C_ORDERLINE
       WHERE C_ORDER.C_ORDER_ID = C_ORDERLINE.C_ORDER_ID
       AND C_ORDER.DOCSTATUS = 'CO'
@@ -58,12 +59,15 @@
     <SqlMethodComment></SqlMethodComment>
     <Sql>
     <![CDATA[
-      SELECT ID, C_ORDER_ID, DOCUMENTNO, DATEORDERED, C_BPARTNER_ID, PARTNER_NAME, PRODUCT_NAME, DESCRIPTION, TOTAL_QTY, QTYORDERED, ISACTIVE, ? AS DATE_FORMAT, AD_ORG_ID
+      SELECT ID, C_ORDER_ID, DOCUMENTNO, DATEORDERED, C_BPARTNER_ID, PARTNER_NAME, PRODUCT_NAME, DESCRIPTION, TOTAL_QTY, QTYORDERED, ISACTIVE, ? AS DATE_FORMAT, AD_ORG_ID, AUMQTY, C_AUM, C_DOCTYPE_ID, M_PRODUCT_ID, C_UOM_ID
       FROM(  
       SELECT C_ORDERLINE.C_ORDERLINE_ID AS ID, C_ORDER.C_ORDER_ID AS C_ORDER_ID, C_ORDER.DOCUMENTNO AS DOCUMENTNO, C_ORDER.DATEORDERED AS DATEORDERED, 
       C_BPARTNER.C_BPARTNER_ID AS C_BPARTNER_ID, C_BPARTNER.NAME AS PARTNER_NAME, 
       AD_COLUMN_IDENTIFIER(TO_CHAR('M_Product'), TO_CHAR(C_ORDERLINE.M_PRODUCT_ID), TO_CHAR(?)) AS PRODUCT_NAME, M_ATTRIBUTESETINSTANCE.DESCRIPTION AS DESCRIPTION, C_ORDERLINE.QTYORDERED AS TOTAL_QTY,
-      C_ORDERLINE.QTYORDERED-SUM(COALESCE(M_MATCHPO.QTY,0)) AS QTYORDERED, '-1' AS ISACTIVE, C_ORDERLINE.LINE, C_ORDER.AD_ORG_ID AS AD_ORG_ID
+      C_ORDERLINE.QTYORDERED-SUM(COALESCE(M_MATCHPO.QTY,0)) AS QTYORDERED, '-1' AS ISACTIVE, C_ORDERLINE.LINE, C_ORDER.AD_ORG_ID AS AD_ORG_ID,
+      (CASE WHEN AUMQTY IS NULL THEN C_ORDERLINE.QTYORDERED-SUM(COALESCE(M_MATCHPO.QTY,0)) ELSE (AUMQTY-SUM(COALESCE(M_MATCHPO.QTY,0))) END) AS AUMQTY, 
+      (CASE WHEN C_AUM IS NULL THEN M_GET_DEFAULT_AUM_FOR_DOCUMENT(C_ORDERLINE.M_PRODUCT_ID, C_ORDER.C_DOCTYPE_ID) ELSE C_AUM END) AS C_AUM,
+      C_ORDER.C_DOCTYPE_ID, C_ORDERLINE.M_PRODUCT_ID, C_ORDERLINE.C_UOM_ID
       FROM C_ORDERLINE left join M_MATCHPO on C_ORDERLINE.C_ORDERLINE_ID = M_MATCHPO.C_ORDERLINE_ID
                                            and M_MATCHPO.M_INOUTLINE_ID IS NOT NULL
                        left join M_ATTRIBUTESETINSTANCE on C_ORDERLINE.M_ATTRIBUTESETINSTANCE_ID = M_ATTRIBUTESETINSTANCE.M_ATTRIBUTESETINSTANCE_ID,
@@ -77,7 +81,8 @@
       AND C_ORDER.C_DOCTYPE_ID = C_DOCTYPE.C_DOCTYPE_ID
       AND C_DOCTYPE.ISRETURN = 'N'
       GROUP BY C_ORDERLINE.C_ORDERLINE_ID, C_ORDER.C_ORDER_ID, C_ORDER.DOCUMENTNO, C_ORDER.DATEORDERED, C_BPARTNER.C_BPARTNER_ID,
-      C_BPARTNER.NAME, C_ORDERLINE.M_PRODUCT_ID, M_ATTRIBUTESETINSTANCE.DESCRIPTION, C_ORDERLINE.QTYORDERED, C_ORDERLINE.LINE, C_ORDER.AD_ORG_ID
+      C_BPARTNER.NAME, C_ORDERLINE.M_PRODUCT_ID, M_ATTRIBUTESETINSTANCE.DESCRIPTION, C_ORDERLINE.QTYORDERED, C_ORDERLINE.LINE, C_ORDER.AD_ORG_ID,
+      C_ORDER.C_DOCTYPE_ID, C_ORDERLINE.M_PRODUCT_ID, C_ORDERLINE.C_UOM_ID, C_AUM, AUMQTY
       ) A
       WHERE (CASE WHEN Total_Qty < 0 THEN -1 ELSE 1 END) = (CASE WHEN Qtyordered < 0 THEN -1 ELSE 1 End) AND Qtyordered <> 0
       ORDER BY C_BPARTNER_ID, DOCUMENTNO, LINE
@@ -213,5 +218,30 @@
       SELECT VALUE FROM M_LOCATOR WHERE M_LOCATOR_ID=?
     </Sql>
     <Parameter name="mLocatorId"/>
-  </SqlMethod>  
+  </SqlMethod>
+  <SqlMethod name="selectAUM" type="preparedStatement" return="multiple">
+    <SqlMethodComment></SqlMethodComment>
+    <Sql>
+      <![CDATA[
+        SELECT M.C_UOM_ID AS ID, C.NAME AS NAME
+        FROM M_PRODUCT_AUM M, C_UOM C
+        WHERE M.M_PRODUCT_ID = ?
+        AND M.C_UOM_ID = C.C_UOM_ID
+      ]]>
+    </Sql>
+    <Parameter name="productId"/>
+  </SqlMethod>
+  <SqlMethod name="selectAUMDefault" type="preparedStatement" return="multiple">
+    <SqlMethodComment></SqlMethodComment>
+    <Sql>
+      <![CDATA[
+        SELECT M_GET_DEFAULT_AUM_FOR_DOCUMENT(?, ?) AS ID, 
+          (SELECT UOMSYMBOL FROM C_UOM WHERE C_UOM_ID = M_GET_DEFAULT_AUM_FOR_DOCUMENT(?, ?)) AS NAME FROM DUAL
+      ]]>
+    </Sql>
+    <Parameter name="productId"/>
+    <Parameter name="cDoctypeId"/>
+    <Parameter name="productId"/>
+    <Parameter name="cDoctypeId"/>
+  </SqlMethod>
 </SqlClass>