mirror of
https://github.com/inventree/InvenTree.git
synced 2025-07-13 08:21:26 +00:00
Parts now know how many builds they are allocated to
- allocated_builds returns lists of active builds this part is allocated to - allocated_build_count returns the total number of this part allocated to builds - allocation_count returns total number of allocated parts (in the future this will also include those parts allocated to customer orders)
This commit is contained in:
@ -158,9 +158,11 @@ class Part(models.Model):
|
||||
This subtracts stock which is already allocated
|
||||
"""
|
||||
|
||||
# TODO - For now, just return total stock count
|
||||
# TODO - In future must take account of allocated stock
|
||||
return self.total_stock
|
||||
total = self.total_stock
|
||||
|
||||
total -= self.allocation_count
|
||||
|
||||
return max(total, 0)
|
||||
|
||||
@property
|
||||
def can_build(self):
|
||||
@ -181,7 +183,7 @@ class Part(models.Model):
|
||||
if total is None or n < total:
|
||||
total = n
|
||||
|
||||
return total
|
||||
return max(total, 0)
|
||||
|
||||
@property
|
||||
def active_builds(self):
|
||||
@ -205,6 +207,44 @@ class Part(models.Model):
|
||||
|
||||
return sum([b.quantity for b in self.active_builds])
|
||||
|
||||
@property
|
||||
def allocated_builds(self):
|
||||
""" Return list of builds to which this part is allocated
|
||||
"""
|
||||
|
||||
builds = []
|
||||
|
||||
for item in self.used_in.all():
|
||||
for build in item.part.active_builds:
|
||||
builds.append(build)
|
||||
|
||||
return builds
|
||||
|
||||
@property
|
||||
def allocated_build_count(self):
|
||||
""" Return the total number of this that are allocated for builds
|
||||
"""
|
||||
|
||||
total = 0
|
||||
|
||||
for item in self.used_in.all():
|
||||
for build in item.part.active_builds:
|
||||
n = build.quantity * item.quantity
|
||||
total += n
|
||||
|
||||
return total
|
||||
|
||||
@property
|
||||
def allocation_count(self):
|
||||
""" Return true if any of this part is allocated
|
||||
- To another build
|
||||
- To a customer order
|
||||
"""
|
||||
|
||||
return sum([
|
||||
self.allocated_build_count,
|
||||
])
|
||||
|
||||
@property
|
||||
def total_stock(self):
|
||||
""" Return the total stock quantity for this part.
|
||||
|
Reference in New Issue
Block a user