mirror of
https://github.com/Part-DB/Part-DB-server.git
synced 2025-12-06 11:09:29 +00:00
Fix Wrong default number of project builds if BOM is empty #1038
This commit is contained in:
parent
7a1a458abe
commit
05839a549c
3 changed files with 18 additions and 8 deletions
|
|
@ -63,17 +63,19 @@ class ProjectBuildHelper
|
||||||
*/
|
*/
|
||||||
public function getMaximumBuildableCount(Project $project): int
|
public function getMaximumBuildableCount(Project $project): int
|
||||||
{
|
{
|
||||||
|
$bom_entries = $project->getBomEntries();
|
||||||
|
if ($bom_entries->isEmpty()) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
$maximum_buildable_count = PHP_INT_MAX;
|
$maximum_buildable_count = PHP_INT_MAX;
|
||||||
foreach ($project->getBomEntries() as $bom_entry) {
|
foreach ($bom_entries as $bom_entry) {
|
||||||
//Skip BOM entries without a part (as we can not determine that)
|
//Skip BOM entries without a part (as we can not determine that)
|
||||||
if (!$bom_entry->isPartBomEntry()) {
|
if (!$bom_entry->isPartBomEntry()) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
//The maximum buildable count for the whole project is the minimum of all BOM entries
|
//The maximum buildable count for the whole project is the minimum of all BOM entries
|
||||||
$maximum_buildable_count = min($maximum_buildable_count, $this->getMaximumBuildableCountForBOMEntry($bom_entry));
|
$maximum_buildable_count = min($maximum_buildable_count, $this->getMaximumBuildableCountForBOMEntry($bom_entry));
|
||||||
}
|
}
|
||||||
|
|
||||||
return $maximum_buildable_count;
|
return $maximum_buildable_count;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -8,7 +8,8 @@
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
||||||
{% block card_content %}
|
{% block card_content %}
|
||||||
{% set can_build = buildHelper.projectBuildable(project, number_of_builds) %}
|
{% set bom_empty = project.bomEntries | length == 0 %}
|
||||||
|
{% set can_build = not bom_empty and buildHelper.projectBuildable(project, number_of_builds) %}
|
||||||
{% import "components/projects.macro.html.twig" as project_macros %}
|
{% import "components/projects.macro.html.twig" as project_macros %}
|
||||||
|
|
||||||
{% if project.status is not empty and project.status != "in_production" %}
|
{% if project.status is not empty and project.status != "in_production" %}
|
||||||
|
|
@ -18,7 +19,10 @@
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
<div class="alert {% if can_build %}alert-success{% else %}alert-danger{% endif %}" role="alert">
|
<div class="alert {% if can_build %}alert-success{% else %}alert-danger{% endif %}" role="alert">
|
||||||
{% if not can_build %}
|
{% if bom_empty %}
|
||||||
|
<h5><i class="fa-solid fa-circle-exclamation fa-fw"></i> {% trans %}project.builds.no_bom_entries{% endtrans %}</h5>
|
||||||
|
<span class="text-muted">{% trans %}project.builds.no_bom_entries_hint{% endtrans %}</span>
|
||||||
|
{% elseif not can_build %}
|
||||||
<h5><i class="fa-solid fa-circle-exclamation fa-fw"></i> {% trans %}project.builds.build_not_possible{% endtrans %}</h5>
|
<h5><i class="fa-solid fa-circle-exclamation fa-fw"></i> {% trans %}project.builds.build_not_possible{% endtrans %}</h5>
|
||||||
<b>{% trans with {"%number_of_builds%": number_of_builds} %}project.builds.following_bom_entries_miss_instock_n{% endtrans %}</b>
|
<b>{% trans with {"%number_of_builds%": number_of_builds} %}project.builds.following_bom_entries_miss_instock_n{% endtrans %}</b>
|
||||||
<ul>
|
<ul>
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,5 @@
|
||||||
{% set can_build = buildHelper.projectBuildable(project) %}
|
{% set bom_empty = project.bomEntries | length == 0 %}
|
||||||
|
{% set can_build = not bom_empty and buildHelper.projectBuildable(project) %}
|
||||||
|
|
||||||
{% import "components/projects.macro.html.twig" as project_macros %}
|
{% import "components/projects.macro.html.twig" as project_macros %}
|
||||||
|
|
||||||
|
|
@ -9,7 +10,10 @@
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
<div class="alert mt-2 {% if can_build %}alert-success{% else %}alert-danger{% endif %}" role="alert">
|
<div class="alert mt-2 {% if can_build %}alert-success{% else %}alert-danger{% endif %}" role="alert">
|
||||||
{% if not can_build %}
|
{% if bom_empty %}
|
||||||
|
<h5><i class="fa-solid fa-circle-exclamation fa-fw"></i> {% trans %}project.builds.no_bom_entries{% endtrans %}</h5>
|
||||||
|
<span class="text-muted">{% trans %}project.builds.no_bom_entries_hint{% endtrans %}</span>
|
||||||
|
{% elseif not can_build %}
|
||||||
<h5><i class="fa-solid fa-circle-exclamation fa-fw"></i> {% trans %}project.builds.build_not_possible{% endtrans %}</h5>
|
<h5><i class="fa-solid fa-circle-exclamation fa-fw"></i> {% trans %}project.builds.build_not_possible{% endtrans %}</h5>
|
||||||
<b>{% trans %}project.builds.following_bom_entries_miss_instock{% endtrans %}</b>
|
<b>{% trans %}project.builds.following_bom_entries_miss_instock{% endtrans %}</b>
|
||||||
<ul>
|
<ul>
|
||||||
|
|
@ -27,7 +31,7 @@
|
||||||
<div class="row mt-2">
|
<div class="row mt-2">
|
||||||
<div class="col-4">
|
<div class="col-4">
|
||||||
<div class="input-group mb-3">
|
<div class="input-group mb-3">
|
||||||
<input type="number" min="1" class="form-control" placeholder="{% trans %}project.builds.number_of_builds{% endtrans %}" name="n" required>
|
<input type="number" min="1" class="form-control" placeholder="{% trans %}project.builds.number_of_builds{% endtrans %}" name="n" required value="1">
|
||||||
<input type="hidden" name="_redirect" value="{{ uri_without_host(app.request) }}">
|
<input type="hidden" name="_redirect" value="{{ uri_without_host(app.request) }}">
|
||||||
<button class="btn btn-outline-secondary" type="submit" id="button-addon2">{% trans %}project.build.btn_build{% endtrans %}</button>
|
<button class="btn btn-outline-secondary" type="submit" id="button-addon2">{% trans %}project.build.btn_build{% endtrans %}</button>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue