Skip to content
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

[ECP-9225] Use Magento_Tax module to build open invoice line items #2651

Open
wants to merge 60 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
60 commits
Select commit Hold shift + click to select a range
202b339
deprecate tax calculation methods and rely on Magento_Weee module to …
RokPopov Jun 7, 2024
3852ec3
Merge branch 'main' into ECP-9225
RokPopov Jul 3, 2024
77d8c6b
fix unit tests
RokPopov Jul 4, 2024
07d8bdb
Merge branch 'main' into ECP-9225
RokPopov Jul 4, 2024
2f0447e
set magento_weee version
RokPopov Jul 5, 2024
0931f1e
fix open invoice unit tests
RokPopov Jul 5, 2024
395709e
add area code to magento installation script for CI/CD pipeline
RokPopov Jul 5, 2024
10c3ebe
fix code sniffer issue
RokPopov Jul 5, 2024
2285397
add verbose output to debug pipeline workflows
RokPopov Jul 5, 2024
d837f56
capture errors directly
RokPopov Jul 5, 2024
39425f8
add verbose output to plugin installation
RokPopov Jul 5, 2024
f2e7d34
debugging makefile
RokPopov Jul 5, 2024
27a2cdd
output stack trace directly
RokPopov Jul 5, 2024
151e76c
verbose output in setup:upgrade command
RokPopov Jul 5, 2024
c8d622b
debug makefile
RokPopov Jul 5, 2024
576051f
debug 2 makefile
RokPopov Jul 5, 2024
40cfa44
more verbose outputs
RokPopov Jul 5, 2024
2f1d264
run n98-magerun command as www-data user
RokPopov Jul 5, 2024
0b2c12e
debug 3
RokPopov Jul 5, 2024
5498b2d
debug 4
RokPopov Jul 5, 2024
6a9231f
debug 5
RokPopov Jul 5, 2024
f629ad7
debug 6
RokPopov Jul 5, 2024
2013f6f
debug 6
RokPopov Jul 5, 2024
ff84c91
add area code to EnablePaymentMethodsCommand
RokPopov Jul 9, 2024
d0a6b57
Merge branch 'main' into ECP-9225
RokPopov Jul 9, 2024
d3f3b9e
fix enable payment methods command tests
RokPopov Jul 9, 2024
a3574ca
set area when calling cli upgrade script
RokPopov Jul 9, 2024
12b96f8
try to fix area issue in ci/cd pipeline
RokPopov Jul 9, 2024
aeaec39
Merge branch 'main' into ECP-9225
RokPopov Jul 10, 2024
80c6557
CI/CD debugging
RokPopov Jul 10, 2024
ba31221
remove area code setup command from magento installation
RokPopov Jul 10, 2024
d40d756
add state to custom webhook processor command, fix unit test
RokPopov Jul 10, 2024
02f3ba7
debug pipeline
RokPopov Jul 10, 2024
94707a7
fix unit test
RokPopov Jul 10, 2024
509d182
debug functional tests
RokPopov Jul 10, 2024
ba3ffae
add custom console command to set the area code and include it before…
RokPopov Jul 10, 2024
4ef944f
replicate restapi workflow magento installation into mftf workflow
RokPopov Jul 11, 2024
4407b74
remove redundant console command class and change steps in mftf workf…
RokPopov Jul 11, 2024
98a0bc5
remove unused console command from di.xml
RokPopov Jul 11, 2024
1064653
change order of processes in mftf.yml
RokPopov Jul 11, 2024
c18aa54
flush the cache before running install
RokPopov Jul 11, 2024
a84e7f5
copy rest api tests into mftf tests to check if install step will fail
RokPopov Jul 11, 2024
2c75b48
remove mftf specific container to check the result of the workflow
RokPopov Jul 11, 2024
7a903c8
mirror restapi tests completely
RokPopov Jul 12, 2024
80cf3c5
execute on pull request on main
RokPopov Jul 12, 2024
4ebd605
add mftf container
RokPopov Jul 12, 2024
7a3aa70
enable mftf tests to run
RokPopov Jul 12, 2024
0b4c63e
temporarily comment out mftf part of the workflow
RokPopov Jul 12, 2024
835634e
enable mftf part again
RokPopov Jul 12, 2024
8a53218
Merge branch 'main' into ECP-9225
RokPopov Jul 12, 2024
f0689f3
Merge branch 'main' into ECP-9225
candemiralp Jan 8, 2025
417a3cb
[ECP-9225] Revert workflow related changes
Jan 8, 2025
66da533
[ECP-9225] Use Magento_Tax module instead of Magento_Weee
Jan 8, 2025
82d7c4f
[ECP-9225] Replace Weee module import
Jan 8, 2025
1ef5b68
[ECP-9225] Use factory to load Renderer class
Jan 8, 2025
48d37c9
[ECP-9225] Fix unit test
Jan 8, 2025
ce71f32
[ECP-9225] Fix unit test
Jan 8, 2025
68dd837
[ECP-9225] Remove unused variable
Jan 8, 2025
a6dd6ea
[ECP-9225] Fix unit tests
Jan 8, 2025
1627983
Merge branch 'main' into ECP-9225
candemiralp Jan 8, 2025
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
60 changes: 23 additions & 37 deletions Helper/ChargedCurrency.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
use Magento\Sales\Model\Order;
use Magento\Sales\Model\Order\Invoice;
use Magento\Sales\Api\Data\CreditmemoItemInterface;
use Magento\Tax\Block\Item\Price\RendererFactory;

