No need to query on taxhist when we know the inherited table.
[xtuple] / foundation-database / public / functions / calculatetaxdetailline.sql
index df47bb4..b48cbc5 100644 (file)
@@ -1,8 +1,8 @@
 
-CREATE OR REPLACE FUNCTION calculatetaxdetailline(text, integer) 
+CREATE OR REPLACE FUNCTION calculatetaxdetailline(text, integer)
   RETURNS SETOF taxdetail AS
 $BODY$
--- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pOrderType ALIAS FOR $1;
@@ -12,7 +12,7 @@ DECLARE
   _totaltax numeric;
   _y RECORD;
   _table text;
-  
+
 BEGIN
    _totaltax=0.0;
 
@@ -31,14 +31,12 @@ BEGIN
    ELSIF pOrderType = 'AP' THEN
      _table := 'apopentax';
    END IF;
-     
+
    _qry := 'SELECT taxhist_tax_id as tax_id, tax_code, tax_descrip, taxhist_tax, COALESCE(taxhist_sequence,0) AS taxhist_sequence
-            FROM taxhist 
-             JOIN tax ON (taxhist_tax_id=tax_id) 
-             JOIN pg_class ON (pg_class.oid=taxhist.tableoid) 
-            WHERE ( (taxhist_parent_id = ' || pOrderId || ')
-             AND (relname=''' || _table || ''') );';
-    
+            FROM ' || _table || '
+             JOIN tax ON (taxhist_tax_id=tax_id)
+            WHERE ( (taxhist_parent_id = ' || pOrderId || ') );';
+
    FOR _y IN  EXECUTE _qry
    LOOP
      _row.taxdetail_tax_id=_y.tax_id;