Exemplo n.º 1
0
def test_outputs_allocated_event():
    batch = Batch("batchref", "RETRO-LAMPSHADE", 100, eta=None)
    line = OrderLine("oref", "RETRO-LAMPSHADE", 10)
    product = Product(sku="RETRO-LAMPSHADE", batches=[batch])
    product.allocate(line)
    expected = events.Allocated(
        orderid="oref", sku="RETRO-LAMPSHADE", qty=10, batchref=batch.reference
    )
    assert product.events[-1] == expected
Exemplo n.º 2
0
 def allocate(self, line: OrderLine) -> str:
     try:
         batch = next(b for b in sorted(self.batches)
                      if b.can_allocate(line))
         batch.allocate(line)
         self.version_number += 1
         self.events.append(
             events.Allocated(orderid=line.orderid,
                              sku=line.sku,
                              qty=line.qty,
                              batchref=batch.reference))
         return batch.reference
     except StopIteration:
         self.events.append(events.OutOfStock(line.sku))
         return None
Exemplo n.º 3
0
 def allocate(self, line: OrderLine) -> None:
     try:
         # I can use sorted the way I want by defining __gt__
         batch = next(b for b in sorted(self.batches)
                      if b.can_allocate(line))
         batch.allocate(line)
         self._events.append(
             events.Allocated(
                 order_id=line.order_id,
                 batch_ref=batch.reference,
                 sku=line.sku,
                 qty=line.qty,
             ))
         self.version_number += 1  # here
         # return batch.reference
     except StopIteration:
         # raise OutOfStock(f"Out of stock for SKU {line.sku}")
         self._events.append(events.OutOfStock(sku=line.sku))
     except BatchIdempotency:
         self._events.append(
             events.OrderAlreadyAllocated(order_id=line.order_id))