details:   https://code.openbravo.com/erp/devel/pi/rev/33a7fe93995e
changeset: 33855:33a7fe93995e
user:      David Miguelez <david.miguelez <at> openbravo.com>
date:      Thu Apr 19 12:31:46 2018 +0200
summary:   Fixes Issue 38238. Do not group Invoices by Organization when not 
possible.

In case the orders belong to different Organizations and there has not
been an Organization selected manually for which to create the Invoice,
do not group by Organization since it is not possible from a functional
point of view.

* Order the results of the query by Organization
* Check group by Organization logic
* Use this logic to decide if the Invoice should be grouped by Organization
  or not

diffstat:

 src-db/database/model/functions/C_INVOICE_CREATE.xml |  11 +++++++++--
 1 files changed, 9 insertions(+), 2 deletions(-)

diffs (35 lines):

diff -r dd78fd211350 -r 33a7fe93995e 
src-db/database/model/functions/C_INVOICE_CREATE.xml
--- a/src-db/database/model/functions/C_INVOICE_CREATE.xml      Sat Apr 14 
15:25:14 2018 +0200
+++ b/src-db/database/model/functions/C_INVOICE_CREATE.xml      Thu Apr 19 
12:31:46 2018 +0200
@@ -94,6 +94,7 @@
     c_soo_doctype C_DOCTYPE.C_DOCTYPE_ID%TYPE := 
'01360D369B5F473686354A701A6EA559';
 
     Cur_Bpblocked RECORD;
+    v_groupByOrg VARCHAR2(1);
     
     Cur_OrderLine_ISOPEN BOOLEAN:=false;
     Cur_InOutLine_ISOPEN BOOLEAN:=false;
@@ -909,7 +910,7 @@
                 OR(v_Selection<>'Y'
                 AND(si.DateLimit IS NULL
                 OR TRUNC(o.DateOrdered)<=si.DateLimit)) ))
