Skip to content

Commit db4e479

Browse files
🔃 [EngCom] Public Pull Requests - 2.2-develop
Accepted Public Pull Requests: - #21944: [Backport] Fixed calculation of 'Total' column under "Last Orders" listing on the admin dashboard (by @eduard13) - #21535: [Backport] Fix Broken Tax Rate Search Filter Admin grid #21521 (by @tuyennn) Fixed GitHub Issues: - #18754: Negative order amount in dashboard latest order when order is cancelled where coupon has been used (reported by @albsa) has been fixed in #21944 by @eduard13 in 2.2-develop branch Related commits: 1. 7d81b55 2. 0cea562 3. 891e2e1 4. a54bba3 - #21281: Wrong order amount on dashboard on Last orders listing when order has discount and it is partially refunded (reported by @rav-redchamps) has been fixed in #21944 by @eduard13 in 2.2-develop branch Related commits: 1. 7d81b55 2. 0cea562 3. 891e2e1 4. a54bba3 - #21521: Broken Tax Rate Search Filter - SQLSTATE[23000] (reported by @robyerevan) has been fixed in #21535 by @tuyennn in 2.2-develop branch Related commits: 1. d935998 2. fb2d354
2 parents 592b86b + 59619bd commit db4e479

File tree

2 files changed

+42
-6
lines changed

2 files changed

+42
-6
lines changed

app/code/Magento/Reports/Model/ResourceModel/Order/Collection.php

Lines changed: 40 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -769,11 +769,12 @@ public function addOrdersCount()
769769
*/
770770
public function addRevenueToSelect($convertCurrency = false)
771771
{
772-
$expr = $this->getTotalsExpression(
772+
$expr = $this->getTotalsExpressionWithDiscountRefunded(
773773
!$convertCurrency,
774774
$this->getConnection()->getIfNullSql('main_table.base_subtotal_refunded', 0),
775775
$this->getConnection()->getIfNullSql('main_table.base_subtotal_canceled', 0),
776-
$this->getConnection()->getIfNullSql('main_table.base_discount_canceled', 0)
776+
$this->getConnection()->getIfNullSql('ABS(main_table.base_discount_refunded)', 0),
777+
$this->getConnection()->getIfNullSql('ABS(main_table.base_discount_canceled)', 0)
777778
);
778779
$this->getSelect()->columns(['revenue' => $expr]);
779780

@@ -791,11 +792,12 @@ public function addSumAvgTotals($storeId = 0)
791792
/**
792793
* calculate average and total amount
793794
*/
794-
$expr = $this->getTotalsExpression(
795+
$expr = $this->getTotalsExpressionWithDiscountRefunded(
795796
$storeId,
796797
$this->getConnection()->getIfNullSql('main_table.base_subtotal_refunded', 0),
797798
$this->getConnection()->getIfNullSql('main_table.base_subtotal_canceled', 0),
798-
$this->getConnection()->getIfNullSql('main_table.base_discount_canceled', 0)
799+
$this->getConnection()->getIfNullSql('ABS(main_table.base_discount_refunded)', 0),
800+
$this->getConnection()->getIfNullSql('ABS(main_table.base_discount_canceled)', 0)
799801
);
800802

801803
$this->getSelect()->columns(
@@ -808,13 +810,15 @@ public function addSumAvgTotals($storeId = 0)
808810
}
809811

810812
/**
811-
* Get SQL expression for totals
813+
* Get SQL expression for totals.
812814
*
813815
* @param int $storeId
814816
* @param string $baseSubtotalRefunded
815817
* @param string $baseSubtotalCanceled
816818
* @param string $baseDiscountCanceled
817819
* @return string
820+
* @deprecated
821+
* @see getTotalsExpressionWithDiscountRefunded
818822
*/
819823
protected function getTotalsExpression(
820824
$storeId,
@@ -825,10 +829,40 @@ protected function getTotalsExpression(
825829
$template = ($storeId != 0)
826830
? '(main_table.base_subtotal - %2$s - %1$s - ABS(main_table.base_discount_amount) - %3$s)'
827831
: '((main_table.base_subtotal - %1$s - %2$s - ABS(main_table.base_discount_amount) + %3$s) '
828-
. ' * main_table.base_to_global_rate)';
832+
. ' * main_table.base_to_global_rate)';
829833
return sprintf($template, $baseSubtotalRefunded, $baseSubtotalCanceled, $baseDiscountCanceled);
830834
}
831835

836+
/**
837+
* Get SQL expression for totals with discount refunded.
838+
*
839+
* @param int $storeId
840+
* @param string $baseSubtotalRefunded
841+
* @param string $baseSubtotalCanceled
842+
* @param string $baseDiscountRefunded
843+
* @param string $baseDiscountCanceled
844+
* @return string
845+
*/
846+
private function getTotalsExpressionWithDiscountRefunded(
847+
$storeId,
848+
$baseSubtotalRefunded,
849+
$baseSubtotalCanceled,
850+
$baseDiscountRefunded,
851+
$baseDiscountCanceled
852+
) {
853+
$template = ($storeId != 0)
854+
? '(main_table.base_subtotal - %2$s - %1$s - (ABS(main_table.base_discount_amount) - %3$s - %4$s))'
855+
: '((main_table.base_subtotal - %1$s - %2$s - (ABS(main_table.base_discount_amount) - %3$s - %4$s)) '
856+
. ' * main_table.base_to_global_rate)';
857+
return sprintf(
858+
$template,
859+
$baseSubtotalRefunded,
860+
$baseSubtotalCanceled,
861+
$baseDiscountRefunded,
862+
$baseDiscountCanceled
863+
);
864+
}
865+
832866
/**
833867
* Sort order by total amount
834868
*

app/code/Magento/Tax/etc/di.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,7 @@
143143
<arguments>
144144
<argument name="fieldMapping" xsi:type="array">
145145
<item name="id" xsi:type="string">tax_calculation_rule_id</item>
146+
<item name="code" xsi:type="string">main_table.code</item>
146147
<item name="tax_rate_ids" xsi:type="string">tax_calculation_rate_id</item>
147148
<item name="customer_tax_class_ids" xsi:type="string">cd.customer_tax_class_id</item>
148149
<item name="product_tax_class_ids" xsi:type="string">cd.product_tax_class_id</item>
@@ -154,6 +155,7 @@
154155
<arguments>
155156
<argument name="fieldMapping" xsi:type="array">
156157
<item name="id" xsi:type="string">tax_calculation_rule_id</item>
158+
<item name="code" xsi:type="string">main_table.code</item>
157159
<item name="tax_rate_ids" xsi:type="string">tax_calculation_rate_id</item>
158160
<item name="customer_tax_class_ids" xsi:type="string">cd.customer_tax_class_id</item>
159161
<item name="product_tax_class_ids" xsi:type="string">cd.product_tax_class_id</item>

0 commit comments

Comments
 (0)