Tweaked build detail page

This commit is contained in:
Oliver 2018-05-01 08:55:51 +10:00
parent a2ff1d16f3
commit dad594dc7a
2 changed files with 18 additions and 4 deletions

View File

@ -60,6 +60,20 @@ class Build(models.Model):
# Notes can be attached to each build output
notes = models.TextField(blank=True)
@property
def required_parts(self):
parts = []
for item in self.part.bom_items.all():
part = {'part': item.sub_part,
'per_build': item.quantity,
'quantity': item.quantity * self.quantity
}
parts.append(part)
return parts
@property
def is_active(self):
""" Is this build active?

View File

@ -46,11 +46,11 @@
</tr>
</thead>
<tbody>
{% for item in build.part.bom_items.all %}
{% for item in build.required_parts %}
<tr>
<td><a href="{% url 'part-detail' item.sub_part.id %}">{{ item.sub_part.name }}</a></td>
<td>{{ build.quantity }} &times {{ item.quantity }}</td>
<td>{{ item.sub_part.total_stock }}</td>
<td><a href="{% url 'part-detail' item.part.id %}">{{ item.part.name }}</a></td>
<td>{{ item.quantity }}</td>
<td>{{ item.part.total_stock }}</td>
</tr>
{% endfor %}
</tbody>