public function releasePartial($quantity, $reason = '', $cost = 0)
{
$current = $this->getAttribute('quantity');
if ((double) $quantity === (double) $current || $quantity > $current) {
return $this->releaseAll($reason, $cost);
}
$this->validatePreviousState([$this::STATE_INVENTORY_ON_HOLD], $this::STATE_INVENTORY_RELEASED);
$left = (double) $current - (double) $quantity;
$this->setAttribute('quantity', $left);
$previousState = $this->getAttribute('state');
$this->setAttribute('state', $this::STATE_INVENTORY_RELEASED_PARTIAL);
if (empty($reason)) {
$reason = $this->getTransactionReason('released-partial');
}
if ($this->processStockPutAndSave($quantity, 'inventory.transaction.released.partial', $reason, $cost)) {
return $this->returnToPreviousState($previousState);
}
return false;
}