Reduce order table net revenue by refund total (https://github.com/woocommerce/woocommerce-admin/pull/988)

* Reduce order table net revenue by refund total

* Use order utils to get refund total
This commit is contained in:
Joshua T Flowers 2018-12-05 10:06:00 +08:00 committed by GitHub
parent 9e1cb88dfa
commit 755b9c94f7
4 changed files with 3735 additions and 3725 deletions

View File

@ -7,6 +7,7 @@
* WooCommerce dependencies
*/
import { getCurrencyFormatDecimal } from '@woocommerce/currency';
import { getOrderRefundTotal } from 'lib/order-values';
export function formatTableOrders( orders ) {
return orders.map( order => {
@ -33,7 +34,9 @@ export function formatTableOrders( orders ) {
items_sold: line_items.reduce( ( acc, item ) => item.quantity + acc, 0 ),
coupon_lines,
currency,
net_revenue: getCurrencyFormatDecimal( total - total_tax - shipping_total - discount_total ),
net_revenue: getCurrencyFormatDecimal(
total - total_tax - shipping_total - discount_total + getOrderRefundTotal( order )
),
};
} );
}

View File

@ -64,7 +64,7 @@ class WC_Admin_Reports_Orders_Data_Store extends WC_Admin_Reports_Data_Store imp
'refunds' => 'SUM(refund_total) AS refunds',
'taxes' => 'SUM(tax_total) AS taxes',
'shipping' => 'SUM(shipping_total) AS shipping',
'net_revenue' => 'SUM(net_total) AS net_revenue',
'net_revenue' => '( SUM(net_total) - SUM(refund_total) ) AS net_revenue',
'avg_items_per_order' => 'AVG(num_items_sold) AS avg_items_per_order',
'avg_order_value' => 'AVG(gross_total) AS avg_order_value',
'num_returning_customers' => 'SUM(returning_customer = 1) AS num_returning_customers',

File diff suppressed because it is too large Load Diff

View File

@ -32,6 +32,13 @@ class WC_Tests_Reports_Orders extends WC_Unit_Test_Case {
$order->set_total( 97 ); // $25x4 products + $10 shipping - $20 discount + $7 tax.
$order->save();
$refund = wc_create_refund(
array(
'amount' => 12,
'order_id' => $order->get_id(),
)
);
$data_store = new WC_Admin_Reports_Orders_Data_Store();
$data_store::update( $order );
@ -51,10 +58,10 @@ class WC_Tests_Reports_Orders extends WC_Unit_Test_Case {
'avg_order_value' => 97,
'gross_revenue' => 97,
'coupons' => 20,
'refunds' => 0,
'refunds' => 12,
'taxes' => 7,
'shipping' => 10,
'net_revenue' => 80,
'net_revenue' => 68,
'num_returning_customers' => 0,
'num_new_customers' => 1,
'products' => '1',
@ -68,11 +75,11 @@ class WC_Tests_Reports_Orders extends WC_Unit_Test_Case {
'date_end_gmt' => $end_time,
'subtotals' => array(
'gross_revenue' => 97,
'net_revenue' => 80,
'net_revenue' => 68,
'coupons' => 20,
'shipping' => 10,
'taxes' => 7,
'refunds' => 0,
'refunds' => 12,
'orders_count' => 1,
'num_items_sold' => 4,
'avg_items_per_order' => 4,
@ -94,7 +101,7 @@ class WC_Tests_Reports_Orders extends WC_Unit_Test_Case {
$query = new WC_Admin_Reports_Orders_Stats_Query( $args );
$expected_stats = array(
'totals' => array(
'net_revenue' => 80,
'net_revenue' => 68,
'avg_order_value' => 97,
'orders_count' => 1,
'avg_items_per_order' => 4,
@ -112,7 +119,7 @@ class WC_Tests_Reports_Orders extends WC_Unit_Test_Case {
'date_end' => $end_time,
'date_end_gmt' => $end_time,
'subtotals' => array(
'net_revenue' => 80,
'net_revenue' => 68,
'avg_order_value' => 97,
'orders_count' => 1,
'avg_items_per_order' => 4,