Function to test if enough parts for a build

This commit is contained in:
Oliver 2018-05-01 09:00:09 +10:00
parent dad594dc7a
commit 7c3b1f9bb4
2 changed files with 23 additions and 0 deletions

View File

@ -74,6 +74,17 @@ class Build(models.Model):
return parts
@property
def can_build(self):
""" Return true if there are enough parts to supply build
"""
for item in self.required_parts:
if item['part'].total_stock < item['quantity']:
return False
return True
@property
def is_active(self):
""" Is this build active?

View File

@ -24,6 +24,18 @@
<tr>
<td>Created</td><td>{{ build.creation_date }}</td>
</tr>
{% if build.is_active %}
<tr>
<td>Enough Parts?</td>
<td>
{% if build.can_build %}
Yes
{% else %}
No
{% endif %}
</td>
</tr>
{% endif %}
{% if batch.completion_date %}
<tr>
<td>Completed</td><td>{{ build.creation_date }}</td>