Merge pull request #24208 from woocommerce/fix/order-screen-tax-calculation-to-honor-rounding-setting

Honor tax rounding preference in edit item and refund flows
This commit is contained in:
Claudio Sanches 2019-12-05 20:52:48 -03:00 committed by GitHub
commit 5dac360e8a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 3 deletions

View File

@ -383,10 +383,12 @@ jQuery( function ( $ ) {
var unit_total_tax = accounting.unformat( $line_total_tax.attr( 'data-total_tax' ), woocommerce_admin.mon_decimal_point ) / o_qty;
var $line_subtotal_tax = $( 'input.line_subtotal_tax[data-tax_id="' + tax_id + '"]', $row );
var unit_subtotal_tax = accounting.unformat( $line_subtotal_tax.attr( 'data-subtotal_tax' ), woocommerce_admin.mon_decimal_point ) / o_qty;
var round_at_subtotal = 'yes' === woocommerce_admin_meta_boxes.round_at_subtotal;
var precision = woocommerce_admin_meta_boxes[ round_at_subtotal ? 'rounding_precision' : 'currency_format_num_decimals' ];
if ( 0 < unit_total_tax ) {
$line_total_tax.val(
parseFloat( accounting.formatNumber( unit_total_tax * qty, woocommerce_admin_meta_boxes.rounding_precision, '' ) )
parseFloat( accounting.formatNumber( unit_total_tax * qty, precision, '' ) )
.toString()
.replace( '.', woocommerce_admin.mon_decimal_point )
);
@ -394,7 +396,7 @@ jQuery( function ( $ ) {
if ( 0 < unit_subtotal_tax ) {
$line_subtotal_tax.val(
parseFloat( accounting.formatNumber( unit_subtotal_tax * qty, woocommerce_admin_meta_boxes.rounding_precision, '' ) )
parseFloat( accounting.formatNumber( unit_subtotal_tax * qty, precision, '' ) )
.toString()
.replace( '.', woocommerce_admin.mon_decimal_point )
);
@ -1019,8 +1021,11 @@ jQuery( function ( $ ) {
var unit_total_tax = accounting.unformat( line_total_tax.data( 'total_tax' ), woocommerce_admin.mon_decimal_point ) / qty;
if ( 0 < unit_total_tax ) {
var round_at_subtotal = 'yes' === woocommerce_admin_meta_boxes.round_at_subtotal;
var precision = woocommerce_admin_meta_boxes[ round_at_subtotal ? 'rounding_precision' : 'currency_format_num_decimals' ];
$refund_line_total_tax.val(
parseFloat( accounting.formatNumber( unit_total_tax * refund_qty, woocommerce_admin_meta_boxes.rounding_precision, '' ) )
parseFloat( accounting.formatNumber( unit_total_tax * refund_qty, precision, '' ) )
.toString()
.replace( '.', woocommerce_admin.mon_decimal_point )
).change();

View File

@ -115,6 +115,10 @@ $row_class = apply_filters( 'woocommerce_admin_html_order_item_class', ! empt
$tax_item_id = $tax_item->get_rate_id();
$tax_item_total = isset( $tax_data['total'][ $tax_item_id ] ) ? $tax_data['total'][ $tax_item_id ] : '';
$tax_item_subtotal = isset( $tax_data['subtotal'][ $tax_item_id ] ) ? $tax_data['subtotal'][ $tax_item_id ] : '';
$round_at_subtotal = 'yes' === get_option( 'woocommerce_tax_round_at_subtotal' );
$tax_item_total = wc_round_tax_total( $tax_item_total, $round_at_subtotal ? wc_get_rounding_precision() : null );
$tax_item_subtotal = wc_round_tax_total( $tax_item_subtotal, $round_at_subtotal ? wc_get_rounding_precision() : null );
?>
<td class="line_tax" width="1%">
<div class="view">