是否可以部分退款来退税?


8

在发出贷项通知单(也称为退款)时,Magento会自动退还运输和产品税,但不退还在“调整退款”字段中输入的值(也称为部分退款)。

是否可以配置Magento,使其对调整退款字段中输入的值自动退税?

参考: 在此处输入图片说明

Answers:


3

您将在该类中找到处理此问题的代码Mage_Sales_Model_Order_Creditmemo_Total_Tax

该行代码$part = $creditmemo->getShippingAmount()/$orderShippingAmount;(位于第116行)清楚地表明,这是经过专门编码的,仅用于根据creditMemo表单中的shippingAmount字段计算税款。

明显的变化是将代码调整为也使用“调整退款”字段。

由于magento如何在creditmemo计算中将其实例化为Totals Collector子系统的一部分,因此您实际上无法重写此类。

但是,您可以调整收集器以使用您自己的类的版本,因此不会丢失所有内容。

因此,在您自己的模块中,将以下代码放置在config.xml中。它进入<global>元素内部

<global>
    <sales>
      <order_creditmemo>
         <totals>
            <tax>
              <class>NAMESPACE_MODULE/order_creditmemo_total_tax</class>
              <after>subtotal</after>
            </tax>
         </totals>
      </order_creditmemo>
   </sales>
<global>

现在,您将创建类文件NAMESPACE/MODULE/Model/Order/Creditmemo/Total/Tax,该文件扩展了核心文件。

class NAMESPACE_MODULE_Model_Order_Creditmemo_Total_Tax extends Mage_Sales_Model_Order_Creditmemo_Total_Tax

