Reduce net order total by refunded amount less tax and shipping refunds (https://github.com/woocommerce/woocommerce-admin/pull/1600)
* Reduce net order total by refunded amount less tax and shipping refunds * Fix net_totals in tests with refunds
This commit is contained in:
parent
4f64358c8e
commit
44604bcd02
|
@ -401,7 +401,7 @@ class WC_Admin_Reports_Orders_Stats_Data_Store extends WC_Admin_Reports_Data_Sto
|
|||
'refund_total' => $order->get_total_refunded(),
|
||||
'tax_total' => $order->get_total_tax(),
|
||||
'shipping_total' => $order->get_shipping_total(),
|
||||
'net_total' => (float) $order->get_total() - (float) $order->get_total_tax() - (float) $order->get_shipping_total(),
|
||||
'net_total' => self::get_net_total( $order ),
|
||||
'returning_customer' => self::is_returning_customer( $order ),
|
||||
'status' => self::normalize_order_status( $order->get_status() ),
|
||||
);
|
||||
|
@ -507,6 +507,23 @@ class WC_Admin_Reports_Orders_Stats_Data_Store extends WC_Admin_Reports_Data_Sto
|
|||
return $num_items;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the net amount from an order without shipping, tax, or refunds.
|
||||
*
|
||||
* @param array $order WC_Order object.
|
||||
* @return float
|
||||
*/
|
||||
protected static function get_net_total( $order ) {
|
||||
$net_total = $order->get_total() - $order->get_total_tax() - $order->get_shipping_total();
|
||||
|
||||
$refunds = $order->get_refunds();
|
||||
foreach ( $refunds as $refund ) {
|
||||
$net_total += $refund->get_total() - $refund->get_total_tax() - $refund->get_shipping_total();
|
||||
}
|
||||
|
||||
return $net_total > 0 ? (float) $net_total : 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check to see if an order's customer has made previous orders or not
|
||||
*
|
||||
|
|
|
@ -58,13 +58,13 @@ class WC_Tests_Reports_Orders_Stats extends WC_Unit_Test_Case {
|
|||
'orders_count' => 1,
|
||||
'num_items_sold' => 4,
|
||||
'avg_items_per_order' => 4,
|
||||
'avg_order_value' => 68,
|
||||
'avg_order_value' => 56,
|
||||
'gross_revenue' => 97,
|
||||
'coupons' => 20,
|
||||
'refunds' => 12,
|
||||
'taxes' => 7,
|
||||
'shipping' => 10,
|
||||
'net_revenue' => 68,
|
||||
'net_revenue' => 56,
|
||||
'num_returning_customers' => 0,
|
||||
'num_new_customers' => 1,
|
||||
'products' => 1,
|
||||
|
@ -79,7 +79,7 @@ class WC_Tests_Reports_Orders_Stats extends WC_Unit_Test_Case {
|
|||
'date_end_gmt' => $end_time,
|
||||
'subtotals' => array(
|
||||
'gross_revenue' => 97,
|
||||
'net_revenue' => 68,
|
||||
'net_revenue' => 56,
|
||||
'coupons' => 20,
|
||||
'shipping' => 10,
|
||||
'taxes' => 7,
|
||||
|
@ -87,7 +87,7 @@ class WC_Tests_Reports_Orders_Stats extends WC_Unit_Test_Case {
|
|||
'orders_count' => 1,
|
||||
'num_items_sold' => 4,
|
||||
'avg_items_per_order' => 4,
|
||||
'avg_order_value' => 68,
|
||||
'avg_order_value' => 56,
|
||||
'num_returning_customers' => 0,
|
||||
'num_new_customers' => 1,
|
||||
'segments' => array(),
|
||||
|
@ -106,8 +106,8 @@ class WC_Tests_Reports_Orders_Stats extends WC_Unit_Test_Case {
|
|||
$query = new WC_Admin_Reports_Orders_Stats_Query( $args );
|
||||
$expected_stats = array(
|
||||
'totals' => array(
|
||||
'net_revenue' => 68,
|
||||
'avg_order_value' => 68,
|
||||
'net_revenue' => 56,
|
||||
'avg_order_value' => 56,
|
||||
'orders_count' => 1,
|
||||
'avg_items_per_order' => 4,
|
||||
'num_items_sold' => 4,
|
||||
|
@ -125,8 +125,8 @@ class WC_Tests_Reports_Orders_Stats extends WC_Unit_Test_Case {
|
|||
'date_end' => $end_time,
|
||||
'date_end_gmt' => $end_time,
|
||||
'subtotals' => array(
|
||||
'net_revenue' => 68,
|
||||
'avg_order_value' => 68,
|
||||
'net_revenue' => 56,
|
||||
'avg_order_value' => 56,
|
||||
'orders_count' => 1,
|
||||
'avg_items_per_order' => 4,
|
||||
'num_items_sold' => 4,
|
||||
|
|
Loading…
Reference in New Issue