From a2ff1d16f36ae7f26ab61ae192d272008b68c717 Mon Sep 17 00:00:00 2001 From: Oliver Date: Mon, 30 Apr 2018 22:45:11 +1000 Subject: [PATCH] Introspection of build allocation Yay for dicts --- InvenTree/part/models.py | 19 +++++++++---------- InvenTree/part/templates/part/allocation.html | 14 +++++++------- 2 files changed, 16 insertions(+), 17 deletions(-) diff --git a/InvenTree/part/models.py b/InvenTree/part/models.py index 6ae17df085..316fbaee67 100644 --- a/InvenTree/part/models.py +++ b/InvenTree/part/models.py @@ -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): diff --git a/InvenTree/part/templates/part/allocation.html b/InvenTree/part/templates/part/allocation.html index 13760371e1..61c4ebc2b1 100644 --- a/InvenTree/part/templates/part/allocation.html +++ b/InvenTree/part/templates/part/allocation.html @@ -1,5 +1,5 @@ {% extends "part/part_base.html" %} - +{% load maths %} {% block details %} {% include "part/tabs.html" with tab="allocation" %} @@ -12,15 +12,15 @@ Build Making - Allocted + Allocated Status -{% for build in part.allocated_builds %} +{% for allocation in part.build_allocation %} - {{ build.title }} - {{ build.part.name }} - Quantity - {% include "build_status.html" with build=build %} + {{ allocation.build.title }} + {{ allocation.build.quantity }} × {{ allocation.build.part.name }} + {{ allocation.quantity }} + {% include "build_status.html" with build=allocation.build %} {% endfor %}