Bug Tracker Incident #15639
Thanks for this feedback, Keith. Closing based on feedback.
I have tested this on 3.7.4 and it behaves as it should, dividing the discountfromcust value returned by formatPrcnt by 100 to arrive at a correct value of f_discountfromcust.
change metasql salesOrderItems-list as described (correctly scale f_discountfromcust)
The MetaSQL statement “salesOrderItems" (type “list”) uses the coitem.custprice and coitem.price fields to calculate the customer discount, since the entered discount is not stored on coitem.
It uses the following CASE statement to do the calculation in the FROM clause of the query:
CASE WHEN (coitem_custprice = 0.0) THEN 100.0
This results in “discountfromcust” being equal to a number between 0 and 100.
In the SELECT clause of the query, the query checks for the existence of parameter “includeFormatted”. If the parameter does not exist, the query sets the returned value of f_discountfromcust to discountfromcust, and that is correct. However, if the parameter does exist, the query sets the returned value of f_discountfromcust to be formatPrcnt(discountfromcust). This is not correct, because the formatPrcnt function returns a value of SELECT formatNumeric( * 100, 'percent') as its result, which when using discountfromcust (a number between 0 and 100) as its parameter, returns a value between 0 and 10,000. In effect, because the initial calculation of discountfromcust multiplies by 100, and the formatting function also multiplies by 100, the end result is 100 times higher than it should be. For instance, if price is and custprice is 0, then discountfromcust is 10, but f_discountfromcust when “includeFormatted” exists is 1,000.
The problem shows itself when one adds f_discountfromcust to a Sales Order Acknowledgement report generated from the Sales Order entry window. In this case, xTuple must pass “includeFormatted” as a parameter to the report, because f_discountfromcust is always shown at a value 100 times higher than it should be.
This took a lot to describe, but it’s a quick fix, as shown in the attached TXT file with an updated salesOrderList MetaSQL query. When “includeFormatted” exists, the query needs to return f_discountfromcust as formatPrcnt(discountfromcust / 100), not formatPrcnt(discountfromcust).
Steps to Reproduce:
Change the Customer Order Acknowledgement report to include Discount on the detail line.
Create a sales order and enter a customer discount of 10% on the sales order line item. Print the sales order using the updated Customer Order Acknowledgement. The discount shown will be 1000, not 10.
|Incident||1326||Exchange Rates and Effectivity Dates in 2.2.1 affecting Aging reports / invoices||Related to||x|
|Incident||1355||Create a Package||Related to||x|
|Project||XTUPLEAPPS||Ported From Mantis||x|
SubscribersYou do not have permission to view subscribers.
|10/06/11 16:07||ptyler||Status||Status Changed: Resolved -> Closed|
|09/09/11 17:36||krauseo||New||Incident Added|
|09/09/11 17:36||krauseo||Characteristic Backport Added: "No"|
|09/09/11 17:36||krauseo||Characteristic CodeReview Added: ""|
|09/09/11 17:36||krauseo||Characteristic Operating System Added: "Windows XP"|
|09/09/11 17:36||krauseo||Characteristic haxTuple Added: "No"|
|09/09/11 17:36||krauseo||Characteristic Estimated Hours Added: ""|
|09/09/11 17:36||krauseo||Characteristic Doc Flag Added: "False"|
|09/09/11 17:36||krauseo||Characteristic Copyright Assigned Added: "Yes"|
|09/09/11 17:36||acdrupal||Found In: -> 3.7.2|
|09/11/11 14:53||krauseo||Summary Updated: "*MetaSQL statement “salesOrderItems” (list) incorrectly calculates “discountfromcust” when the “IncludeFormatted” parameter exist" -> "*MetaSQL statement “salesOrderItems” (list) incorrectly calculates “discountfromcust” when the IncludeFormatted parameter exists"|
|09/11/11 14:53||krauseo||Description Updated: "The MetaSQL statemen..." -> "The MetaSQL statemen..."|
|09/12/11 14:34||reddog||Fixed In: -> 3.8.0|
|09/12/11 14:33||reddog||Characteristic CodeReview Changed: "" -> "Needed"|
|09/12/11 14:33||reddog||Description Updated: "The MetaSQL statemen..." -> "The MetaSQL statemen..."|
|09/12/11 14:33||reddog||Status||Status Changed: New -> Resolved|
|09/12/11 14:33||reddog||Assigned||Assigned to: "" -> "reddog"|
|09/12/11 14:33||reddog||Resolution||Resolution Changed: -> Fixed|
|09/21/11 10:50||reddog||Characteristic Backport Changed: "No" -> "Yes"|
|09/21/11 14:05||reddog||Characteristic Backport Changed: "Yes" -> "No"|
|09/21/11 14:07||reddog||Fixed In: 3.8.0Beta -> 3.7.4|
|06/20/14 10:24||bc_admin||Characteristic Points Deleted: ""|