DEV Community

fulfillmentyx
fulfillmentyx

Posted on Edited on

Describe partially fulfilled orders without double-counting the order

By YX Fulfillment

One customer order can move in more than one shipment. A report that labels package rows as “orders shipped” overstates how many orders have moved, and a report that sets “fulfilled” after the first parcel can hide unshipped units.

Keep order lines, shipments and parcels separate in both the tables and the report. This example follows a five-unit order line through two shipments. Two parcels move in the first shipment and one in the second. Both shipment records represent parcels that have already been tendered, and one unit still waits in the warehouse.

from dataclasses import dataclass

@dataclass(frozen=True)
class Package:
    shipment_id: str
    package_id: str
    units: int

ordered_units = 5
packages = [
    Package("SH-1","P-1",2),
    Package("SH-1","P-2",1),
    Package("SH-2","P-3",1),
]
package_keys = {record.package_id for record in packages}
shipment_keys = {record.shipment_id for record in packages}
assert len(package_keys) == len(packages)

shipped_units = sum(record.units for record in packages)
remaining_units = ordered_units - shipped_units
assert (len(shipment_keys), len(package_keys), shipped_units, remaining_units) == (2, 3, 4, 1)
for record in packages:
    print(record.shipment_id, record.package_id, "units:", record.units)
print("Orders represented:", 1)
print("Shipments:", len(shipment_keys), "packages:", len(package_keys))
print("Units shipped:", shipped_units, "units remaining:", remaining_units)
Enter fullscreen mode Exit fullscreen mode

Output from a local run on Python 3.9.6

SH-1 P-1 units: 2
SH-1 P-2 units: 1
SH-2 P-3 units: 1
Orders represented: 1
Shipments: 2 packages: 3
Units shipped: 4 units remaining: 1
Enter fullscreen mode Exit fullscreen mode

At shipment grain the answer is two. At package grain it is three. At order grain there is one order with a partial shipment. The one remaining unit follows from this fixture's agreed quantity. New cancellations or revisions would change the denominator, so a historical snapshot needs the order quantity that was valid at that point in time.

For a multi-item order, compute the progress per order line before determining the overall order status. Package manifests usually need a child table for item quantities. A simple package-level total can say “five units shipped” while a specific SKU still needs attention. Also agree whether a label issued, a package packed, or a parcel tendered is the event that counts as shipped.

Top comments (0)