Skip to content

Wrong stock quantity register in transaction after received quantity#85

Open
yashiroiori wants to merge 51 commits intomauricecalhoun:masterfrom
Trexology:master
Open

Wrong stock quantity register in transaction after received quantity#85
yashiroiori wants to merge 51 commits intomauricecalhoun:masterfrom
Trexology:master

Conversation

@yashiroiori
Copy link
Copy Markdown

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.

3 participants