I was having the same issue due to UK VAT rules and found several magento bug created on github but no actual fix.
So then while looking for a workaround I have built a module to change the Magento behaviour according to our requirement.
Basically we need to update the definition of mapItem
method of class Magento\Tax\Model\Sales\Total\Quote\CommonTaxCollector
For that we need to override 2 magento classes i.e. write preference in di.xml
<preference for="Magento\Tax\Model\Sales\Total\Quote\CommonTaxCollector" type="VendorName\MagentoChildProductTaxExtend\Preference\Tax\Model\Sales\Total\Quote\CommonTaxCollector"/>
<preference for="Magento\Tax\Model\Sales\Total\Quote\Tax" type="VendorName\MagentoChildProductTaxExtend\Preference\Tax\Model\Sales\Total\Quote\Tax"/>
Now in mapItem
method of class VendorName\MagentoChildProductTaxExtend\Preference\Tax\Model\Sales\Total\Quote\CommonTaxCollector
in line 211, we need to replace the $item->getProduct()->getTaxClassId()
with the child product tax class id.
For that, we can change to these lines of code in our own class -
$taxClassId = $item->getProduct()->getTaxClassId();
if($item->getHasChildren()) {
foreach ($item->getChildren() as $child) {
$taxClassId = $child->getProduct()->getTaxClassId();
}
}
/** @var \Magento\Tax\Api\Data\QuoteDetailsItemInterface $itemDataObject */
$itemDataObject = $itemDataObjectFactory->create();
$itemDataObject->setCode($item->getTaxCalculationItemId())
->setQuantity($item->getQty())
->setTaxClassKey(
$this->taxClassKeyDataObjectFactory->create()
->setType(TaxClassKeyInterface::TYPE_ID)
//->setValue($item->getProduct()->getTaxClassId())
->setValue($taxClassId)
)
->setIsTaxIncluded($priceIncludesTax)
->setType(self::ITEM_TYPE_PRODUCT);
Create your own module and add those codes, this works in every tax related section in magento, Tested on Ver 2.2.2
Cheers!!