8

我在 Magento 中遇到了增值税的奇怪四舍五入问题。我的产品设置是 * 含 20% 增值税的产品价格是 183.59

我在购物篮中添加了 30 件商品,成本为 30 * 183.59 = 5507.70。我可以在购物篮/结帐中看到这个值,这很好。如果我的篮子里只有 1 件商品,那没关系。

最终增值税也是 5507.70 * 20 / 120 = 917.95,但我得到 918.00

你知道如何解决这个问题或者我去哪里看看吗?提前致谢。

4

2 回答 2

11

最后我找到了解决方案。我将 System > VAT > Tax Calculation Method Based on 从 Unit price 更改为 Row Total 并且它有效,更多详细信息在这里

我发现的问题在core/store模型中。我不得不重写roundPrice方法并在那里改变舍入精度。

public function roundPrice($price)
{
   return round($price, 4);
}
于 2012-11-23T13:40:24.070 回答
6

信息

Magento 中基于先前舍入操作 delta 的舍入价格。

app/code/core/Mage/Tax/Model/Sales/Total/Quote/Tax.php:1392 app/code/core/Mage/Tax/Model/Sales/Total/Quote/Subtotal.php:719

protected function _deltaRound($price, $rate, $direction, $type = 'regular')
{
    if ($price) {
        $rate = (string)$rate;
        $type = $type . $direction;
        // initialize the delta to a small number to avoid non-deterministic behavior with rounding of 0.5
        $delta = isset($this->_roundingDeltas[$type][$rate]) ? $this->_roundingDeltas[$type][$rate] : 0.000001;
        $price += $delta;
        $this->_roundingDeltas[$type][$rate] = $price - $this->_calculator->round($price);
        $price = $this->_calculator->round($price);
    }
    return $price;
}

有时,由于高增量计算错误 ( $this->_calculator->round($price)),这可能会导致错误。例如,出于这个原因,某些价格可能会在±1 美分的范围内变化。

解决方案

为避免这种情况,您需要提高增量计算的准确性。

改变

$this->_roundingDeltas[$type][$rate] = $price - $this->_calculator->round($price);

$this->_roundingDeltas[$type][$rate] = $price - round($price, 4);

需要在两个文件中进行更改:

app/code/core/Mage/Tax/Model/Sales/Total/Quote/Tax.php:1392 app/code/core/Mage/Tax/Model/Sales/Total/Quote/Subtotal.php:719

不要修改或破解核心文件!重写!

该解决方案在不同版本的 Magento 1.9.x 上进行了测试,但也许这将在早期版本中工作。

附言

改变roundPrice函数,如下图,可以解决舍入误差问题,但会导致其他问题(例如,某些平台要求四舍五入到小数点后两位)。

app/code/core/Mage/Core/Model/Store.php:995

public function roundPrice($price)
{
    return round($price, 4);
}
于 2018-01-30T14:47:46.737 回答