Skip to content

Commit 31dc9a8

Browse files
committed
ACP2E-2756: [Cloud] Order Status changed to complete when partially refund of a partially shipped order
- adjusted tests
1 parent b1de35e commit 31dc9a8

File tree

5 files changed

+59
-23
lines changed

5 files changed

+59
-23
lines changed

app/code/Magento/Sales/Controller/Adminhtml/Order/Creditmemo/Save.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ class Save extends \Magento\Backend\App\Action implements HttpPostActionInterfac
1818
*
1919
* @see _isAllowed()
2020
*/
21-
const ADMIN_RESOURCE = 'Magento_Sales::sales_creditmemo';
21+
public const ADMIN_RESOURCE = 'Magento_Sales::sales_creditmemo';
2222

2323
/**
2424
* @var \Magento\Sales\Controller\Adminhtml\Order\CreditmemoLoader
@@ -163,7 +163,7 @@ private function adjustCreditMemoItemQuantities(Creditmemo $creditMemo): void
163163
}
164164
}
165165

166-
foreach($parentQuantities as $parentId => $quantity) {
166+
foreach ($parentQuantities as $parentId => $quantity) {
167167
foreach ($items as $item) {
168168
if ($item->getOrderItemId() == $parentId) {
169169
$item->setQty($quantity);

app/code/Magento/Sales/Model/Order/Item.php

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -24,36 +24,38 @@
2424
*/
2525
class Item extends AbstractModel implements OrderItemInterface
2626
{
27-
const STATUS_PENDING = 1;
27+
public const STATUS_PENDING = 1;
2828

2929
// No items shipped, invoiced, canceled, refunded nor backordered
30-
const STATUS_SHIPPED = 2;
30+
public const STATUS_SHIPPED = 2;
3131

3232
// When qty ordered - [qty canceled + qty returned] = qty shipped
33-
const STATUS_INVOICED = 9;
33+
public const STATUS_INVOICED = 9;
3434

3535
// When qty ordered - [qty canceled + qty returned] = qty invoiced
36-
const STATUS_BACKORDERED = 3;
36+
public const STATUS_BACKORDERED = 3;
3737

3838
// When qty ordered - [qty canceled + qty returned] = qty backordered
39-
const STATUS_CANCELED = 5;
39+
public const STATUS_CANCELED = 5;
4040

4141
// When qty ordered = qty canceled
42-
const STATUS_PARTIAL = 6;
42+
public const STATUS_PARTIAL = 6;
4343

4444
// If [qty shipped or(max of two) qty invoiced + qty canceled + qty returned]
4545
// < qty ordered
46-
const STATUS_MIXED = 7;
46+
public const STATUS_MIXED = 7;
4747

4848
// All other combinations
49-
const STATUS_REFUNDED = 8;
49+
public const STATUS_REFUNDED = 8;
5050

5151
// When qty ordered = qty refunded
52-
const STATUS_RETURNED = 4;
52+
public const STATUS_RETURNED = 4;
5353

54-
// When qty ordered = qty returned // not used at the moment
55-
56-
// When qty ordered = qty returned // not used at the moment
54+
/**
55+
* When qty ordered = qty returned // not used at the moment
56+
*
57+
* @var string
58+
*/
5759
protected $_eventPrefix = 'sales_order_item';
5860

5961
/**

app/code/Magento/Sales/Model/ResourceModel/Order/Handler/State.php

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,16 +21,15 @@ class State
2121
*/
2222
public function check(Order $order)
2323
{
24-
if ($order->isCanceled() && $order->canUnhold() && $order->canInvoice()) {
25-
return $this;
26-
}
27-
2824
$currentState = $order->getState();
2925
if ($this->canBeProcessingStatus($order, $currentState)) {
3026
$order->setState(Order::STATE_PROCESSING)
3127
->setStatus($order->getConfig()->getStateDefaultStatus(Order::STATE_PROCESSING));
3228
$currentState = Order::STATE_PROCESSING;
3329
}
30+
if ($order->isCanceled() && $order->canUnhold() && $order->canInvoice()) {
31+
return $this;
32+
}
3433

3534
if ($this->canBeClosedStatus($order, $currentState)) {
3635
$order->setState(Order::STATE_CLOSED)
@@ -80,6 +79,10 @@ private function canBeClosedStatus(Order $order, string $currentState): bool
8079
return true;
8180
}
8281

82+
if ($order->getIsVirtual() && $order->getStatus() === Order::STATE_CLOSED) {
83+
return true;
84+
}
85+
8386
return false;
8487
}
8588

app/code/Magento/Sales/Test/Unit/Controller/Adminhtml/Order/Creditmemo/SaveTest.php

Lines changed: 34 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
use Magento\Sales\Helper\Data as SalesData;
2828
use Magento\Sales\Model\Order;
2929
use Magento\Sales\Model\Order\Creditmemo;
30+
use Magento\Sales\Model\Order\Creditmemo\Item;
3031
use Magento\Sales\Model\Order\Email\Sender\CreditmemoSender;
3132
use PHPUnit\Framework\MockObject\MockObject;
3233
use PHPUnit\Framework\TestCase;
@@ -210,9 +211,19 @@ public function testSaveActionOnlineRefundToStoreCredit()
210211

211212
$creditmemoMock = $this->createPartialMock(
212213
Creditmemo::class,
213-
['load', 'getGrandTotal']
214+
['load', 'getGrandTotal', 'getAllItems']
214215
);
215216
$creditmemoMock->expects($this->once())->method('getGrandTotal')->willReturn('1');
217+
$orderItem = $this->createMock(Order\Item::class);
218+
$orderItem->expects($this->once())
219+
->method('getParentItemId');
220+
$creditMemoItem = $this->createMock(Item::class);
221+
$creditMemoItem->expects($this->once())
222+
->method('getOrderItem')
223+
->willReturn($orderItem);
224+
$creditmemoMock->expects($this->once())
225+
->method('getAllItems')
226+
->willReturn([$creditMemoItem]);
216227
$this->memoLoaderMock->expects(
217228
$this->once()
218229
)->method(
@@ -258,9 +269,19 @@ public function testSaveActionWithNegativeCreditmemo()
258269

259270
$creditmemoMock = $this->createPartialMock(
260271
Creditmemo::class,
261-
['load', 'isValidGrandTotal']
272+
['load', 'isValidGrandTotal', 'getAllItems']
262273
);
263274
$creditmemoMock->expects($this->once())->method('isValidGrandTotal')->willReturn(false);
275+
$orderItem = $this->createMock(Order\Item::class);
276+
$orderItem->expects($this->once())
277+
->method('getParentItemId');
278+
$creditMemoItem = $this->createMock(Item::class);
279+
$creditMemoItem->expects($this->once())
280+
->method('getOrderItem')
281+
->willReturn($orderItem);
282+
$creditmemoMock->expects($this->once())
283+
->method('getAllItems')
284+
->willReturn([$creditMemoItem]);
264285
$this->memoLoaderMock->expects(
265286
$this->once()
266287
)->method(
@@ -342,7 +363,7 @@ public function testExecuteEmails(
342363

343364
$creditmemo = $this->createPartialMock(
344365
Creditmemo::class,
345-
['isValidGrandTotal', 'getOrder', 'getOrderId']
366+
['isValidGrandTotal', 'getOrder', 'getOrderId', 'getAllItems']
346367
);
347368
$creditmemo->expects($this->once())
348369
->method('isValidGrandTotal')
@@ -353,6 +374,16 @@ public function testExecuteEmails(
353374
$creditmemo->expects($this->once())
354375
->method('getOrderId')
355376
->willReturn($orderId);
377+
$orderItem = $this->createMock(Order\Item::class);
378+
$orderItem->expects($this->once())
379+
->method('getParentItemId');
380+
$creditMemoItem = $this->createMock(Item::class);
381+
$creditMemoItem->expects($this->once())
382+
->method('getOrderItem')
383+
->willReturn($orderItem);
384+
$creditmemo->expects($this->once())
385+
->method('getAllItems')
386+
->willReturn([$creditMemoItem]);
356387

357388
$this->_requestMock->expects($this->any())
358389
->method('getParam')

app/code/Magento/Sales/Test/Unit/Model/Order/ItemTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -321,7 +321,7 @@ public function getItemQtyVariants()
321321
'qty_ordered' => 12, 'qty_invoiced' => 12, 'qty_refunded' => 5, 'qty_shipped' => 4,
322322
'qty_canceled' => 0
323323
],
324-
'expectedResult' => ['to_ship' => 7.0, 'to_invoice' => 0.0]
324+
'expectedResult' => ['to_ship' => 3.0, 'to_invoice' => 0.0]
325325
],
326326
'complete' => [
327327
'options' => [
@@ -342,7 +342,7 @@ public function getItemQtyVariants()
342342
'qty_ordered' => 4.4, 'qty_invoiced' => 0.4, 'qty_refunded' => 0.4, 'qty_shipped' => 4,
343343
'qty_canceled' => 0,
344344
],
345-
'expectedResult' => ['to_ship' => 0.4, 'to_invoice' => 4.0]
345+
'expectedResult' => ['to_ship' => 0.0, 'to_invoice' => 4.0]
346346
],
347347
'completely_invoiced_using_decimals' => [
348348
'options' => [

0 commit comments

Comments
 (0)