Fixes issue 33838: Correct Stock Reservation when created from a closed order
authorMark <markmm82@gmail.com>
Thu, 15 Sep 2016 12:14:10 -0400
changeset 30292 676e26599466
parent 30291 61036197bbae
child 30293 dcaf5195237a
child 30552 4389ee8779f4
Fixes issue 33838: Correct Stock Reservation when created from a closed order

When voiding a shipment related to a reserved order, if order is closed, new reservation will not be created (in case order was fully shipped) and existing reservation will not be updated (in case order was partially shipped).
Besides, when closing an order, related reservation will be also closed.
src-db/database/model/functions/C_ORDER_POST1.xml
src-db/database/model/functions/M_INOUT_POST.xml
--- a/src-db/database/model/functions/C_ORDER_POST1.xml	Thu Sep 15 14:04:47 2016 +0200
+++ b/src-db/database/model/functions/C_ORDER_POST1.xml	Thu Sep 15 12:14:10 2016 -0400
@@ -1325,6 +1325,7 @@
                   END IF;
                   UPDATE m_reservation
                   SET quantity = cur_orderline.qtyordered,
+                      res_status = 'CL',
                       updated = now(),
                       updatedby = v_user
                   WHERE m_reservation_id = v_reservation_id;
--- a/src-db/database/model/functions/M_INOUT_POST.xml	Thu Sep 15 14:04:47 2016 +0200
+++ b/src-db/database/model/functions/M_INOUT_POST.xml	Thu Sep 15 12:14:10 2016 -0400
@@ -1180,10 +1180,13 @@
               JOIN M_INOUTLINE iol
               ON ol.c_orderline_id = iol.c_orderline_id
               AND ol.m_product_id = iol.m_product_id
+              JOIN C_ORDER o
+              ON ol.c_order_id = o.c_order_id
               WHERE iol.m_inout_id = Cur_InOut.m_inout_id
               AND r.res_status <> 'DR'
               AND iol.movementqty > 0
               AND iol.canceled_inoutline_id IS NULL
+              AND o.docstatus <> 'CL'
               AND r.created = (
                 SELECT max(created)
                 FROM M_RESERVATION