def test_records_out_of_stock_event_if_cannot_allocate(): batch = Batch('batch1', 'SMALL-FORK', 10, eta=today) product = Product(sku="SMALL-FORK", batches=[batch]) product.allocate(OrderLine('order1', 'SMALL-FORK', 10)) allocation = product.allocate(OrderLine('order2', 'SMALL-FORK', 1)) assert product.events[-1] == events.OutOfStock(sku="SMALL-FORK") assert allocation is None
def test_records_out_of_stock_event_if_cannot_allocate(): sku = "KALANCHOE-EVENTO" batch = BatchOrder("b1", sku, 15, eta=TOMORROW) product = Product(sku, batches=[batch]) product.allocate(OrderLine("o1", sku, 10)) b2 = product.allocate(OrderLine("o2", sku, 20)) assert product.latest_event == events.OutOfStock(sku=sku) assert b2 is None
def test_records_out_of_stock_event_if_cannot_allocat(): batch = model.Batch('b1', '椅子', 10, eta=today) product = model.Product('椅子', batches=[batch]) product.allocate(model.OrderLine('o1', '椅子', 10)) allocation = product.allocate(model.OrderLine( 'o2', '椅子', 1, )) assert product.events[-1] == events.OutOfStock(sku='椅子') assert allocation is None
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
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))
def test_records_out_of_stock_event_if_cannot_allocate(): <<<<<<< HEAD batch = Batch('batch1', 'SMALL-FORK', 10, eta=today) product = Product(sku="SMALL-FORK", batches=[batch]) product.allocate(OrderLine('order1', 'SMALL-FORK', 10)) allocation = product.allocate(OrderLine('order2', 'SMALL-FORK', 1)) ======= batch = Batch("batch1", "SMALL-FORK", 10, eta=today) product = Product(sku="SMALL-FORK", batches=[batch]) product.allocate(OrderLine("order1", "SMALL-FORK", 10)) allocation = product.allocate(OrderLine("order2", "SMALL-FORK", 1)) >>>>>>> upstream/master assert product.events[-1] == events.OutOfStock(sku="SMALL-FORK") assert allocation is None def test_increments_version_number(): <<<<<<< HEAD line = OrderLine('oref', "SCANDI-PEN", 10) product = Product(sku="SCANDI-PEN", batches=[Batch('b1', "SCANDI-PEN", 100, eta=None)]) ======= line = OrderLine("oref", "SCANDI-PEN", 10) product = Product( sku="SCANDI-PEN", batches=[Batch("b1", "SCANDI-PEN", 100, eta=None)] ) >>>>>>> upstream/master product.version_number = 7 product.allocate(line)