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.
+
+