From 9aa6e714f2ec06054c6057561bfd53b249383d92 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20B=C3=B6hmer?= Date: Thu, 29 Dec 2022 17:33:28 +0100 Subject: [PATCH] Ensure that its own project builds part is not added to the project BOM --- src/Entity/ProjectSystem/ProjectBOMEntry.php | 18 +++++++++++++++++- translations/validators.en.xlf | 6 ++++++ 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/src/Entity/ProjectSystem/ProjectBOMEntry.php b/src/Entity/ProjectSystem/ProjectBOMEntry.php index 6d0a68da..80b0da7c 100644 --- a/src/Entity/ProjectSystem/ProjectBOMEntry.php +++ b/src/Entity/ProjectSystem/ProjectBOMEntry.php @@ -199,7 +199,7 @@ class ProjectBOMEntry extends AbstractDBElement /** * @Assert\Callback */ - public function validate(ExecutionContextInterface $context, $payload) + public function validate(ExecutionContextInterface $context, $payload): void { //Round quantity to whole numbers, if the part is not a decimal part if ($this->part) { @@ -230,6 +230,22 @@ class ProjectBOMEntry extends AbstractDBElement ->atPath('mountnames') ->addViolation(); } + + //Check that the part is not the build representation part of this device or one of its parents + if ($this->part && $this->part->getBuiltProject() !== null) { + //Get the associated project + $associated_project = $this->part->getBuiltProject(); + //Check that it is not the same as the current project neither one of its parents + $current_project = $this->project; + while ($current_project) { + if ($associated_project === $current_project) { + $context->buildViolation('project.bom_entry.can_not_add_own_builds_part') + ->atPath('part') + ->addViolation(); + } + $current_project = $current_project->getParent(); + } + } } diff --git a/translations/validators.en.xlf b/translations/validators.en.xlf index 3eaef9eb..f7425fde 100644 --- a/translations/validators.en.xlf +++ b/translations/validators.en.xlf @@ -263,5 +263,11 @@ The number of mountnames has to match the BOMs quantity! + + + project.bom_entry.can_not_add_own_builds_part + You can not add a project's own builds part to the BOM. + +