Skip to content

Commit 0b2c441

Browse files
committed
use method chaining to fix a nasty constructor thing
1 parent 584efbb commit 0b2c441

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

domain_model.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,10 @@ def __getitem__(self, sku):
2525
def __contains__(self, sku):
2626
return sku in self._sources
2727

28+
def with_sources(self, sources: dict):
29+
self._sources = sources
30+
return self
31+
2832
def supplement_with(self, other):
2933
for sku, source in other._sources.items():
3034
if sku not in self:
@@ -70,14 +74,12 @@ def decrement_available(self, sku, qty):
7074
self._lines[sku] -= qty
7175

7276
def allocation_for(self, order: Order):
73-
allocation = Allocation(order)
74-
allocation._sources = { # TODO: this ain't right
77+
return Allocation(order).with_sources({
7578
line.sku: self
7679
for line in order.lines
7780
if line.sku in self
7881
and self[line.sku] > line.qty
79-
}
80-
return allocation
82+
})
8183

8284

8385
class Warehouse(_Stock):

0 commit comments

Comments
 (0)