fix tax rate rounding

This commit is contained in:
Steffen Mahler 2020-03-30 19:30:10 +02:00
parent 6de80fff2f
commit c13ae36494
2 changed files with 9 additions and 4 deletions

View File

@ -7,7 +7,7 @@ class Tax
/**
* @var int
*/
public const TAX_PRECISION = 4;
private const TAX_PRECISION = 2;
/**
* Returns an array with tax rates and tax amount
@ -29,6 +29,11 @@ class Tax
$taxes[$taxRate] += $asBase ? $item->base_tax_amount : $item->tax_amount;
}
// finaly round tax amounts now (to reduce rounding differences)
foreach ($taxes as $taxRate => $taxAmount) {
$taxes[$taxRate] = round($taxAmount, self::TAX_PRECISION);
}
return $taxes;
}
@ -45,7 +50,7 @@ class Tax
$result = 0;
foreach ($taxes as $taxRate => $taxAmount) {
$result += round($taxAmount, 2);
$result += $taxAmount;
}
return $result;

View File

@ -72,10 +72,10 @@ class TaxCest
$this->scenario = [
'object' => Cart::getCart(),
'expectedTaxRates' => [
(string)round((float)$tax1->tax_rate, \Webkul\Tax\Helpers\Tax::TAX_PRECISION)
(string)round((float)$tax1->tax_rate, 4)
=> round(11 * $product1->price * $tax1->tax_rate / 100, 4),
(string)round((float)$tax2->tax_rate, \Webkul\Tax\Helpers\Tax::TAX_PRECISION)
(string)round((float)$tax2->tax_rate, 4)
=> round(7 * $product2->price * $tax2->tax_rate / 100, 4),
],
'expectedTaxTotal' =>