马根托:发票总额的税务计算不正确


Magento: Incorrect tax calculation on invoice totals

我正在运行Magento 1.5.1.0,过去在发票总额的税务计算方面遇到问题。虽然我的商店中的所有总额的计算都是正确的,但后端发票视图和pdf发票会显示不正确的总额。

错误的显示值和正确的值之间的差异可以在这张图片上看到:(简短版本:小计将包括运输税,尽管运输税已经包含在运输中)http://i731.photobucket.com/albums/ww318/vitamin6/orderview_fixed.jpg

所以我在freestyle.com上发布了这个问题,有人设法解决了它。但正如我后来发现的那样,这个解决方案并不能涵盖所有情况——如果订单是免费送货的,发票小计仍然不正确。以下是显示差异的屏幕截图:http://i731.photobucket.com/albums/ww318/vitamin6/orderview_freeship.jpg

自由职业者编辑了以下文件以修复错误的税务计算:app''code''local''Mage''Sales''Model''Order''Invoice''Total''Subtotal.php

在那里有以下代码:

    if ($invoice->isLast()) {
        $subtotal = $allowedSubtotal;
        $baseSubtotal = $baseAllowedSubtotal;
        $subtotalInclTax = $allowedSubtotalInclTax;
        $baseSubtotalInclTax  = $baseAllowedSubtotalInclTax;

被替换为:

    if ($invoice->isLast()) {
        $subtotal = $allowedSubtotal;
        $baseSubtotal = $baseAllowedSubtotal;
        //$subtotalInclTax = $allowedSubtotalInclTax;
        //$baseSubtotalInclTax  = $baseAllowedSubtotalInclTax;
        $subtotalInclTax = min($allowedSubtotalInclTax, $subtotalInclTax);
        $baseSubtotalInclTax = min($baseAllowedSubtotalInclTax, $baseSubtotalInclTax);

有人能给我指一个正确的方向吗?我必须如何进一步修改文件,以使免费送货的订单能够修复?如果需要,可以提供有关税务设置等的更多详细信息-提前感谢!

汇总排序有一个错误,可能会导致非常严重的问题。

您有添加总计的模块吗?

看看这个:https://stackoverflow.com/a/11954867/288568

这是很久以前的事了,对我来说,这个问题通过一个magento更新得到了解决(我现在使用的是1.8.1.0)。我浏览了我的旧文件,我能找到的只有这个编辑:

app''code''core''Mage''Sales''Model''Order''Invoice''Total''Subtotom.php(取自1.7.0.2)

<?php /**  * Magento  *  * NOTICE OF LICENSE  *  * This source file is subject to the Open Software License (OSL 3.0)  * that is bundled with this package in the file LICENSE.txt.  * It is also available through the world-wide-web at this URL:  * http://opensource.org/licenses/osl-3.0.php  * If you did not receive a copy of the license and are unable to  * obtain it through the world-wide-web, please send an email  * to license@magentocommerce.com so we can send you a copy immediately.  *  * DISCLAIMER  *  * Do not edit or add to this file if you wish to upgrade Magento to newer  * versions in the future. If you wish to customize Magento for your  * needs please refer to http://www.magentocommerce.com for more information.  *  * @category    Mage  * @package     Mage_Sales  * @copyright   Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)  * @license     http://opensource.org/licenses/osl-3.0.php  Open Software License (OSL
3.0)  */

class Mage_Sales_Model_Order_Invoice_Total_Subtotal extends Mage_Sales_Model_Order_Invoice_Total_Abstract {
    /**
     * Collect invoice subtotal
     *
     * @param   Mage_Sales_Model_Order_Invoice $invoice
     * @return  Mage_Sales_Model_Order_Invoice_Total_Subtotal
     */
    public function collect(Mage_Sales_Model_Order_Invoice $invoice)
    {
        $subtotal       = 0;
        $baseSubtotal   = 0;
        $subtotalInclTax= 0;
        $baseSubtotalInclTax = 0;
        $order = $invoice->getOrder();
        foreach ($invoice->getAllItems() as $item) {
            if ($item->getOrderItem()->isDummy()) {
                continue;
            }
            $item->calcRowTotal();
            $subtotal       += $item->getRowTotal();
            $baseSubtotal   += $item->getBaseRowTotal();
            $subtotalInclTax+= $item->getRowTotalInclTax();
            $baseSubtotalInclTax += $item->getBaseRowTotalInclTax();
        }
        $allowedSubtotal = $order->getSubtotal() - $order->getSubtotalInvoiced();
        $baseAllowedSubtotal = $order->getBaseSubtotal() - $order->getBaseSubtotalInvoiced();
        $allowedSubtotalInclTax = $allowedSubtotal + $order->getHiddenTaxAmount()
                + $order->getTaxAmount() - $order->getTaxInvoiced() - $order->getHiddenTaxInvoiced();
        $baseAllowedSubtotalInclTax = $baseAllowedSubtotal + $order->getBaseHiddenTaxAmount()
                + $order->getBaseTaxAmount() - $order->getBaseTaxInvoiced() - $order->getBaseHiddenTaxInvoiced();
        /**
         * Check if shipping tax calculation is included to current invoice.
         */
        $includeShippingTax = true;
        foreach ($invoice->getOrder()->getInvoiceCollection() as $previousInvoice) {
            if ($previousInvoice->getShippingAmount() && !$previousInvoice->isCanceled()) {
                $includeShippingTax = false;
                break;
            }
        }
        if ($includeShippingTax) {
            $allowedSubtotalInclTax     -= $order->getShippingTaxAmount();
            $baseAllowedSubtotalInclTax -= $order->getBaseShippingTaxAmount();
        } else {
            $allowedSubtotalInclTax     += $order->getShippingHiddenTaxAmount();
            $baseAllowedSubtotalInclTax += $order->getBaseShippingHiddenTaxAmount();
        }
        if ($invoice->isLast()) {
            $subtotal = $allowedSubtotal;
            $baseSubtotal = $baseAllowedSubtotal;
            $subtotalInclTax = $allowedSubtotalInclTax;
            $baseSubtotalInclTax  = $baseAllowedSubtotalInclTax;
        } else {
            $subtotal = min($allowedSubtotal, $subtotal);
            $baseSubtotal = min($baseAllowedSubtotal, $baseSubtotal);
            $subtotalInclTax = min($allowedSubtotalInclTax, $subtotalInclTax);
            $baseSubtotalInclTax = min($baseAllowedSubtotalInclTax, $baseSubtotalInclTax);
        }
        $invoice->setSubtotal($subtotal);
        $invoice->setBaseSubtotal($baseSubtotal);
        $invoice->setSubtotalInclTax($subtotalInclTax);
        $invoice->setBaseSubtotalInclTax($baseSubtotalInclTax);
        $invoice->setGrandTotal($invoice->getGrandTotal() + $subtotal);
        $invoice->setBaseGrandTotal($invoice->getBaseGrandTotal() + $baseSubtotal);
        return $this;
    } }