class ChargedCurrency
{
Expand All @@ -26,16 +27,10 @@ class ChargedCurrency
*/
const BASE = "base";

/**
* @var Config
*/
private $config;

public function __construct(
Config $config
) {
$this->config = $config;
}
private readonly Config $config,
private readonly RendererFactory $priceRendererFactory
) { }

/**
* @param Order $order
Expand All @@ -44,7 +39,7 @@ public function __construct(
*
* @return AdyenAmountCurrency
*/
public function getOrderAmountCurrency(Order $order, bool $orderPlacement = true)
public function getOrderAmountCurrency(Order $order, bool $orderPlacement = true): AdyenAmountCurrency
{
$chargedCurrency = $orderPlacement
? $this->config->getChargedCurrency($order->getStoreId())
Expand All @@ -71,7 +66,7 @@ public function getOrderAmountCurrency(Order $order, bool $orderPlacement = true
* @param Quote $quote
* @return AdyenAmountCurrency
*/
public function getQuoteAmountCurrency(Quote $quote)
public function getQuoteAmountCurrency(Quote $quote): AdyenAmountCurrency
{
$chargedCurrency = $this->config->getChargedCurrency($quote->getStoreId());
if ($chargedCurrency == self::BASE) {
Expand All @@ -83,6 +78,7 @@ public function getQuoteAmountCurrency(Quote $quote)
public function getQuoteItemAmountCurrency(Quote\Item $item): AdyenAmountCurrency
{
$chargedCurrency = $this->config->getChargedCurrency($item->getStoreId());
$priceRenderer = $this->priceRendererFactory->create();

if ($chargedCurrency == self::BASE) {
return new AdyenAmountCurrency(
Expand All @@ -91,8 +87,7 @@ public function getQuoteItemAmountCurrency(Quote\Item $item): AdyenAmountCurrenc
$item->getBaseDiscountAmount() / $item->getQty(),
$item->getBaseTaxAmount() / $item->getQty(),
null,
$item->getBaseRowTotalInclTax() / $item->getQty(),
$item->getBaseDiscountTaxCompensationAmount() / $item->getQty()
$priceRenderer->getBaseTotalAmount($item) / $item->getQty()
);
}

Expand All @@ -102,14 +97,14 @@ public function getQuoteItemAmountCurrency(Quote\Item $item): AdyenAmountCurrenc
$item->getDiscountAmount() / $item->getQty(),
$item->getTaxAmount() / $item->getQty(),
null,
$item->getRowTotalInclTax() / $item->getQty(),
$item->getDiscountTaxCompensationAmount() / $item->getQty()
$priceRenderer->getTotalAmount($item) / $item->getQty()
);
}

public function getInvoiceItemAmountCurrency(Invoice\Item $item): AdyenAmountCurrency
{
$chargedCurrency = $item->getInvoice()->getOrder()->getAdyenChargedCurrency();
$priceRenderer = $this->priceRendererFactory->create();

if ($chargedCurrency == self::BASE) {
return new AdyenAmountCurrency(
Expand All @@ -118,8 +113,7 @@ public function getInvoiceItemAmountCurrency(Invoice\Item $item): AdyenAmountCur
$item->getBaseDiscountAmount() / $item->getQty(),
$item->getBaseTaxAmount() / $item->getQty(),
null,
$item->getBaseRowTotalInclTax() / $item->getQty(),
$item->getBaseDiscountTaxCompensationAmount() / $item->getQty()
$priceRenderer->getBaseTotalAmount($item)
);
}

Expand All @@ -129,16 +123,15 @@ public function getInvoiceItemAmountCurrency(Invoice\Item $item): AdyenAmountCur
$item->getDiscountAmount() / $item->getQty(),
$item->getTaxAmount() / $item->getQty(),
null,
$item->getRowTotalInclTax() / $item->getQty(),
$item->getDiscountTaxCompensationAmount() / $item->getQty()
$priceRenderer->getTotalAmount($item)
);
}

/**
* @param CreditmemoInterface $creditMemo
* @return AdyenAmountCurrency
*/
public function getCreditMemoAmountCurrency(CreditmemoInterface $creditMemo)
public function getCreditMemoAmountCurrency(CreditmemoInterface $creditMemo): AdyenAmountCurrency
{
$chargedCurrency = $creditMemo->getOrder()->getAdyenChargedCurrency();
if ($chargedCurrency == self::BASE) {
Expand All @@ -162,7 +155,7 @@ public function getCreditMemoAmountCurrency(CreditmemoInterface $creditMemo)
* @param CreditmemoInterface $creditMemo
* @return AdyenAmountCurrency
*/
public function getCreditMemoAdjustmentAmountCurrency(CreditmemoInterface $creditMemo)
public function getCreditMemoAdjustmentAmountCurrency(CreditmemoInterface $creditMemo): AdyenAmountCurrency
{
$chargedCurrency = $creditMemo->getOrder()->getAdyenChargedCurrency();
if ($chargedCurrency == self::BASE) {
Expand All @@ -188,8 +181,7 @@ public function getCreditMemoShippingAmountCurrency(CreditmemoInterface $creditM
null,
$creditMemo->getBaseShippingTaxAmount(),
null,
$creditMemo->getBaseShippingInclTax(),
$creditMemo->getBaseShippingDiscountTaxCompensationAmnt()
$creditMemo->getBaseShippingInclTax()
);
}
return new AdyenAmountCurrency(
Expand All @@ -198,14 +190,14 @@ public function getCreditMemoShippingAmountCurrency(CreditmemoInterface $creditM
null,
$creditMemo->getShippingTaxAmount(),
null,
$creditMemo->getShippingInclTax(),
$creditMemo->getShippingDiscountTaxCompensationAmount()
$creditMemo->getShippingInclTax()
);
}

public function getCreditMemoItemAmountCurrency(CreditmemoItemInterface $item): AdyenAmountCurrency
{
$chargedCurrency = $item->getCreditMemo()->getOrder()->getAdyenChargedCurrency();
$priceRenderer = $this->priceRendererFactory->create();

if ($chargedCurrency == self::BASE) {
return new AdyenAmountCurrency(
Expand All @@ -214,8 +206,7 @@ public function getCreditMemoItemAmountCurrency(CreditmemoItemInterface $item):
$item->getBaseDiscountAmount() / $item->getQty(),
$item->getBaseTaxAmount() / $item->getQty(),
null,
$item->getBaseRowTotalInclTax() / $item->getQty(),
$item->getBaseDiscountTaxCompensationAmount() / $item->getQty()
$priceRenderer->getBaseTotalAmount($item)
);
}
return new AdyenAmountCurrency(
Expand All @@ -224,8 +215,7 @@ public function getCreditMemoItemAmountCurrency(CreditmemoItemInterface $item):
$item->getDiscountAmount() / $item->getQty(),
$item->getTaxAmount() / $item->getQty(),
null,
$item->getRowTotalInclTax() / $item->getQty(),
$item->getDiscountTaxCompensationAmount() / $item->getQty()
$priceRenderer->getTotalAmount($item)
);
}

Expand All @@ -240,8 +230,7 @@ public function getQuoteShippingAmountCurrency(Quote $quote): AdyenAmountCurrenc
$quote->getShippingAddress()->getBaseShippingDiscountAmount(),
$quote->getShippingAddress()->getBaseShippingTaxAmount(),
null,
$quote->getShippingAddress()->getBaseShippingInclTax(),
$quote->getShippingAddress()->getBaseShippingDiscountTaxCompensationAmnt()
$quote->getShippingAddress()->getBaseShippingInclTax()
);
}

Expand All @@ -251,8 +240,7 @@ public function getQuoteShippingAmountCurrency(Quote $quote): AdyenAmountCurrenc
$quote->getShippingAddress()->getShippingDiscountAmount(),
$quote->getShippingAddress()->getShippingTaxAmount(),
null,
$quote->getShippingAddress()->getShippingInclTax(),
$quote->getShippingAddress()->getShippingDiscountTaxCompensationAmount()
$quote->getShippingAddress()->getShippingInclTax()
);
}

Expand All @@ -267,8 +255,7 @@ public function getInvoiceShippingAmountCurrency(Invoice $invoice): AdyenAmountC
null,
$invoice->getBaseShippingTaxAmount(),
null,
$invoice->getBaseShippingInclTax(),
$invoice->getBaseShippingDiscountTaxCompensationAmnt()
$invoice->getBaseShippingInclTax()
);
}

