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])
|
return sum([b.quantity for b in self.active_builds])
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def allocated_builds(self):
|
def build_allocation(self):
|
||||||
""" Return list of builds to which this part is allocated
|
""" Return list of builds to which this part is allocated
|
||||||
"""
|
"""
|
||||||
|
|
||||||
builds = []
|
builds = []
|
||||||
|
|
||||||
for item in self.used_in.all():
|
for item in self.used_in.all():
|
||||||
|
|
||||||
for build in item.part.active_builds:
|
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
|
return builds
|
||||||
|
|
||||||
@ -236,14 +242,7 @@ class Part(models.Model):
|
|||||||
""" Return the total number of this that are allocated for builds
|
""" Return the total number of this that are allocated for builds
|
||||||
"""
|
"""
|
||||||
|
|
||||||
total = 0
|
return sum([a['quantity'] for a in self.build_allocation])
|
||||||
|
|
||||||
for item in self.used_in.all():
|
|
||||||
for build in item.part.active_builds:
|
|
||||||
n = build.quantity * item.quantity
|
|
||||||
total += n
|
|
||||||
|
|
||||||
return total
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def allocation_count(self):
|
def allocation_count(self):
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
{% extends "part/part_base.html" %}
|
{% extends "part/part_base.html" %}
|
||||||
|
{% load maths %}
|
||||||
{% block details %}
|
{% block details %}
|
||||||
|
|
||||||
{% include "part/tabs.html" with tab="allocation" %}
|
{% include "part/tabs.html" with tab="allocation" %}
|
||||||
@ -12,15 +12,15 @@
|
|||||||
<tr>
|
<tr>
|
||||||
<th>Build</th>
|
<th>Build</th>
|
||||||
<th>Making</th>
|
<th>Making</th>
|
||||||
<th>Allocted</th>
|
<th>Allocated</th>
|
||||||
<th>Status</th>
|
<th>Status</th>
|
||||||
</tr>
|
</tr>
|
||||||
{% for build in part.allocated_builds %}
|
{% for allocation in part.build_allocation %}
|
||||||
<tr>
|
<tr>
|
||||||
<td><a href="{% url 'build-detail' build.id %}">{{ build.title }}</a></td>
|
<td><a href="{% url 'build-detail' allocation.build.id %}">{{ allocation.build.title }}</a></td>
|
||||||
<td><a href="{% url 'part-detail' build.part.id %}">{{ build.part.name }}</a></td>
|
<td>{{ allocation.build.quantity }} × <a href="{% url 'part-detail' allocation.build.part.id %}">{{ allocation.build.part.name }}</a></td>
|
||||||
<td>Quantity</td>
|
<td>{{ allocation.quantity }}</td>
|
||||||
<td>{% include "build_status.html" with build=build %}</td>
|
<td>{% include "build_status.html" with build=allocation.build %}</td>
|
||||||
</tr>
|
</tr>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</table>
|
</table>
|
||||||
|
Loading…
Reference in New Issue
Block a user