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

Feature/avs 421 129 allow tax calc before discount #239

Merged
Merged
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
9 changes: 6 additions & 3 deletions Framework/Interaction/Line.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
15 changes: 15 additions & 0 deletions Helper/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -1075,6 +1077,19 @@ 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
);
}

/**
* Get Shipping Tax Code.
*
Expand Down
9 changes: 9 additions & 0 deletions etc/adminhtml/system.xml
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,15 @@
<field id="filter_tax_by_region">1</field>
</depends>
</field>
<field id="calculate_tax_before_discounts" translate="label" type="select" sortOrder="1008" showInDefault="1" showInWebsite="1" showInStore="1">
<label>Calculate Tax Before Discount</label>
<source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
<comment><![CDATA[Should tax be calculated on each item before discounts are applied ]]></comment>
<depends>
<field id="enabled">1</field>
<field id="tax_mode" negative="1">1</field>
</depends>
</field>
<field id="is_seller_importer_of_record" translate="label comment" type="select" sortOrder="1008" showInDefault="1" showInWebsite="1" showInStore="1">
<label>Set Seller as Importer of Record for Global Transactions</label>
<source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
Expand Down
1 change: 1 addition & 0 deletions etc/config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
<queue_admin_notification_enabled>1</queue_admin_notification_enabled>
<queue_failure_notification_enabled>1</queue_failure_notification_enabled>
<customer_code_format>id</customer_code_format>
<calculate_tax_before_discounts>0</calculate_tax_before_discounts>
</avatax>
</tax>
</default>
Expand Down