diff --git a/intaro.retailcrm/classes/general/history/RetailCrmHistory_v5.php b/intaro.retailcrm/classes/general/history/RetailCrmHistory_v5.php index 5ff4aabe..5563f16f 100644 --- a/intaro.retailcrm/classes/general/history/RetailCrmHistory_v5.php +++ b/intaro.retailcrm/classes/general/history/RetailCrmHistory_v5.php @@ -1734,7 +1734,7 @@ class RetailCrmHistory $basket = $order->getBasket(); foreach ($shipmentCollection as $shipment) { - if (!$shipment->isSystem()) { + if (!$shipment->isSystem() && !$shipment->isShipped()) { $reserved = false; if ($shipment->needReservation()) { diff --git a/tests/classes/general/history/RetailCrmHistory_v5Test.php b/tests/classes/general/history/RetailCrmHistory_v5Test.php index a27e6063..d97e785c 100644 --- a/tests/classes/general/history/RetailCrmHistory_v5Test.php +++ b/tests/classes/general/history/RetailCrmHistory_v5Test.php @@ -1,5 +1,6 @@ createMock(\Bitrix\Sale\ShipmentCollection::class); + $shipmentCollection->method('resetCollection') + ->willReturn(true); + $shipmentCollection->method('tryUnreserve') + ->willReturn(true); + $shipmentCollection->method('tryReserve') + ->willReturn(true); + + $shipment = $this->createMock(\Bitrix\Sale\Shipment::class); + $shipment->method('getShipmentItemCollection') + ->willReturn($shipmentCollection); + $shipment->method('needReservation') + ->willReturn(true); + $shipment->method('isShipped') + ->willReturn(true); + $shipment->method('isSystem') + ->willReturn(false); + + $shipmentCollection->method('getIterator') + ->willReturn(new \ArrayObject([$shipment])); + + $order = $this->createMock(\Bitrix\Sale\Order::class); + $order->method('getShipmentCollection') + ->willReturn($shipmentCollection); + $order->method('getBasket') + ->willReturn(true); + + $this->assertEquals(null, RetailCrmHistory::shipmentItemReset($order)); + + $shipment->method('isShipped') + ->willReturn(false); + + $this->assertEquals(null, RetailCrmHistory::shipmentItemReset($order)); + } + private function getCustomers(): array { return [