[Reservations]fix issue in get_stock when no reservation is given.
authorGorka Ion Damián <gorkaion.damian@openbravo.com>
Thu, 22 Nov 2012 17:37:04 +0100
changeset 18745 7dfe05aa19c5
parent 18744 229839951ded
child 18746 a1922885972b
[Reservations]fix issue in get_stock when no reservation is given.
src-db/database/model/functions/M_GET_STOCK.xml
src-db/database/model/functions/M_RESERVATION_POST.xml
--- a/src-db/database/model/functions/M_GET_STOCK.xml	Thu Nov 22 17:09:37 2012 +0100
+++ b/src-db/database/model/functions/M_GET_STOCK.xml	Thu Nov 22 17:37:04 2012 +0100
@@ -211,7 +211,7 @@
           LEFT JOIN m_attributesetinstance asi ON t.m_attributesetinstance_id = asi.m_attributesetinstance_id
           LEFT JOIN m_product_uom pu ON t.m_product_uom_id = pu.m_product_uom_id
           LEFT JOIN c_uom u ON pu.c_uom_id = u.c_uom_id
-          LEFT JOIN m_reservation r ON r.m_reservation_id = v_reservation_id
+          LEFT JOIN m_reservation r ON r.m_reservation_id = v_reservation_id AND r.m_product_id = t.m_product_id AND r.c_uom_id = t.c_uom_id
           LEFT JOIN (
               SELECT r.m_product_id, r.c_uom_id, rs.m_locator_id, COALESCE(rs.m_attributesetinstance_id, '0') as m_attributesetinstance_id,
                   SUM(rs.quantity - COALESCE(rs.releasedqty, 0)) AS reservedqty
--- a/src-db/database/model/functions/M_RESERVATION_POST.xml	Thu Nov 22 17:09:37 2012 +0100
+++ b/src-db/database/model/functions/M_RESERVATION_POST.xml	Thu Nov 22 17:37:04 2012 +0100
@@ -160,7 +160,8 @@
   
         UPDATE c_orderline
         SET so_res_status = CASE WHEN v_quantity = v_reservedqty THEN 'CR'
-                                 ELSE 'PR'
+                                 WHEN v_reservedqty > 0 THEN 'PR'
+                                 ELSE 'NR'
                             END
         WHERE c_orderline_id = v_orderline_id;
   
@@ -179,11 +180,11 @@
                             END
         WHERE c_order_id = v_sales_order_id;
       END IF;
-  
+      -- ADD RESERVED STOCK
+      M_RESERVE_STOCK_AUTO(v_reservation_id, v_user_id, v_message);
+
       v_newstatus := 'CO';
       v_newaction := 'HO';
-      -- ADD RESERVED STOCK
-      M_RESERVE_STOCK_AUTO(v_reservation_id, v_user_id, v_message);
     END;
 
   ELSIF (v_resaction = 'HO') THEN