您将需要将核心类的整个`collect'方法复制到新文件中。

在第114行添加以下代码(紧随该代码之后$shippingDelta = $baseOrderShippingAmount - $baseOrderShippingRefundedAmount

 /** adjust to also calculate tax on the adjustment value **/
            $adjustment = ($creditmemo->getAdjustment() > 0)?$creditmemo->getAdjustment():$creditmemo->getShippingAmount();
            if($creditmemo->getAdjustment() > 0 && $creditmemo->getShippingAmount() > 0) {
                $adjustment = $creditmemo->getAdjustment() + $creditmemo->getShippingAmount();
            }
            /** end adjustment **/

并将线116从调整$part = $creditmemo->getShippingAmount()/$orderShippingAmount;$part = $adjustment/$orderShippingAmount;

然后,这将有效地在计算中使用“装运金额”或“调整金额”。


谢谢!但是,如果我理解正确,那么这仅在存在运输成本的情况下有效。没有运费将无法正常工作。
西蒙(Simon)

6

实质性的问题是,magento不知道要使用哪个税收因素。如果没有可退款的产品,则没有税率。

我只是使用我可以在产品中找到的最高税率来解决此问题,请随时根据您的用例进行调整。

该税是在课程结束时在calculateTaxForRefundAdjustment中计算的。

config.xml

<?xml version="1.0"?>
<config>
    <modules>
        <Project_RefundPartialCreditmemoWithTax>
            <version>1.0.0</version>
        </Project_RefundPartialCreditmemoWithTax>
    </modules>
    <global>
        <models>
            <project_refundpartialcreditmemowithtax>
                 <class>Project_RefundPartialCreditmemoWithTax_Model</class>
            </project_refundpartialcreditmemowithtax>
        </models>
        <sales>
          <order_creditmemo>
             <totals>
                <tax>
                  <class>project_refundpartialcreditmemowithtax/order_creditmemo_total_tax</class>
                </tax>
             </totals>
          </order_creditmemo>
       </sales>
    </global>
</config>

app / code / local / Project / RefundPartialCreditmemoWithTax / Model / Order / Creditmemo / Total / Tax.php

<?php

class Project_RefundPartialCreditmemoWithTax_Model_Order_Creditmemo_Total_Tax
    extends Mage_Sales_Model_Order_Creditmemo_Total_Tax
{
    public function collect(Mage_Sales_Model_Order_Creditmemo $creditmemo)
    {
        $shippingTaxAmount = 0;
        $baseShippingTaxAmount = 0;
        $totalHiddenTax = 0;
        $baseTotalHiddenTax = 0;

        $order = $creditmemo->getOrder();

        list($totalTax, $baseTotalTax) = $this->calculateTaxForRefundAdjustment($creditmemo);

        /** @var $item Mage_Sales_Model_Order_Creditmemo_Item */
        foreach ($creditmemo->getAllItems() as $item) {
            $orderItem = $item->getOrderItem();
            if ($orderItem->isDummy()) {
                continue;
            }
            $orderItemTax = $orderItem->getTaxInvoiced();
            $baseOrderItemTax = $orderItem->getBaseTaxInvoiced();
            $orderItemHiddenTax = $orderItem->getHiddenTaxInvoiced();
            $baseOrderItemHiddenTax = $orderItem->getBaseHiddenTaxInvoiced();
            $orderItemQty = $orderItem->getQtyInvoiced();

            if (($orderItemTax || $orderItemHiddenTax) && $orderItemQty) {
                /**
                 * Check item tax amount
                 */

                $tax = $orderItemTax - $orderItem->getTaxRefunded();
                $baseTax = $baseOrderItemTax - $orderItem->getTaxRefunded();
                $hiddenTax = $orderItemHiddenTax - $orderItem->getHiddenTaxRefunded();
                $baseHiddenTax = $baseOrderItemHiddenTax - $orderItem->getBaseHiddenTaxRefunded();
                if (!$item->isLast()) {
                    $availableQty = $orderItemQty - $orderItem->getQtyRefunded();
                    $tax = $creditmemo->roundPrice($tax / $availableQty * $item->getQty());
                    $baseTax = $creditmemo->roundPrice($baseTax / $availableQty * $item->getQty(), 'base');
                    $hiddenTax = $creditmemo->roundPrice($hiddenTax / $availableQty * $item->getQty());
                    $baseHiddenTax = $creditmemo->roundPrice($baseHiddenTax / $availableQty * $item->getQty(), 'base');
                }

                $item->setTaxAmount($tax);
                $item->setBaseTaxAmount($baseTax);
                $item->setHiddenTaxAmount($hiddenTax);
                $item->setBaseHiddenTaxAmount($baseHiddenTax);

                $totalTax += $tax;
                $baseTotalTax += $baseTax;
                $totalHiddenTax += $hiddenTax;
                $baseTotalHiddenTax += $baseHiddenTax;
            }
        }

        $invoice = $creditmemo->getInvoice();

        if ($invoice) {
            //recalculate tax amounts in case if refund shipping value was changed
            if ($order->getBaseShippingAmount() && $creditmemo->getBaseShippingAmount()) {
                $taxFactor = $creditmemo->getBaseShippingAmount() / $order->getBaseShippingAmount();
                $shippingTaxAmount = $invoice->getShippingTaxAmount() * $taxFactor;
                $baseShippingTaxAmount = $invoice->getBaseShippingTaxAmount() * $taxFactor;
                $totalHiddenTax += $invoice->getShippingHiddenTaxAmount() * $taxFactor;
                $baseTotalHiddenTax += $invoice->getBaseShippingHiddenTaxAmount() * $taxFactor;
                $shippingTaxAmount = $creditmemo->roundPrice($shippingTaxAmount);
                $baseShippingTaxAmount = $creditmemo->roundPrice($baseShippingTaxAmount, 'base');
                $totalHiddenTax = $creditmemo->roundPrice($totalHiddenTax);
                $baseTotalHiddenTax = $creditmemo->roundPrice($baseTotalHiddenTax, 'base');
                $totalTax += $shippingTaxAmount;
                $baseTotalTax += $baseShippingTaxAmount;
            }
        } else {
            $orderShippingAmount = $order->getShippingAmount();
            $baseOrderShippingAmount = $order->getBaseShippingAmount();

            $baseOrderShippingRefundedAmount = $order->getBaseShippingRefunded();

            $shippingTaxAmount = 0;
            $baseShippingTaxAmount = 0;
            $shippingHiddenTaxAmount = 0;
            $baseShippingHiddenTaxAmount = 0;

            $shippingDelta = $baseOrderShippingAmount - $baseOrderShippingRefundedAmount;

            if ($shippingDelta > $creditmemo->getBaseShippingAmount()) {
                $part = $creditmemo->getShippingAmount() / $orderShippingAmount;
                $basePart = $creditmemo->getBaseShippingAmount() / $baseOrderShippingAmount;
                $shippingTaxAmount = $order->getShippingTaxAmount() * $part;
                $baseShippingTaxAmount = $order->getBaseShippingTaxAmount() * $basePart;
                $shippingHiddenTaxAmount = $order->getShippingHiddenTaxAmount() * $part;
                $baseShippingHiddenTaxAmount = $order->getBaseShippingHiddenTaxAmount() * $basePart;
                $shippingTaxAmount = $creditmemo->roundPrice($shippingTaxAmount);
                $baseShippingTaxAmount = $creditmemo->roundPrice($baseShippingTaxAmount, 'base');
                $shippingHiddenTaxAmount = $creditmemo->roundPrice($shippingHiddenTaxAmount);
                $baseShippingHiddenTaxAmount = $creditmemo->roundPrice($baseShippingHiddenTaxAmount, 'base');
            } elseif ($shippingDelta == $creditmemo->getBaseShippingAmount()) {
                $shippingTaxAmount = $order->getShippingTaxAmount() - $order->getShippingTaxRefunded();
                $baseShippingTaxAmount = $order->getBaseShippingTaxAmount() - $order->getBaseShippingTaxRefunded();
                $shippingHiddenTaxAmount = $order->getShippingHiddenTaxAmount()
                    - $order->getShippingHiddenTaxRefunded();
                $baseShippingHiddenTaxAmount = $order->getBaseShippingHiddenTaxAmount()
                    - $order->getBaseShippingHiddenTaxRefunded();
            }
            $totalTax += $shippingTaxAmount;
            $baseTotalTax += $baseShippingTaxAmount;
            $totalHiddenTax += $shippingHiddenTaxAmount;
            $baseTotalHiddenTax += $baseShippingHiddenTaxAmount;
        }

        $allowedTax = $order->getTaxInvoiced() - $order->getTaxRefunded() - $creditmemo->getTaxAmount();
        $allowedBaseTax = $order->getBaseTaxInvoiced() - $order->getBaseTaxRefunded()
            - $creditmemo->getBaseTaxAmount();
        $allowedHiddenTax = $order->getHiddenTaxInvoiced() + $order->getShippingHiddenTaxAmount()
            - $order->getHiddenTaxRefunded() - $order->getShippingHiddenTaxRefunded();
        $allowedBaseHiddenTax = $order->getBaseHiddenTaxInvoiced() + $order->getBaseShippingHiddenTaxAmount()
            - $order->getBaseHiddenTaxRefunded() - $order->getBaseShippingHiddenTaxRefunded();


        $totalTax = min($allowedTax, $totalTax);
        $baseTotalTax = min($allowedBaseTax, $baseTotalTax);
        $totalHiddenTax = min($allowedHiddenTax, $totalHiddenTax);
        $baseTotalHiddenTax = min($allowedBaseHiddenTax, $baseTotalHiddenTax);

        $creditmemo->setTaxAmount($creditmemo->getTaxAmount() + $totalTax);
        $creditmemo->setBaseTaxAmount($creditmemo->getBaseTaxAmount() + $baseTotalTax);
        $creditmemo->setHiddenTaxAmount($totalHiddenTax);
        $creditmemo->setBaseHiddenTaxAmount($baseTotalHiddenTax);

        $creditmemo->setShippingTaxAmount($shippingTaxAmount);
        $creditmemo->setBaseShippingTaxAmount($baseShippingTaxAmount);

        $creditmemo->setGrandTotal($creditmemo->getGrandTotal() + $totalTax + $totalHiddenTax);
        $creditmemo->setBaseGrandTotal($creditmemo->getBaseGrandTotal() + $baseTotalTax + $baseTotalHiddenTax);
        return $this;
    }

    /**
     * @param Mage_Sales_Model_Order_Creditmemo $creditmemo
     * @return array
     */
    private function calculateTaxForRefundAdjustment(Mage_Sales_Model_Order_Creditmemo $creditmemo)
    {
        /** @var Mage_Sales_Model_Resource_Order_Item_Collection $orderItems */
        $orderItems = $creditmemo->getOrder()->getItemsCollection();
        $taxPercentage = 0;
        foreach ($orderItems as $item) {
            $taxPercentage = max($taxPercentage, $item->getTaxPercent() / 100);
        }

        $totalAdjustment = $creditmemo->getAdjustmentPositive() - $creditmemo->getAdjustmentNegative();
        $baseTotalAdjustment = $creditmemo->getBaseAdjustmentPositive() - $creditmemo->getBaseAdjustmentNegative();

        // Adjustment values already include tax in my case. Modify calculation if you're entering values without tax
        $totalAdjustmentTax = $totalAdjustment / ($taxPercentage + 1) * $taxPercentage;
        $baseTotalAdjustmentTax = $baseTotalAdjustment / ($taxPercentage + 1) * $taxPercentage;

        $creditmemo->setGrandTotal($creditmemo->getGrandTotal() - $totalAdjustmentTax);
        $creditmemo->setBaseGrandTotal($creditmemo->getBaseGrandTotal() - $baseTotalAdjustmentTax);

        return [$totalAdjustmentTax, $baseTotalAdjustmentTax];
    }
}

我可以确认这比最近的Magento版本(1.9.xx)可接受的答案更好。
大安范登伯格

@Fabian,您的解决方案很好,但是为什么要更新贷项凭证小计?,好像我不退还任何产品和运费,而是通过“调整退款”退款了一些金额,那么它显示了从调整退款金额到小计的税额。
Yogita

没有。该代码不包含“小计”
Fabian Blechschmidt

@FabianBlechschmidt,您是对的,该代码不包含小计,但我的使用方式-我没有退还运费或物品,因此我的小计最初为$ 0.00,我仅退款“ Adjustment Refund”。贷项凭单生成后,当我打开该视图以查看时,它将以小计显示税额,但小计应为零,因为我没有退还任何项目。我的系统包括 税和我退还$ 10.00的裁决退款($ 0.65税)。然后向我显示小计= $ 0.65调整退款= $ 10.00总计Incl。不含税= $ 10.00不含税= $ 0.65 税费= $ 9.35为什么小计为零?
Yogita

请打开一个新问题,描述您做了什么,发生了什么以及期望得到什么。
Fabian Blechschmidt

0

由于明天缺少回复且赏金到期,因此我的解决方法如下:

输入Adjustment Refund含税的。

请注意注释中的细分,以供您参考和供客户参考。

By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.