Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wrong stock quantity register in transaction after received quantity #85

Open
wants to merge 51 commits into
base: master
Choose a base branch
from

Conversation

yashiroiori
Copy link

When register a transaction with stock example: 26, when apply method received and put 10, the stock saved are 16 instace of 10, maybe wrong is in the line 720

https://github.com/Trexology/inventory/blob/e08adab035717412babac36f6c092d2a4a3ab15b/src/Traits/InventoryTransactionTrait.php#L720

public function receivedPartial($quantity, $reason = '', $cost = 0)
{
$current = $this->getAttribute('quantity');

    if ((float) $quantity === (float) $current || $quantity > $current) {
        return $this->receivedAll($reason, $cost);
    }

    // Only allow the previous state of ordered
    $this->validatePreviousState([
        $this::STATE_ORDERED_PENDING,
    ], $this::STATE_ORDERED_RECEIVED_PARTIAL);

    // Get the left over amount of quantity still to be received
    $left = (float) $current - (float) $quantity;

    $this->setAttribute('quantity', $left);

    $previousState = $this->getAttribute('state');

    $this->setAttribute('state', $this::STATE_ORDERED_RECEIVED_PARTIAL);

    if (empty($reason)) {
        $reason = $this->getTransactionReason('received-partial');
    }
    //---------------------------
    // $left have a $current quantity - $quantity, in the example are: 26 - 10 = 16 and this value put into stock instance of 10
    // then change: $left->change for $quantity and put 10 into stock of inventory
    //---------------------------
    if ($this->processStockPutAndSave($quantity, 'inventory.transaction.received.partial', $reason, $cost)) {
        return $this->returnToPreviousState($previousState);
    }

    return false;
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants