This commit is contained in:
Albert Juhé Lluveras 2019-03-15 21:44:03 +01:00 committed by GitHub
parent fae447014f
commit e6cf40e3f0
4 changed files with 64 additions and 6 deletions

View File

@ -32,8 +32,7 @@ export default class TaxesReportTable extends Component {
return [ return [
{ {
label: __( 'Tax Code', 'woocommerce-admin' ), label: __( 'Tax Code', 'woocommerce-admin' ),
// @todo It should be the tax code, not the ID key: 'tax_code',
key: 'tax_rate_id',
required: true, required: true,
isLeftAligned: true, isLeftAligned: true,
isSortable: true, isSortable: true,
@ -72,19 +71,20 @@ export default class TaxesReportTable extends Component {
getRowsContent( taxes ) { getRowsContent( taxes ) {
return map( taxes, tax => { return map( taxes, tax => {
const { order_tax, orders_count, tax_rate, tax_rate_id, total_tax, shipping_tax } = tax; const { order_tax, orders_count, tax_rate, total_tax, shipping_tax } = tax;
const taxCode = getTaxCode( tax );
// @todo Must link to the tax detail report // @todo Must link to the tax detail report
const taxLink = ( const taxLink = (
<Link href="" type="wc-admin"> <Link href="" type="wc-admin">
{ getTaxCode( tax ) } { taxCode }
</Link> </Link>
); );
return [ return [
{ {
display: taxLink, display: taxLink,
value: tax_rate_id, value: taxCode,
}, },
{ {
display: tax_rate.toFixed( 2 ) + '%', display: tax_rate.toFixed( 2 ) + '%',

View File

@ -264,6 +264,7 @@ class WC_Admin_REST_Reports_Taxes_Controller extends WC_REST_Reports_Controller
'enum' => array( 'enum' => array(
'name', 'name',
'tax_rate_id', 'tax_rate_id',
'tax_code',
'rate', 'rate',
'order_tax', 'order_tax',
'total_tax', 'total_tax',

View File

@ -295,7 +295,9 @@ class WC_Admin_Reports_Taxes_Data_Store extends WC_Admin_Reports_Data_Store impl
protected function normalize_order_by( $order_by ) { protected function normalize_order_by( $order_by ) {
global $wpdb; global $wpdb;
if ( 'rate' === $order_by ) { if ( 'tax_code' === $order_by ) {
return 'CONCAT_WS( "-", NULLIF(tax_rate_country, ""), NULLIF(tax_rate_state, ""), NULLIF(tax_rate_name, ""), NULLIF(tax_rate_priority, "") )';
} else if ( 'rate' === $order_by ) {
return "CAST({$wpdb->prefix}woocommerce_tax_rates.tax_rate as DECIMAL(7,4))"; return "CAST({$wpdb->prefix}woocommerce_tax_rates.tax_rate as DECIMAL(7,4))";
} }

View File

@ -269,6 +269,61 @@ class WC_Tests_API_Reports_Taxes extends WC_REST_Unit_Test_Case {
$this->assertEquals( 10, $reports[1]['tax_rate'] ); $this->assertEquals( 10, $reports[1]['tax_rate'] );
} }
/**
* Test getting reports with param `orderby=tax_code`.
*
* @since 3.5.0
*/
public function test_get_reports_orderby_tax_code() {
global $wpdb;
wp_set_current_user( $this->user );
WC_Helper_Reports::reset_stats_dbs();
$wpdb->insert(
$wpdb->prefix . 'woocommerce_tax_rates',
array(
'tax_rate_id' => 1,
'tax_rate' => '7',
'tax_rate_country' => 'US',
'tax_rate_state' => 'GA',
'tax_rate_name' => 'TestTax',
'tax_rate_priority' => 1,
'tax_rate_order' => 1,
)
);
$wpdb->insert(
$wpdb->prefix . 'woocommerce_tax_rates',
array(
'tax_rate_id' => 2,
'tax_rate' => '10',
'tax_rate_country' => 'CA',
'tax_rate_state' => 'ON',
'tax_rate_name' => 'TestTax 2',
'tax_rate_priority' => 1,
'tax_rate_order' => 1,
)
);
$request = new WP_REST_Request( 'GET', $this->endpoint );
$request->set_query_params(
array(
'order' => 'asc',
'orderby' => 'tax_code',
'taxes' => '1,2',
)
);
$response = $this->server->dispatch( $request );
$reports = $response->get_data();
$this->assertEquals( 200, $response->get_status() );
$this->assertEquals( 2, count( $reports ) );
$this->assertEquals( 2, $reports[0]['tax_rate_id'] );
$this->assertEquals( 1, $reports[1]['tax_rate_id'] );
}
/** /**
* Test getting reports without valid permissions. * Test getting reports without valid permissions.
* *