mirror of
https://github.com/Part-DB/Part-DB-server.git
synced 2025-06-23 02:09:03 +02:00
Ensure that a project BOM includes the build parts of its subprojects
This commit is contained in:
parent
9aa6e714f2
commit
ef6d30e04b
3 changed files with 37 additions and 1 deletions
|
@ -31,6 +31,7 @@ use Doctrine\Common\Collections\Collection;
|
|||
use Doctrine\ORM\Mapping as ORM;
|
||||
use InvalidArgumentException;
|
||||
use Symfony\Component\Validator\Constraints as Assert;
|
||||
use Symfony\Component\Validator\Context\ExecutionContextInterface;
|
||||
|
||||
/**
|
||||
* Class AttachmentType.
|
||||
|
@ -280,6 +281,34 @@ class Project extends AbstractStructuralDBElement
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @Assert\Callback
|
||||
*/
|
||||
public function validate(ExecutionContextInterface $context, $payload)
|
||||
{
|
||||
//If this project has subprojects, and these have builds part, they must be included in the BOM
|
||||
foreach ($this->getChildren() as $child) {
|
||||
/** @var $child Project */
|
||||
if ($child->getBuildPart() === null) {
|
||||
continue;
|
||||
}
|
||||
//We have to search all bom entries for the build part
|
||||
$found = false;
|
||||
foreach ($this->getBomEntries() as $bom_entry) {
|
||||
if ($bom_entry->getPart() === $child->getBuildPart()) {
|
||||
$found = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//When the build part is not found, we have to add an error
|
||||
if (!$found) {
|
||||
$context->buildViolation('project.bom_has_to_include_all_subelement_parts')
|
||||
->atPath('bom_entries')
|
||||
->setParameter('%project_name%', $child->getName())
|
||||
->setParameter('%part_name%', $child->getBuildPart()->getName())
|
||||
->addViolation();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -41,6 +41,7 @@
|
|||
{% block additional_panes %}
|
||||
<div class="tab-pane" id="bom">
|
||||
{% form_theme form.bom_entries with ['Form/collection_types_layout.html.twig'] %}
|
||||
{{ form_errors(form.bom_entries) }}
|
||||
{{ form_widget(form.bom_entries) }}
|
||||
</div>
|
||||
{% endblock %}
|
|
@ -269,5 +269,11 @@
|
|||
<target>You can not add a project's own builds part to the BOM.</target>
|
||||
</segment>
|
||||
</unit>
|
||||
<unit id="2x2XDI_" name="project.bom_has_to_include_all_subelement_parts">
|
||||
<segment>
|
||||
<source>project.bom_has_to_include_all_subelement_parts</source>
|
||||
<target>The project BOM has to include all subprojects builds parts. Part %part_name% of project %project_name% missing!</target>
|
||||
</segment>
|
||||
</unit>
|
||||
</file>
|
||||
</xliff>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue