From ca986cba0152d151f3ed26d2a864a665adcb26f5 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Tue, 1 Aug 2023 11:26:10 +1000 Subject: [PATCH] Fix auto-allocation of build outputs (#5378) (#5379) - Creation of BuildItem objects was using old model references (cherry picked from commit 668dab4175a2de227c1bb0f8ef3f78100f81e903) Co-authored-by: Oliver --- InvenTree/build/models.py | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/InvenTree/build/models.py b/InvenTree/build/models.py index 5ffc4f3a41..c4abe0b8de 100644 --- a/InvenTree/build/models.py +++ b/InvenTree/build/models.py @@ -719,14 +719,22 @@ class Build(MPTTModel, InvenTree.models.InvenTreeBarcodeMixin, InvenTree.models. if items.exists() and items.count() == 1: stock_item = items[0] - # Allocate the stock item - BuildItem.objects.create( - build=self, - bom_item=bom_item, - stock_item=stock_item, - quantity=1, - install_into=output, - ) + # Find the 'BuildLine' object which points to this BomItem + try: + build_line = BuildLine.objects.get( + build=self, + bom_item=bom_item + ) + + # Allocate the stock items against the BuildLine + BuildItem.objects.create( + build_line=build_line, + stock_item=stock_item, + quantity=1, + install_into=output, + ) + except BuildLine.DoesNotExist: + pass else: """Create a single build output of the given quantity."""