From 801fd1efc80996e5b14f04a773aeda17f7e9a998 Mon Sep 17 00:00:00 2001 From: Preston Choate Date: Fri, 25 Jan 2019 14:32:57 -0600 Subject: [PATCH 1/2] AVS-421-129 - Add config value for calculating tax before or after discounts. Add helper method to access new config value. Refactored TaxLine class to check for new config value to calculate line amount. --- Framework/Interaction/Line.php | 9 ++++++--- Helper/Config.php | 15 +++++++++++++++ etc/adminhtml/system.xml | 9 +++++++++ 3 files changed, 30 insertions(+), 3 deletions(-) diff --git a/Framework/Interaction/Line.php b/Framework/Interaction/Line.php index 7c0a37dc..4314f82e 100644 --- a/Framework/Interaction/Line.php +++ b/Framework/Interaction/Line.php @@ -260,9 +260,12 @@ protected function convertTaxQuoteDetailsItemToData(\Magento\Tax\Api\Data\QuoteD $description = $extensionAttributes ? $extensionAttributes->getAvataxDescription() : ''; $taxCode = $extensionAttributes ? $extensionAttributes->getAvataxTaxCode() : null; - // The AvaTax 15 API doesn't support the concept of line-based discounts, so subtract discount amount - // from taxable amount - $amount = ($item->getUnitPrice() * $quantity) - $item->getDiscountAmount(); + // Calculate tax with or without discount based on config setting + if ($this->config->getCalculateTaxBeforeDiscount($item->getStoreId())) { + $amount = $item->getUnitPrice() * $quantity; + } else { + $amount = ($item->getUnitPrice() * $quantity) - $item->getDiscountAmount(); + } $ref1 = $extensionAttributes ? $extensionAttributes->getAvataxRef1() : null; $ref2 = $extensionAttributes ? $extensionAttributes->getAvataxRef2() : null; diff --git a/Helper/Config.php b/Helper/Config.php index b0841199..d43a0266 100644 --- a/Helper/Config.php +++ b/Helper/Config.php @@ -47,6 +47,8 @@ class Config extends AbstractHelper const XML_PATH_AVATAX_REGION_FILTER_LIST = 'tax/avatax/region_filter_list'; + const XML_PATH_AVATAX_CALCULATE_BEFORE_DISCOUNT = 'tax/avatax/calculate_tax_before_discounts'; + const XML_PATH_AVATAX_LIVE_MODE = 'tax/avatax/live_mode'; const XML_PATH_AVATAX_PRODUCTION_ACCOUNT_NUMBER = 'tax/avatax/production_account_number'; @@ -1072,4 +1074,17 @@ public function isSellerImporterOfRecord($originAddress, $destAddress, $storeId) } return $isSellerImporterOfRecord; } + + /** + * @param $store + * @return mixed + */ + public function getCalculateTaxBeforeDiscount($store) + { + return $this->scopeConfig->getValue( + self::XML_PATH_AVATAX_CALCULATE_BEFORE_DISCOUNT, + ScopeInterface::SCOPE_STORE, + $store + ); + } } diff --git a/etc/adminhtml/system.xml b/etc/adminhtml/system.xml index 4a0a6980..81499381 100644 --- a/etc/adminhtml/system.xml +++ b/etc/adminhtml/system.xml @@ -79,6 +79,15 @@ 1 + + + Magento\Config\Model\Config\Source\Yesno + + + 1 + 1 + + Magento\Config\Model\Config\Source\Yesno From 9afd63cc30870068a5f9deac43db3c9b4ca8da72 Mon Sep 17 00:00:00 2001 From: Preston Choate Date: Fri, 22 Feb 2019 14:36:37 -0600 Subject: [PATCH 2/2] AVS-421_129 - Added default value for new calculate tax before discounts config field --- etc/config.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/etc/config.xml b/etc/config.xml index 96fdf069..f09ce01f 100644 --- a/etc/config.xml +++ b/etc/config.xml @@ -56,6 +56,7 @@ 1 1 id + 0