Skip to content

Commit a68e58e

Browse files
author
mastiuhin-olexandr
committed
MC-39878: Invoice for an order that contains only one configurable product is not generated correctly
1 parent 1c3837c commit a68e58e

File tree

2 files changed

+67
-7
lines changed

2 files changed

+67
-7
lines changed

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -679,6 +679,11 @@ public function register()
679679
public function isLast()
680680
{
681681
foreach ($this->getAllItems() as $item) {
682+
$orderItem = $item->getOrderItem();
683+
if ($orderItem->isDummy()) {
684+
continue;
685+
}
686+
682687
if (!$item->isLast()) {
683688
return false;
684689
}

dev/tests/integration/testsuite/Magento/Sales/Model/Order/InvoiceTest.php

Lines changed: 62 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,57 @@
33
* Copyright © Magento, Inc. All rights reserved.
44
* See COPYING.txt for license details.
55
*/
6+
declare(strict_types=1);
7+
68
namespace Magento\Sales\Model\Order;
79

8-
class InvoiceTest extends \PHPUnit\Framework\TestCase
10+
use PHPUnit\Framework\TestCase;
11+
use Magento\TestFramework\Helper\Bootstrap;
12+
use Magento\Sales\Model\ResourceModel\Order\Collection as OrderCollection;
13+
use Magento\Sales\Api\InvoiceManagementInterface;
14+
use Magento\Sales\Api\OrderRepositoryInterface;
15+
use Magento\Framework\Api\SearchCriteriaBuilder;
16+
17+
/**
18+
* Invoice model test.
19+
*/
20+
class InvoiceTest extends TestCase
921
{
1022
/**
11-
* @var \Magento\Sales\Model\ResourceModel\Order\Collection
23+
* @var \Magento\Framework\ObjectManagerInterface
24+
*/
25+
private $objectManager;
26+
27+
/**
28+
* @var OrderCollection
29+
*/
30+
private $collection;
31+
32+
/**
33+
* @var InvoiceManagementInterface
34+
*/
35+
private $invoiceManagement;
36+
37+
/**
38+
* @var OrderRepositoryInterface
39+
*/
40+
private $orderRepository;
41+
42+
/**
43+
* @var SearchCriteriaBuilder
1244
*/
13-
private $_collection;
45+
private $searchCriteriaBuilder;
1446

47+
/**
48+
* @inheritDoc
49+
*/
1550
protected function setUp(): void
1651
{
17-
$this->_collection = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(
18-
\Magento\Sales\Model\ResourceModel\Order\Collection::class
19-
);
52+
$this->objectManager = Bootstrap::getObjectManager();
53+
$this->collection = $this->objectManager->create(OrderCollection::class);
54+
$this->invoiceManagement = $this->objectManager->get(InvoiceManagementInterface::class);
55+
$this->orderRepository = $this->objectManager->get(OrderRepositoryInterface::class);
56+
$this->searchCriteriaBuilder = $this->objectManager->get(SearchCriteriaBuilder::class);
2057
}
2158

2259
/**
@@ -27,9 +64,27 @@ public function testOrderTotalItemCount()
2764
$expectedResult = [['total_item_count' => 1]];
2865
$actualResult = [];
2966
/** @var \Magento\Sales\Model\Order $order */
30-
foreach ($this->_collection->getItems() as $order) {
67+
foreach ($this->collection->getItems() as $order) {
3168
$actualResult[] = ['total_item_count' => $order->getData('total_item_count')];
3269
}
3370
$this->assertEquals($expectedResult, $actualResult);
3471
}
72+
73+
/**
74+
* Test order with exactly one configurable.
75+
*
76+
* @return void
77+
* @magentoDataFixture Magento/Sales/_files/order_configurable_product.php
78+
*/
79+
public function testLastInvoiceWithConfigurable(): void
80+
{
81+
$searchCriteria = $this->searchCriteriaBuilder->addFilter('increment_id', '100000001')
82+
->create();
83+
$orders = $this->orderRepository->getList($searchCriteria);
84+
$orders = $orders->getItems();
85+
$order = array_shift($orders);
86+
$invoice = $this->invoiceManagement->prepareInvoice($order);
87+
88+
self::assertEquals($invoice->isLast(), true);
89+
}
3590
}

0 commit comments

Comments
 (0)