-              ORDER BY sh.C_BPartner_ID, pl.istaxincluded, (
+              ORDER BY sh.C_BPartner_ID, pl.istaxincluded, sh.ad_org_id, (
                 CASE TO_CHAR(SUBSTR(RPAD(substr(bp.InvoiceGrouping, 
instr(bp.InvoiceGrouping, '_') + 1), 15, '0'), 1, 1))
                   WHEN '0'
                   THEN '0'
@@ -1034,7 +1035,13 @@
               ELSE 
                 v_invOrg_ID := Cur_InvoiceSchedule.AD_Org_ID;
               END IF;
-              IF((v_Partner_ID<>Cur_InvoiceSchedule.C_BPartner_ID) OR 
(v_istaxincluded <> cur_invoiceschedule.istaxincluded) 
OR(SUBSTR(Cur_InvoiceSchedule.InvoiceGrouping, 1, 1)='1' AND 
v_gOrg_ID<>Cur_InvoiceSchedule.AD_Org_ID) 
OR(SUBSTR(Cur_InvoiceSchedule.InvoiceGrouping, 2, 1)='1' AND 
v_gOrder_ID<>Cur_InvoiceSchedule.C_Order_ID) 
OR(SUBSTR(Cur_InvoiceSchedule.InvoiceGrouping, 3, 1)='1' AND 
v_gInOut_ID<>Cur_InvoiceSchedule.M_InOut_ID) 
OR(SUBSTR(Cur_InvoiceSchedule.InvoiceGrouping, 4, 1)='1' AND 
v_gBillTo_ID<>Cur_InvoiceSchedule.BillTo_ID) 
OR(SUBSTR(Cur_InvoiceSchedule.InvoiceGrouping, 5, 1)='1' AND 
v_gBPartner_Location_ID<>Cur_InvoiceSchedule.C_BPartner_Location_ID) 
OR(SUBSTR(Cur_InvoiceSchedule.InvoiceGrouping, 6, 1)='1' AND 
v_gSalesRep_ID<>Cur_InvoiceSchedule.SalesRep_ID) 
OR(SUBSTR(Cur_InvoiceSchedule.InvoiceGrouping, 7, 1)='1' AND 
v_gPaymentRule<>Cur_InvoiceSchedule.PaymentRule) 
OR(SUBSTR(Cur_InvoiceSchedule.InvoiceGrouping, 8, 1)='1' AND 
v_gPaymentTerm_ID<>Cur_InvoiceSchedule.C_PaymentTerm_ID) OR(SUBSTR(
+              IF (SUBSTR(Cur_InvoiceSchedule.InvoiceGrouping, 1, 1)='0' AND 
v_IncludeChildOrgs = 'Y' AND v_AD_Org_ID IS NOT NULL) THEN
+                -- Related to Issue 38238: Only when an Organizaton for the 
Invoice has been explicitly selected by the user, and the Children 
Organizations are included it is possible to group by Organization
+                v_groupByOrg := 'Y';
+              ELSE
+                v_groupByOrg := 'N';
+              END IF;
+              IF((v_Partner_ID<>Cur_InvoiceSchedule.C_BPartner_ID) OR 
(v_istaxincluded <> cur_invoiceschedule.istaxincluded) OR(v_groupByOrg = 'N' 
AND v_gOrg_ID<>Cur_InvoiceSchedule.AD_Org_ID) 
OR(SUBSTR(Cur_InvoiceSchedule.InvoiceGrouping, 2, 1)='1' AND 
v_gOrder_ID<>Cur_InvoiceSchedule.C_Order_ID) 
OR(SUBSTR(Cur_InvoiceSchedule.InvoiceGrouping, 3, 1)='1' AND 
v_gInOut_ID<>Cur_InvoiceSchedule.M_InOut_ID) 
OR(SUBSTR(Cur_InvoiceSchedule.InvoiceGrouping, 4, 1)='1' AND 
v_gBillTo_ID<>Cur_InvoiceSchedule.BillTo_ID) 
OR(SUBSTR(Cur_InvoiceSchedule.InvoiceGrouping, 5, 1)='1' AND 
v_gBPartner_Location_ID<>Cur_InvoiceSchedule.C_BPartner_Location_ID) 
OR(SUBSTR(Cur_InvoiceSchedule.InvoiceGrouping, 6, 1)='1' AND 
v_gSalesRep_ID<>Cur_InvoiceSchedule.SalesRep_ID) 
OR(SUBSTR(Cur_InvoiceSchedule.InvoiceGrouping, 7, 1)='1' AND 
v_gPaymentRule<>Cur_InvoiceSchedule.PaymentRule) 
OR(SUBSTR(Cur_InvoiceSchedule.InvoiceGrouping, 8, 1)='1' AND 
v_gPaymentTerm_ID<>Cur_InvoiceSchedule.C_PaymentTerm_ID) OR(SUBSTR(
                 Cur_InvoiceSchedule.InvoiceGrouping, 9, 1)='1' AND 
v_gCurrency_ID<>Cur_InvoiceSchedule.C_Currency_ID) 
OR(SUBSTR(Cur_InvoiceSchedule.InvoiceGrouping, 10, 1)='1' AND 
v_gCampaign_ID<>Cur_InvoiceSchedule.C_Campaign_ID) 
OR(SUBSTR(Cur_InvoiceSchedule.InvoiceGrouping, 11, 1)='1' AND 
((v_gProject_ID<>Cur_InvoiceSchedule.C_Project_ID) OR (v_gProject_ID IS NULL 
AND Cur_InvoiceSchedule.C_Project_ID IS NOT NULL) OR (v_gProject_ID IS NOT NULL 
AND Cur_InvoiceSchedule.C_Project_ID IS NULL))) 
OR(SUBSTR(Cur_InvoiceSchedule.InvoiceGrouping, 12, 1)='1' AND 
v_gActivitiy_ID<>Cur_InvoiceSchedule.C_Activity_ID) 
OR(SUBSTR(Cur_InvoiceSchedule.InvoiceGrouping, 13, 1)='1' AND 
v_gOrgTrx_ID<>Cur_InvoiceSchedule.AD_OrgTrx_ID) 
OR(SUBSTR(Cur_InvoiceSchedule.InvoiceGrouping, 14, 1)='1' AND 
v_gUser1_ID<>Cur_InvoiceSchedule.User1_ID) 
OR(SUBSTR(Cur_InvoiceSchedule.InvoiceGrouping, 15, 1)='1' AND 
v_gUser2_ID<>Cur_InvoiceSchedule.User2_ID)) THEN
                 v_Partner_ID:=Cur_InvoiceSchedule.C_BPartner_ID;
                 v_istaxincluded:=cur_invoiceschedule.istaxincluded;

------------------------------------------------------------------------------
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

Reply via email to