Skip to content

Commit e2e7bc5

Browse files
committed
make Batches sortable [dunder_gt]
1 parent eb49ab4 commit e2e7bc5

1 file changed

Lines changed: 10 additions & 0 deletions

File tree

model.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@ def __init__(
2929
self._purchased_quantity = qty
3030
self._allocations = set() # type: Set[OrderLine]
3131

32+
def __repr__(self):
33+
return f'<Batch {self.reference}>'
34+
3235
def __eq__(self, other):
3336
if not isinstance(other, Batch):
3437
return False
@@ -37,6 +40,13 @@ def __eq__(self, other):
3740
def __hash__(self):
3841
return hash(self.reference)
3942

43+
def __gt__(self, other):
44+
if self.eta is None:
45+
return False
46+
if other.eta is None:
47+
return True
48+
return self.eta > other.eta
49+
4050
def allocate(self, line: OrderLine):
4151
if self.can_allocate(line):
4252
self._allocations.add(line)

0 commit comments

Comments
 (0)