Skip to content
This repository was archived by the owner on Apr 22, 2019. It is now read-only.

Commit 45a01c1

Browse files
Merge pull request #239 from classyllama/feature/AVS-421_129-allow-tax-calc-before-discount
Feature/avs 421 129 allow tax calc before discount
2 parents ee7ce2b + 9afd63c commit 45a01c1

File tree

4 files changed

+31
-3
lines changed

4 files changed

+31
-3
lines changed

Framework/Interaction/Line.php

+6-3
Original file line numberDiff line numberDiff line change
@@ -260,9 +260,12 @@ protected function convertTaxQuoteDetailsItemToData(\Magento\Tax\Api\Data\QuoteD
260260
$description = $extensionAttributes ? $extensionAttributes->getAvataxDescription() : '';
261261
$taxCode = $extensionAttributes ? $extensionAttributes->getAvataxTaxCode() : null;
262262

263-
// The AvaTax 15 API doesn't support the concept of line-based discounts, so subtract discount amount
264-
// from taxable amount
265-
$amount = ($item->getUnitPrice() * $quantity) - $item->getDiscountAmount();
263+
// Calculate tax with or without discount based on config setting
264+
if ($this->config->getCalculateTaxBeforeDiscount($item->getStoreId())) {
265+
$amount = $item->getUnitPrice() * $quantity;
266+
} else {
267+
$amount = ($item->getUnitPrice() * $quantity) - $item->getDiscountAmount();
268+
}
266269

267270
$ref1 = $extensionAttributes ? $extensionAttributes->getAvataxRef1() : null;
268271
$ref2 = $extensionAttributes ? $extensionAttributes->getAvataxRef2() : null;

Helper/Config.php

+15
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ class Config extends AbstractHelper
4747

4848
const XML_PATH_AVATAX_REGION_FILTER_LIST = 'tax/avatax/region_filter_list';
4949

50+
const XML_PATH_AVATAX_CALCULATE_BEFORE_DISCOUNT = 'tax/avatax/calculate_tax_before_discounts';
51+
5052
const XML_PATH_AVATAX_LIVE_MODE = 'tax/avatax/live_mode';
5153

5254
const XML_PATH_AVATAX_PRODUCTION_ACCOUNT_NUMBER = 'tax/avatax/production_account_number';
@@ -1075,6 +1077,19 @@ public function isSellerImporterOfRecord($originAddress, $destAddress, $storeId)
10751077
return $isSellerImporterOfRecord;
10761078
}
10771079

1080+
/**
1081+
* @param $store
1082+
* @return mixed
1083+
*/
1084+
public function getCalculateTaxBeforeDiscount($store)
1085+
{
1086+
return $this->scopeConfig->getValue(
1087+
self::XML_PATH_AVATAX_CALCULATE_BEFORE_DISCOUNT,
1088+
ScopeInterface::SCOPE_STORE,
1089+
$store
1090+
);
1091+
}
1092+
10781093
/**
10791094
* Get Shipping Tax Code.
10801095
*

etc/adminhtml/system.xml

+9
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,15 @@
7979
<field id="filter_tax_by_region">1</field>
8080
</depends>
8181
</field>
82+
<field id="calculate_tax_before_discounts" translate="label" type="select" sortOrder="1008" showInDefault="1" showInWebsite="1" showInStore="1">
83+
<label>Calculate Tax Before Discount</label>
84+
<source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
85+
<comment><![CDATA[Should tax be calculated on each item before discounts are applied ]]></comment>
86+
<depends>
87+
<field id="enabled">1</field>
88+
<field id="tax_mode" negative="1">1</field>
89+
</depends>
90+
</field>
8291
<field id="is_seller_importer_of_record" translate="label comment" type="select" sortOrder="1008" showInDefault="1" showInWebsite="1" showInStore="1">
8392
<label>Set Seller as Importer of Record for Global Transactions</label>
8493
<source_model>Magento\Config\Model\Config\Source\Yesno</source_model>

etc/config.xml

+1
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@
5656
<queue_admin_notification_enabled>1</queue_admin_notification_enabled>
5757
<queue_failure_notification_enabled>1</queue_failure_notification_enabled>
5858
<customer_code_format>id</customer_code_format>
59+
<calculate_tax_before_discounts>0</calculate_tax_before_discounts>
5960
</avatax>
6061
</tax>
6162
</default>

0 commit comments

Comments
 (0)