Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
4 changes: 2 additions & 2 deletions app/code/Magento/Sales/Model/Order/Item.php
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ public function getQtyToShip()
public function getSimpleQtyToShip()
{
$qty = $this->getQtyOrdered() - $this->getQtyShipped() - $this->getQtyRefunded() - $this->getQtyCanceled();
return max($qty, 0);
return max(round($qty, 8), 0);
}

/**
Expand All @@ -248,7 +248,7 @@ public function getQtyToInvoice()
}

$qty = $this->getQtyOrdered() - $this->getQtyInvoiced() - $this->getQtyCanceled();
return max($qty, 0);
return max(round($qty, 8), 0);
}

/**
Expand Down
110 changes: 110 additions & 0 deletions app/code/Magento/Sales/Test/Unit/Model/Order/ItemTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -235,4 +235,114 @@ public function getProductOptionsDataProvider()
]
];
}

/**
* Test different combinations of item qty setups
*
* @param array $options
* @param float $expectedResult
*
* @dataProvider getItemQtyVariants
*/
public function testGetSimpleQtyToMethods(array $options, $expectedResult)
{
$this->model->setData($options);
$this->assertSame($this->model->getSimpleQtyToShip(), $expectedResult['to_ship']);
$this->assertSame($this->model->getQtyToInvoice(), $expectedResult['to_invoice']);
}

/**
* Provides different combinations of qty options for an item and the
* expected qtys pending shipment and invoice
*
* @return array
*/
public function getItemQtyVariants()
{
return [
'empty_item' => [
'options' => [
'qty_ordered' => 0, 'qty_invoiced' => 0, 'qty_refunded' => 0, 'qty_shipped' => 0,
'qty_canceled' => 0
],
'expectedResult' => ['to_ship' => 0.0, 'to_invoice' => 0.0]
],
'ordered_item' => [
'options' => [
'qty_ordered' => 12, 'qty_invoiced' => 0, 'qty_refunded' => 0, 'qty_shipped' => 0,
'qty_canceled' => 0
],
'expectedResult' => ['to_ship' => 12.0, 'to_invoice' => 12.0]
],
'partially_invoiced' => [
'options' => ['qty_ordered' => 12, 'qty_invoiced' => 4, 'qty_refunded' => 0, 'qty_shipped' => 0,
'qty_canceled' => 0,
],
'expectedResult' => ['to_ship' => 12.0, 'to_invoice' => 8.0]
],
'completely_invoiced' => [
'options' => [
'qty_ordered' => 12, 'qty_invoiced' => 12, 'qty_refunded' => 0, 'qty_shipped' => 0,
'qty_canceled' => 0,
],
'expectedResult' => ['to_ship' => 12.0, 'to_invoice' => 0.0]
],
'partially_invoiced_refunded' => [
'options' => [
'qty_ordered' => 12, 'qty_invoiced' => 5, 'qty_refunded' => 5, 'qty_shipped' => 0,
'qty_canceled' => 0,
],
'expectedResult' => ['to_ship' => 7.0, 'to_invoice' => 7.0]
],
'partially_refunded' => [
'options' => [
'qty_ordered' => 12, 'qty_invoiced' => 12, 'qty_refunded' => 5, 'qty_shipped' => 0,
'qty_canceled' => 0,
],
'expectedResult' => ['to_ship' => 7.0, 'to_invoice' => 0.0]
],
'partially_shipped' => [
'options' => [
'qty_ordered' => 12, 'qty_invoiced' => 0, 'qty_refunded' => 0, 'qty_shipped' => 4,
'qty_canceled' => 0
],
'expectedResult' => ['to_ship' => 8.0, 'to_invoice' => 12.0]
],
'partially_refunded_partially_shipped' => [
'options' => [
'qty_ordered' => 12, 'qty_invoiced' => 12, 'qty_refunded' => 5, 'qty_shipped' => 4,
'qty_canceled' => 0
],
'expectedResult' => ['to_ship' => 3.0, 'to_invoice' => 0.0]
],
'complete' => [
'options' => [
'qty_ordered' => 12, 'qty_invoiced' => 12, 'qty_refunded' => 0, 'qty_shipped' => 12,
'qty_canceled' => 0
],
'expectedResult' => ['to_ship' => 0.0, 'to_invoice' => 0.0]
],
'canceled' => [
'options' => [
'qty_ordered' => 12, 'qty_invoiced' => 0, 'qty_refunded' => 0, 'qty_shipped' => 0,
'qty_canceled' => 12
],
'expectedResult' => ['to_ship' => 0.0, 'to_invoice' => 0.0]
],
'completely_shipped_using_decimals' => [
'options' => [
'qty_ordered' => 4.4, 'qty_invoiced' => 0.4, 'qty_refunded' => 0.4, 'qty_shipped' => 4,
'qty_canceled' => 0,
],
'expectedResult' => ['to_ship' => 0.0, 'to_invoice' => 4.0]
],
'completely_invoiced_using_decimals' => [
'options' => [
'qty_ordered' => 4.4, 'qty_invoiced' => 4, 'qty_refunded' => 0, 'qty_shipped' => 4,
'qty_canceled' => 0.4
],
'expectedResult' => ['to_ship' => 0.0, 'to_invoice' => 0.0]
]
];
}
}