details: https://code.openbravo.com/erp/devel/pi/rev/9c931e5263c1 changeset: 31569:9c931e5263c1 user: Miguel <martencobasmiguel <at> gmail.com> date: Mon Feb 27 13:05:01 2017 -0500 summary: Fixes issue 24905: Sales Order relation is not updated in Shipment header in some cases.
When a line was deleted was not verified if there was other invoice lines associated to orders distinct than the header's Sales/Purchase Order field and it was not updated rightly. Also when inserting a line from the create lines process, there being two or more lines already inserted related to different orders, the Sales Order field related with the header was updated with the last one. To get the sales order field updated correctly depending on the previous cases, the following logic was added to the CreateFrom_Shipment_data.xsql and M_InOut function. Each time a line is inserted, the shipment's order line field will be updated with NULL if there are not any line created from an order or if there are more than one line created from different orders. In the case that lines were created from an unique sales order then it will be fullfilled with it, otherwise it will be left empty. When the line is deleted, the logic explained above needs to be checked inside a trigger, but it is not possible because the table is in a mutant status in Oracle, due this reason it is not possible to update the shipment's header at line's deletion time. As solution to this situation, this field is updated when the shipment is completed. diffstat: src-db/database/model/functions/M_INOUT_POST.xml | 24 +++++++++- src/org/openbravo/erpCommon/ad_actionButton/CreateFrom_Shipment_data.xsql | 10 +++- 2 files changed, 31 insertions(+), 3 deletions(-) diffs (72 lines): diff -r 83679bd609bb -r 9c931e5263c1 src-db/database/model/functions/M_INOUT_POST.xml --- a/src-db/database/model/functions/M_INOUT_POST.xml Tue Feb 28 10:29:36 2017 +0100 +++ b/src-db/database/model/functions/M_INOUT_POST.xml Mon Feb 27 13:05:01 2017 -0500 @@ -22,7 +22,7 @@ * parts created by ComPiere are Copyright (C) ComPiere, Inc.; * All Rights Reserved. * Contributor(s): Openbravo SLU - * Contributions are Copyright (C) 2001-2016 Openbravo, S.L.U. + * Contributions are Copyright (C) 2001-2017 Openbravo, S.L.U. * * Specifically, this derivative work is based upon the following Compiere * file and version. @@ -511,6 +511,28 @@ -- 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; + IF v_Aux=0 THEN RAISE_APPLICATION_ERROR(-20000, '@ReceiptWithoutLines@'); END IF; diff -r 83679bd609bb -r 9c931e5263c1 src/org/openbravo/erpCommon/ad_actionButton/CreateFrom_Shipment_data.xsql --- a/src/org/openbravo/erpCommon/ad_actionButton/CreateFrom_Shipment_data.xsql Tue Feb 28 10:29:36 2017 +0100 +++ b/src/org/openbravo/erpCommon/ad_actionButton/CreateFrom_Shipment_data.xsql Mon Feb 27 13:05:01 2017 -0500 @@ -12,7 +12,7 @@ * under the License. * The Original Code is Openbravo ERP. * The Initial Developer of the Original Code is Openbravo SLU - * All portions are Copyright (C) 2001-2016 Openbravo SLU + * All portions are Copyright (C) 2001-2017 Openbravo SLU * All Rights Reserved. * Contributor(s): ______________________________________. ************************************************************************ @@ -807,11 +807,17 @@ <SqlMethodComment></SqlMethodComment> <Sql> UPDATE M_InOut SET C_Order_id = ?, DATEORDERED = (SELECT DATEORDERED FROM C_ORDER WHERE C_ORDER_ID=?) - WHERE M_InOut_ID=? + WHERE M_InOut_ID=? AND NOT EXISTS ( + 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 = ? + AND ol.c_order_id != ?) </Sql> <Parameter name="cOrderId"/> <Parameter name="cOrderId"/> <Parameter name="mInoutId"/> + <Parameter name="mInoutId"/> + <Parameter name="cOrderId"/> </SqlMethod> <SqlMethod name="updateC_Invoice_ID" type="preparedStatement" connection="true" return="rowCount"> <SqlMethodComment></SqlMethodComment> ------------------------------------------------------------------------------ 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