Introspection of build allocation

Yay for dicts
This commit is contained in:
Oliver 2018-04-30 22:45:11 +10:00
parent b24ddac0b8
commit a2ff1d16f3
2 changed files with 16 additions and 17 deletions

View File

@ -219,15 +219,21 @@ class Part(models.Model):
return sum([b.quantity for b in self.active_builds])
@property
def allocated_builds(self):
def build_allocation(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)
b = {}
b['build'] = build
b['quantity'] = item.quantity * build.quantity
builds.append(b)
return builds
@ -236,14 +242,7 @@ class Part(models.Model):
""" 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
return sum([a['quantity'] for a in self.build_allocation])
@property
def allocation_count(self):

View File

@ -1,5 +1,5 @@
{% extends "part/part_base.html" %}
{% load maths %}
{% block details %}
{% include "part/tabs.html" with tab="allocation" %}
@ -12,15 +12,15 @@
<tr>
<th>Build</th>
<th>Making</th>
<th>Allocted</th>
<th>Allocated</th>
<th>Status</th>
</tr>
{% for build in part.allocated_builds %}
{% for allocation in part.build_allocation %}
<tr>
<td><a href="{% url 'build-detail' build.id %}">{{ build.title }}</a></td>
<td><a href="{% url 'part-detail' build.part.id %}">{{ build.part.name }}</a></td>
<td>Quantity</td>
<td>{% include "build_status.html" with build=build %}</td>
<td><a href="{% url 'build-detail' allocation.build.id %}">{{ allocation.build.title }}</a></td>
<td>{{ allocation.build.quantity }} &times <a href="{% url 'part-detail' allocation.build.part.id %}">{{ allocation.build.part.name }}</a></td>
<td>{{ allocation.quantity }}</td>
<td>{% include "build_status.html" with build=allocation.build %}</td>
</tr>
{% endfor %}
</table>