Skip to content

Commit 930400b

Browse files
committed
ACP2E-92: Credit memo with decimal qty could be created via API even in case decimal qty disabled
1 parent be9b1fe commit 930400b

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

app/code/Magento/Sales/Model/Order/Creditmemo/Validation/QuantityValidator.php

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,14 @@ public function validate($entity)
8383
}
8484
$orderItem = $orderItemsById[$item->getOrderItemId()];
8585

86+
if ($this->isValidRefundQty($orderItem->getIsQtyDecimal(), $item->getQty())) {
87+
$messages[] =__(
88+
'You cannot use decimal quantity to refund item "%1".',
89+
$item->getSku()
90+
);
91+
continue;
92+
}
93+
8694
if (!$this->canRefundItem($orderItem, $item->getQty(), $invoiceQtysRefundLimits) ||
8795
!$this->isQtyAvailable($orderItem, $item->getQty())
8896
) {
@@ -105,6 +113,21 @@ public function validate($entity)
105113
return $messages;
106114
}
107115

116+
/**
117+
* to check the refund qty is decimal if getIsQtyDecimal is unset.
118+
*
119+
* @param int|null $isQtyDecimal
120+
* @param float $itemQty
121+
* @return bool
122+
*/
123+
private function isValidRefundQty($isQtyDecimal, float $itemQty): bool
124+
{
125+
if (!$isQtyDecimal && (floor($itemQty) !== $itemQty)) {
126+
return true;
127+
}
128+
return false;
129+
}
130+
108131
/**
109132
* We can have problem with float in php (on some server $a=762.73;$b=762.73; $a-$b!=0)
110133
* for this we have additional diapason for 0

app/code/Magento/Sales/i18n/en_US.csv

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -806,3 +806,4 @@ If set YES Email field will be required during Admin order creation for new Cust
806806
"The coupon code has been removed.","The coupon code has been removed."
807807
"This creditmemo no longer exists.","This creditmemo no longer exists."
808808
"Add to address book","Add to address book"
809+
"You cannot use decimal quantity to refund item","You cannot use decimal quantity to refund item"

0 commit comments

Comments
 (0)