For Tax configuration, there are two ways to fix this.
In backend configuration:
Apply Customer Tax ->set 'Before Discount'; This should fix your problem I guess.
You can customize the code as well for same :
In your di.xml, add as below:
<preference for="Magento\Tax\Model\Sales\Total\Quote\Tax" type="<yournamespace>\<yourModule>\Model\Sales\Total\Quote\Tax"/>
Now create your class file Tax.php and add below code:
namespace <yournamespace>\<yourModule>\Model\Sales\Total\Quote;
class Tax extends \Magento\Tax\Model\Sales\Total\Quote\Tax
{
public function __construct(
) {
parent::__construct(
);
}
public function collect(
\Magento\Quote\Model\Quote $quote,
\Magento\Quote\Api\Data\ShippingAssignmentInterface $shippingAssignment,
\Magento\Quote\Model\Quote\Address\Total $total
) {
$total->setTaxAmount($set_your_tax_here);
return $this;
}
}
Hope this helps!