Issue #24224:normalize margin calculations
[xtuple] / foundation-database / public / tables / metasql / opensalesorders-detail.mql
index 81385aa..bb58084 100644 (file)
@@ -20,12 +20,17 @@ SELECT DISTINCT
 <? endforeach ?>
        firstline(cohead_ordercomments) AS notes,
        calcSalesOrderAmt(cohead_id) AS ordertotal,
+       CASE WHEN (calcSalesOrderAmt(cohead_id,'S') != 0.0)
+              THEN calcSalesOrderAmt(cohead_id,'M')
+            ELSE 0.0
+       END AS ordermargin,
        CASE WHEN (calcSalesOrderAmt(cohead_id,'S') != 0.0)
               THEN (calcSalesOrderAmt(cohead_id,'M') / calcSalesOrderAmt(cohead_id,'S'))
             ELSE 1.0
        END AS ordermarginpercent,
        'percent' AS ordermarginpercent_xtnumericrole,
-       'extprice' AS ordertotal_xtnumericrole
+       'extprice' AS ordertotal_xtnumericrole,
+       'extprice' AS ordermargin_xtnumericrole
 FROM cohead 
      JOIN custinfo ON (cohead_cust_id=cust_id) 
      JOIN custtype ON (cust_custtype_id=custtype_id)