awesomemotive / easy-digital-downloads

Sell digital downloads through WordPress
https://easydigitaldownloads.com
GNU General Public License v2.0
863 stars 475 forks source link

3.0 - Customers Report - Averages aren't correct due to picking up refund records #8684

Closed ashleyfae closed 2 years ago

ashleyfae commented 3 years ago

Bug Report

Expected behavior

I have two orders, one of which has been refunded.

Here's how the Customers Reports look:

Screenshot from 2021-06-04 10-52-24

The query that's running for EDD\Stats::get_customer_lifetime_value() is:

SELECT AVG(total) AS total
FROM (
         SELECT SUM(total) AS total
         FROM wp_edd_orders
         WHERE 1 = 1
           AND wp_edd_orders.status IN ('complete', 'revoked')
           AND wp_edd_orders.date_created >= '2021-05-05 00:00:00'
           AND wp_edd_orders.date_created <= '2021-06-04 23:59:59'
         GROUP BY customer_id
     ) o

The problem is that it's picking up the complete refund record, but not the refunded order record and it's making the numbers all weird.

I think what we should be doing is setting wp_edd_orders.type = 'sale' and the statuses should be the gross order statuses.

Information (if a specific version is affected):

PHP Version:

EDD Version (or branch): release/3.0

WordPress Version:

Any other relevant information: This is milestoned for after 3.0 because it's not a blocker for 3.0 launch.

zkawesome commented 2 years ago

@cklosowski already fixed this.