Expand All @@ -278,8 +265,7 @@ public function getInvoiceShippingAmountCurrency(Invoice $invoice): AdyenAmountC
null,
$invoice->getShippingTaxAmount(),
null,
$invoice->getShippingInclTax(),
$invoice->getShippingDiscountTaxCompensationAmount()
$invoice->getShippingInclTax()
);
}

Expand Down
25 changes: 6 additions & 19 deletions Helper/OpenInvoice.php
Original file line number Diff line number Diff line change
Expand Up @@ -142,42 +142,28 @@ protected function formatShippingLineItem(
): array {
$currency = $shippingAmount->getCurrencyCode();

$formattedPriceExcludingTax = $this->adyenHelper->formatAmount(
$shippingAmount->getAmountWithDiscount(),
$currency
);
$formattedPriceIncludingTax = $this->adyenHelper->formatAmount(
$shippingAmount->getAmountIncludingTaxWithDiscount(),
$shippingAmount->getAmountIncludingTax(),
$currency
);

$formattedTaxAmount = $this->adyenHelper->formatAmount($shippingAmount->getTaxAmount(), $currency);
$formattedTaxPercentage = $this->adyenHelper->formatAmount(
$shippingAmount->getCalculatedTaxPercentage(),
$currency
);

return [
'id' => 'shippingCost',
'amountExcludingTax' => $formattedPriceExcludingTax,
'amountIncludingTax' => $formattedPriceIncludingTax,
'taxAmount' => $formattedTaxAmount,
'description' => $shippingDescription,
'quantity' => 1,
'taxPercentage' => $formattedTaxPercentage
'quantity' => 1
];
}

