details: https://code.openbravo.com/erp/devel/pi/rev/4f040fb8603a changeset: 31769:4f040fb8603a user: Alvaro Ferraz <alvaro.ferraz <at> openbravo.com> date: Fri Mar 31 10:34:33 2017 +0200 summary: Related to issue 24905: Code review improvements
Write three queries in just one. Do just one update with a select sub-query. diffstat: src-db/database/model/functions/M_INOUT_POST.xml | 33 ++++++++---------------- 1 files changed, 11 insertions(+), 22 deletions(-) diffs (44 lines): diff -r 91233525974f -r 4f040fb8603a src-db/database/model/functions/M_INOUT_POST.xml --- a/src-db/database/model/functions/M_INOUT_POST.xml Fri Mar 31 10:24:51 2017 +0200 +++ b/src-db/database/model/functions/M_INOUT_POST.xml Fri Mar 31 10:34:33 2017 +0200 @@ -510,29 +510,18 @@ IF(Cur_InOut.Processed='N' AND Cur_InOut.DocStatus='DR' AND Cur_InOut.DocAction='CO') THEN -- For all active shipment lines v_ResultStr:='HeaderLoop-1'; - + -- Update the C_Order_Id of M_InOut accordingly - SELECT COUNT(A.c_order_id) - INTO v_Count - FROM ( - SELECT ol.c_order_id FROM M_InOutLine iol - JOIN C_OrderLine ol on iol.C_OrderLine_Id = ol.C_OrderLine_Id - WHERE iol.M_InOut_Id = Cur_InOut.M_InOut_ID - GROUP BY ol.c_order_id) A; - IF v_Count = 1 THEN - UPDATE M_InOut - SET C_Order_Id = ( - SELECT ol.c_order_id FROM M_InOutLine iol - JOIN C_OrderLine ol on iol.C_OrderLine_Id = ol.C_OrderLine_Id - WHERE iol.M_InOut_Id = Cur_InOut.M_InOut_ID - GROUP BY ol.c_order_id) - WHERE M_InOut_Id = Cur_InOut.M_InOut_ID; - ELSE - UPDATE M_InOut - SET C_Order_Id = NULL - WHERE M_InOut_Id = Cur_InOut.M_InOut_ID; - END IF; - + UPDATE M_InOut io + SET C_Order_Id = ( + SELECT CASE WHEN min(ol.c_order_id) = max(ol.c_order_id) THEN min(ol.c_order_id) ELSE NULL END + FROM M_InOutLine iol + JOIN C_OrderLine ol + ON iol.C_OrderLine_Id = ol.C_OrderLine_Id + WHERE iol.M_InOut_Id = io.M_InOut_ID + ) + WHERE io.M_InOut_Id = Cur_InOut.M_InOut_ID; + IF v_Aux=0 THEN RAISE_APPLICATION_ERROR(-20000, '@ReceiptWithoutLines@'); END IF; ------------------------------------------------------------------------------ Check out the vibrant tech community on one of the world's most engaging tech sites, Slashdot.org! http://sdm.link/slashdot _______________________________________________ Openbravo-commits mailing list Openbravo-commits@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/openbravo-commits