Skip to main content

Stock & cost effects

Delivering a purchase order is what puts goods on the shelf. It raises the product's stock on hand and updates its average cost. Reverting, canceling and returning goods undo the same effects, exactly.

Who uses it​

Supplier staff who read a product's stock history, its average cost or its last purchase price.

How it works​

Event on the POStock on handAverage cost
Marked DeliveredGoes up by the quantity, less anything already returnedRe-averaged with the PO's price
Delivery revertedGoes back down by what is still heldReturns to what it was before
Canceled (after delivery)Goes back down by what is still heldAdjusted for the removal
Items returned to the vendorGoes down by the quantity returnedThe returned units leave the average
A return reduced or removedGoes back upThe units re-enter the average

A product sold by weight moves its weight on hand along with its unit count.

Each movement is its own row in the product's stock history: the delivery, the revert and the return are listed separately, so nothing is overwritten.

Calculations​

Average cost is a weighted average of what is on hand.

StepOn handAverage cost
Before10$5.00
PO for 10 units at $8.00 delivered20$6.50
Reverted10$5.00
Corrected to $6.00 and delivered again20$5.50

(10 × $5.00 + 10 × $6.00) ÷ 20 = $5.50, with no trace of the original $8.00.

Returned goods are not taken out twice. A PO for 10 units with 3 returned to the vendor holds 7. Reverting or canceling removes 7, not 10. Delivering it again adds 7 back. A line returned in full moves no stock when reverted.

Stock can go negative. If 12 of 10 delivered units have since been sold, reverting still goes through and the product shows negative stock.

Reports ignore the noise. Average selling price ignores reversed deliveries and goods returned to a vendor. The last purchase price falls back to the earlier delivered order when the latest delivery is reverted.

Where it shows up​

A product's stock history and its stock on hand, average cost and last purchase price (LPP) on the order lines. See Stock from orders.

Permissions​

Reading stock follows the product permissions. Only full access to purchase orders can cause these movements.

Decisions​

  • Reversals are computed from what the delivery wrote, not from the order's current lines. A price or quantity edited after delivery would otherwise take out a different amount than went in and drift further each cycle.
  • Stock and the status change commit together. An order never claims to be delivered without its stock movement.

Specs​

purchase-order-delivery-reversal.feature
# prefix: PDR
Feature: Purchase Order Delivery Reversal
A supplier who marked a purchase order delivered by mistake can return it to placed,
correct it, and mark it delivered again. Reversing undoes the delivery's effect on
stock on hand and average cost, and may be repeated any number of times without the
effects compounding.

Background:
Given a supplier has placed a purchase order with a vendor

Rule: Only a delivered purchase order can be reversed

Scenario: PDR-001 supplier returns a delivered purchase order to placed
Given the purchase order is delivered
When the supplier reverses the delivery
Then the purchase order is placed
And the supplier can edit its items

Scenario Outline: PDR-002 reversal is rejected when the purchase order is <state>
Given the purchase order is <state>
When the supplier attempts to reverse the delivery
Then the reversal is rejected
And the purchase order is unchanged

Examples:
| state |
| placed |
| canceled |

Scenario: PDR-003 reversal is rejected for a purchase order that no longer exists
Given the purchase order has been removed
When the supplier attempts to reverse the delivery
Then the reversal is rejected

Rule: Reversing a delivery undoes its effect on stock on hand

Scenario: PDR-004 stock on hand returns to its pre-delivery level
Given the supplier held 10 units of a product
And a purchase order for 10 more units was delivered
When the supplier reverses the delivery
Then the supplier holds 10 units of that product

Scenario: PDR-005 inventory history records both the delivery and the reversal
Given a delivered purchase order
When the supplier reverses the delivery
Then the inventory history still shows the original delivery
And the inventory history shows the reversal as a separate movement

Scenario: PDR-006 stock on hand may fall below zero when the goods were already sold on
Given a purchase order for 10 units was delivered
And 12 of those units have since been sold
When the supplier reverses the delivery
Then the reversal is accepted
And the supplier's stock on hand for that product is negative

Scenario: PDR-007 both unit count and total weight are restored for weighed products
Given a delivered purchase order for a product sold by weight
When the supplier reverses the delivery
Then the supplier's unit count returns to its pre-delivery level
And the supplier's total weight on hand returns to its pre-delivery level

Rule: Reversing a delivery undoes its effect on average cost

Scenario: PDR-008 average cost returns to its pre-delivery value
Given the supplier held 10 units at an average cost of $5.00
And a purchase order for 10 units at $8.00 each was delivered
And the average cost became $6.50
When the supplier reverses the delivery
Then the average cost is $5.00

Scenario: PDR-009 average cost reflects a corrected price after re-delivery
Given a purchase order for 10 units at $8.00 each was delivered and then reversed
When the supplier corrects the price to $6.00 and marks it delivered again
Then the average cost reflects $6.00 per unit
And the average cost carries no trace of the original $8.00

Scenario: PDR-010 average cost is cleared when no stock remains on hand
Given the supplier held no stock of a product
And a purchase order for that product was delivered
When the supplier reverses the delivery
Then the supplier holds no stock of that product
And the average cost is zero

