Skip to content

Commit 07dd382

Browse files
committed
make Batches sortable [dunder_gt]
1 parent 0c3b87e commit 07dd382

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

model.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@ def __init__(self, ref: str, sku: str, qty: int, eta: Optional[date]):
2525
self._purchased_quantity = qty
2626
self._allocations = set() # type: Set[OrderLine]
2727

28+
def __repr__(self):
29+
return f"<Batch {self.reference}>"
30+
2831
def __eq__(self, other):
2932
if not isinstance(other, Batch):
3033
return False
@@ -33,6 +36,13 @@ def __eq__(self, other):
3336
def __hash__(self):
3437
return hash(self.reference)
3538

39+
def __gt__(self, other):
40+
if self.eta is None:
41+
return False
42+
if other.eta is None:
43+
return True
44+
return self.eta > other.eta
45+
3646
def allocate(self, line: OrderLine):
3747
if self.can_allocate(line):
3848
self._allocations.add(line)

0 commit comments

Comments
 (0)