data-migration-tool icon indicating copy to clipboard operation
data-migration-tool copied to clipboard

Tax rate information missing

Open fooman opened this issue 6 years ago • 3 comments

Preconditions

  1. Migrate Magento 1.9.4.2 to Magento 2.3.2 (settings and data)

Steps to reproduce

  1. in Magento 1 place order with a taxed item
  2. Enable setting Systems > Configuration > Tax > Orders, Invoices > Display Full Tax Summary
  3. Migrate settings and data

Expected result

  1. In Magento 1 the specific applied tax rate is shown but is missing from Magento 2 image image

Actual result

  1. see above

Additional notes

This seems to be intended behaviour?! as the values are simply zeroed out here https://github.com/magento/data-migration-tool/blob/2.3.2/etc/opensource-to-opensource/1.9.4.2/map.xml.dist#L1882

The values are available in the source database. The below seems to work for me using a custom handler:

            <transform>
                <field>sales_order_tax_item.real_base_amount</field>
                <handler class="\Fooman\Migration\Handler\FieldCopyFromSeparateTableHandler">
                    <param name="tableFrom" value="sales_order_item" />
                    <param name="fieldCopy" value="base_tax_amount" />
                    <param name="commonIdField" value="item_id" />
                    <param name="fieldCopyTo" value="real_base_amount" />
                </handler>
            </transform>

for each of the 4 fields real_base_amount, real_amount, base_amount and amount with base and real being the same (which works in most cases where there is only 1 tax rate applied - see https://github.com/magento/magento2/blob/2.3.2/app/code/Magento/Tax/Model/Plugin/OrderSave.php#L95.

The handler looks like this

<?php

namespace Fooman\Migration\Handler;

use Migration\ResourceModel\Record;
use Migration\Handler\AbstractHandler;
use Migration\ResourceModel\Destination;

class FieldCopyFromSeparateTableHandler extends AbstractHandler
{
    protected $destinationAdapter;
    protected $destination;

    private $tableFrom;
    private $fieldCopy;
    private $fieldCopyTo;
    private $commonIdField;

    /**
     * @param Destination $destination
     * @param             $tableFrom
     * @param             $fieldCopy
     * @param             $fieldCopyTo
     */
    public function __construct(Destination $destination, $tableFrom, $fieldCopy, $fieldCopyTo, $commonIdField)
    {
        $this->destination = $destination;
        $this->destinationAdapter = $destination->getAdapter();
        $this->tableFrom = $tableFrom;
        $this->commonIdField = $commonIdField;
        $this->fieldCopy = $fieldCopy;
        $this->fieldCopyTo = $fieldCopyTo;
    }

    public function handle(Record $recordToHandle, Record $oppositeRecord)
    {
        $this->validate($recordToHandle);
        $fieldCopyValue = $this->getOppFieldValue($recordToHandle->getValue($this->commonIdField)) ;
        $oppositeRecord->setValue($this->fieldCopyTo, $fieldCopyValue);
    }

    public function getOppFieldValue($id)
    {
        /** @var \Magento\Framework\DB\Select $select */
        $select = $this->destinationAdapter->getSelect();
        $select->from(['opp' => $this->destination->addDocumentPrefix($this->tableFrom)], [])
               ->where('opp.'.$this->commonIdField.'=?', $id);
        $select->columns([$this->fieldCopy]);
        return $select->getAdapter()->fetchOne($select);
    }
}

and results in image

fooman avatar Jul 21 '19 22:07 fooman

Hi @fooman

Thank you for reporting and fixing this issue! Internal ticket MC-18494 to process it.

victor-v-rad avatar Jul 23 '19 16:07 victor-v-rad

Thanks @victor-v-rad - just to note the solution that I posted would likely not work for jurisdictions that apply multiple tax rates on the same item (Canada comes to mind). But at least for most other cases this change would improve status quo.

fooman avatar Jul 23 '19 23:07 fooman

Thank you @fooman . It will be taken into account.

victor-v-rad avatar Jul 24 '19 19:07 victor-v-rad