Skip to content

Commit 235e121

Browse files
committed
equality and hash operators [equality_on_batches]
1 parent ad26a08 commit 235e121

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

model.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,14 @@ def __init__(self, ref: str, sku: str, qty: int, eta: Optional[date]):
1919
self._purchased_quantity = qty
2020
self._allocations = set() # type: Set[OrderLine]
2121

22+
def __eq__(self, other):
23+
if not isinstance(other, Batch):
24+
return False
25+
return other.reference == self.reference
26+
27+
def __hash__(self):
28+
return hash(self.reference)
29+
2230
def allocate(self, line: OrderLine):
2331
if self.can_allocate(line):
2432
self._allocations.add(line)

0 commit comments

Comments
 (0)