Skip to content

Issue/33352 #35700

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: 2.4-develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 12 additions & 8 deletions app/code/Magento/Tax/Model/Calculation/UnitBaseCalculator.php
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ protected function calculateWithTaxNotInPrice(QuoteDetailsItemInterface $item, $
$appliedRates = $this->calculationTool->getAppliedRates($taxRateRequest);

$applyTaxAfterDiscount = $this->config->applyTaxAfterDiscount($this->storeId);
$applyTaxRounding = $this->config->applyTaxRounding($this->storeId);
$discountAmount = $item->getDiscountAmount();
$discountTaxCompensationAmount = 0;

Expand Down Expand Up @@ -164,14 +165,17 @@ protected function calculateWithTaxNotInPrice(QuoteDetailsItemInterface $item, $
false,
false
);
$unitTaxAfterDiscount = $this->roundAmount(
$unitTaxAfterDiscount,
$taxId,
false,
self::KEY_REGULAR_DELTA_ROUNDING,
$round,
$item
);

if ($applyTaxRounding) {
$unitTaxAfterDiscount = $this->roundAmount(
$unitTaxAfterDiscount,
$taxId,
false,
self::KEY_REGULAR_DELTA_ROUNDING,
$round,
$item
);
}
}
$appliedTaxes[$taxId] = $this->getAppliedTax(
$unitTaxAfterDiscount * $quantity,
Expand Down
17 changes: 17 additions & 0 deletions app/code/Magento/Tax/Model/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ class Config

public const CONFIG_XML_PATH_APPLY_ON = 'tax/calculation/apply_tax_on';

public const CONFIG_XML_PATH_APPLY_TAX_ROUNDING = 'tax/calculation/apply_tax_rounding';

public const CONFIG_XML_PATH_APPLY_AFTER_DISCOUNT = 'tax/calculation/apply_after_discount';

public const CONFIG_XML_PATH_DISCOUNT_TAX = 'tax/calculation/discount_tax';
Expand Down Expand Up @@ -210,6 +212,21 @@ public function applyTaxAfterDiscount($store = null)
);
}

/**
* Get configuration setting "Apply Tax Rounding" value
*
* @param null|string|bool|int|Store $store
* @return bool
*/
public function applyTaxRounding($store = null)
{
return (bool) $this->_scopeConfig->getValue(
self::CONFIG_XML_PATH_APPLY_TAX_ROUNDING,
\Magento\Store\Model\ScopeInterface::SCOPE_STORE,
$store
);
}

/**
* Get product price display type
* 1 - Excluding tax
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,10 @@ public function testCalculateWithTaxNotInPrice()
->method('applyTaxAfterDiscount')
->willReturn(true);

$this->mockConfig->expects($this->once())
->method('applyTaxRounding')
->willReturn(true);

$this->mockCalculationTool->expects($this->once())
->method('getRate')
->with($this->addressRateRequest)
Expand Down
6 changes: 6 additions & 0 deletions app/code/Magento/Tax/Test/Unit/Model/ConfigTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,12 @@ public function dataProviderScopeConfigMethods(): array
true,
true
],
[
'applyTaxRounding',
Config::CONFIG_XML_PATH_APPLY_TAX_ROUNDING,
true,
true
],
[
'getPriceDisplayType',
Config::CONFIG_XML_PATH_PRICE_DISPLAY_TYPE,
Expand Down
5 changes: 5 additions & 0 deletions app/code/Magento/Tax/etc/adminhtml/system.xml
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,11 @@
<source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
<comment>When catalog price includes tax, enable this setting to fix the price no matter what the customer's tax rate.</comment>
</field>
<field id="apply_tax_rounding" translate="label comment" type="select" sortOrder="80" showInDefault="1" showInWebsite="1">
<label>Apply Tax Rounding</label>
<source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
<comment>When catalog price includes tax, enable this setting to round tax amount.</comment>
</field>
</group>
<group id="defaults" translate="label" sortOrder="30" showInDefault="1" showInWebsite="1" showInStore="1">
<label>Default Tax Destination Calculation</label>
Expand Down
1 change: 1 addition & 0 deletions app/code/Magento/Tax/etc/config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
<price_includes_tax>0</price_includes_tax>
<shipping_includes_tax>0</shipping_includes_tax>
<apply_tax_on>0</apply_tax_on>
<apply_tax_rounding>1</apply_tax_rounding>
</calculation>
<defaults>
<country>US</country>
Expand Down