Rule: Items already returned to the vendor are not reversed twice

Scenario: PDR-011 only the quantity still held is removed
Given a purchase order for 10 units was delivered
And 3 of those units were returned to the vendor
When the supplier reverses the delivery
Then 7 units are removed from stock on hand
And the purchase order has no remaining effect on stock on hand

Scenario: PDR-012 re-delivering restores only the quantity still held
Given a purchase order for 10 units with 3 returned to the vendor was reversed
When the supplier marks it delivered again
Then 7 units are added to stock on hand

Scenario: PDR-013 a fully returned line moves no stock when reversed
Given a purchase order line was delivered and then returned to the vendor in full
When the supplier reverses the delivery
Then no stock movement is recorded for that line

Scenario: PDR-014 canceling a delivered purchase order also accounts for returned items
Given a purchase order for 10 units was delivered
And 3 of those units were returned to the vendor
When the supplier cancels the purchase order
Then 7 units are removed from stock on hand
And the average cost is adjusted for the removal

Rule: Reversal and re-delivery may repeat without compounding

Scenario: PDR-015 repeated cycles leave the same result as a single delivery
Given a purchase order was delivered
When the supplier reverses and re-delivers it three times
And the purchase order is left delivered
Then stock on hand matches a single delivery of that purchase order
And the average cost matches a single delivery of that purchase order

Scenario: PDR-016 a purchase order left reversed has no net effect
Given a purchase order was delivered
When the supplier reverses and re-delivers it three times
And the purchase order is left placed
Then the purchase order has no net effect on stock on hand
And the purchase order has no net effect on the average cost

Scenario: PDR-017 two simultaneous reversals take effect only once
Given a delivered purchase order
When two reversals of the same delivery are attempted at the same time
Then only one reversal takes effect
And stock on hand is reduced only once

Rule: Order history and payments are preserved

Scenario: PDR-018 the date the order was placed is preserved
Given a delivered purchase order placed on a known date
When the supplier reverses the delivery
Then the date the order was placed is unchanged

Scenario: PDR-019 the delivery date is cleared
Given a delivered purchase order
When the supplier reverses the delivery
Then the purchase order has no delivery date

Scenario: PDR-020 payments already recorded are preserved
Given a delivered purchase order that has been paid in full
When the supplier reverses the delivery
Then the payment remains recorded against the purchase order
And the purchase order is still shown as paid

Rule: A payment due date exists as soon as its anchor date is known

Scenario: PDR-021 a due date is available before delivery when an invoice date is known
Given a placed purchase order with an invoice date and payment terms
Then the purchase order has a payment due date

Scenario: PDR-022 the invoice date takes precedence over the delivery date
Given a delivered purchase order with both an invoice date and a delivery date
Then the payment due date is calculated from the invoice date

Scenario: PDR-023 the due date is unaffected by reversal when an invoice date is known
Given a delivered purchase order with an invoice date
When the supplier reverses the delivery
Then the payment due date is unchanged

Scenario: PDR-024 without an invoice date the due date is recalculated on re-delivery
Given a delivered purchase order with no invoice date
When the supplier reverses the delivery and marks it delivered again later
Then the payment due date is calculated from the later delivery date

Scenario: PDR-025 no due date exists without an invoice date or a delivery
Given a placed purchase order with no invoice date
Then the purchase order has no payment due date

Rule: Only the buying business may reverse a delivery

Scenario: PDR-026 the buying business can reverse a delivery
Given a delivered purchase order
When a member of the buying business reverses the delivery
Then the reversal is accepted

Scenario: PDR-027 the selling business cannot reverse a delivery
Given a delivered purchase order
When a member of the selling business attempts to reverse the delivery
Then the reversal is rejected

Rule: Reporting reflects only genuine sales and purchases

Scenario: PDR-028 average selling price ignores reversed deliveries
Given 10 units of a product were sold at $12.00 each
And a delivered purchase order for 10 units of that product was reversed
Then the average selling price for that product is $12.00

Scenario: PDR-029 average selling price ignores items returned to a vendor
Given units of a product were sold
And other units of that product were returned to a vendor
Then the average selling price reflects only the units sold

Scenario: PDR-030 average cost nets a reversed delivery against its original
Given a purchase order for 10 units at $8.00 was delivered, reversed, corrected to $6.00, and delivered again
Then the reported average cost for that product is $6.00

Scenario: PDR-031 last purchase price falls back to the previous delivered order
Given two purchase orders for the same product were delivered at different prices
When the supplier reverses the more recent delivery
Then the last purchase price for that product is the earlier order's price

Rule: A reversal that cannot complete changes nothing

Scenario: PDR-032 a failed reversal leaves the purchase order delivered
Given a delivered purchase order
When the supplier reverses the delivery and the reversal cannot complete
Then the purchase order is still delivered
And stock on hand is unchanged
And the supplier can attempt the reversal again

Known limitations​

  • Weight-only changes do not re-average cost. Average cost is per unit, so a change in weight alone has no quantity to average against.

FAQ​

Why is my stock lower after I canceled a delivered order? The goods the order brought in were removed again, less any units you had already returned.

Why does my average cost differ from the PO price? It is an average of everything on hand, not the latest price. See the table above.