mirror of
https://github.com/inventree/InvenTree
synced 2024-08-30 18:33:04 +00:00
Introspection of build allocation
Yay for dicts
This commit is contained in:
parent
b24ddac0b8
commit
a2ff1d16f3
@ -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):
|
||||
|
@ -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 }} × <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>
|
||||
|
Loading…
Reference in New Issue
Block a user