protected function formatLineItem(AdyenAmountCurrency $itemAmountCurrency, $item, $qty = null): array
{
$currency = $itemAmountCurrency->getCurrencyCode();

$formattedPriceExcludingTax = $this->adyenHelper->formatAmount(
$itemAmountCurrency->getAmountWithDiscount(),
$currency
);
$formattedPriceIncludingTax = $this->adyenHelper->formatAmount(
$itemAmountCurrency->getAmountIncludingTaxWithDiscount(),
$itemAmountCurrency->getAmountIncludingTax(),
$currency
);

Expand All @@ -188,7 +174,6 @@ protected function formatLineItem(AdyenAmountCurrency $itemAmountCurrency, $item

return [
'id' => $product ? $product->getId() : $item->getProductId(),
'amountExcludingTax' => $formattedPriceExcludingTax,
'amountIncludingTax' => $formattedPriceIncludingTax,
'taxAmount' => $formattedTaxAmount,
'description' => $item->getName(),
Expand All @@ -199,6 +184,9 @@ protected function formatLineItem(AdyenAmountCurrency $itemAmountCurrency, $item
];
}

/**
* @deprecated
*/
protected function formatInvoiceDiscount(
mixed $discountAmount, $shippingDiscountAmount, AdyenAmountCurrency $itemAmountCurrency
): array
Expand All @@ -210,7 +198,6 @@ protected function formatInvoiceDiscount(

return [
'id' => 'Discount',
'amountExcludingTax' => $itemAmount,
'amountIncludingTax' => $itemAmount,
'taxAmount' => 0,
'description' => $description,
Expand Down
15 changes: 15 additions & 0 deletions Model/AdyenAmountCurrency.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ class AdyenAmountCurrency

protected $amountDue;

/**
* @deprecated
*/
protected $discountTaxCompensationAmount;

public function __construct(
Expand Down Expand Up @@ -75,11 +78,17 @@ public function getAmountDue()
return $this->amountDue;
}

/**
* @deprecated
*/
public function getDiscountTaxCompensationAmount()
{
return $this->discountTaxCompensationAmount;
}

/**
* @deprecated
*/
public function getAmountIncludingTaxWithDiscount()
{
if ($this->getDiscountTaxCompensationAmount() > 0) {
Expand All @@ -90,11 +99,17 @@ public function getAmountIncludingTaxWithDiscount()
}
}

/**
* @deprecated
*/
public function getAmountWithDiscount()
{
return $this->getAmount() - $this->getDiscountAmount() + $this->getDiscountTaxCompensationAmount();
}

/**
* @deprecated
*/
public function getCalculatedTaxPercentage()
{
if ($this->getAmountWithDiscount() > 0) {
Expand Down
Loading
Loading