Consider the prices of built instances of subprojects (#1459)

* Consider the prices of built instances of subprojects

* Add test

* fix test

* fix test

* fix test...

* fix test again
This commit is contained in:
d-buchmann 2026-07-27 22:33:29 +02:00 committed by GitHub
parent 0169c2d1fa
commit 8c52407c99
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 32 additions and 1 deletions

View file

@ -243,6 +243,10 @@ final readonly class ProjectBuildHelper
*/
private function getBomEntryUnitPrice(ProjectBOMEntry $entry, int $number_of_builds, ?Currency $currency): ?BigDecimal
{
if ($entry->getPart() && $entry->getPart()->getBuiltProject() instanceof Project){
return $this->calculateTotalBuildPrice($entry->getPart()->getBuiltProject(), 1, $entry->getPriceCurrency());
}
if ($entry->getPart() instanceof Part) {
$total_qty = $entry->getQuantity() * $number_of_builds;
$min_order = $this->pricedetailHelper->getMinOrderAmount($entry->getPart());

View file

@ -208,6 +208,33 @@ final class ProjectBuildHelperTest extends WebTestCase
$this->assertTrue(BigDecimal::of('6.00')->isEqualTo($result));
}
public function testCalculateTotalBuildPriceWithBuildPartFromSubproject(): void
{
$project = new Project();
$entry = new ProjectBOMEntry();
$entry->setPart($this->makePartWithPrice(1.50));
$entry->setQuantity(4);
$project->addBomEntry($entry);
$subproject = new Project();
$subentry = new ProjectBOMEntry();
$subentry->setPart($this->makePartWithPrice(3.5));
$subentry->setQuantity(3);
$subproject->addBomEntry($subentry);
$part = new Part();
$entry2 = new ProjectBOMEntry();
$entry2->setPart($part);
$entry2->setQuantity(2);
$part->setBuiltProject($subproject);
$project->addBomEntry($entry2);
// 4 × 1.50 + 2 x (3 x 3.5) = 27.00 for 1 build
$result = $this->service->calculateTotalBuildPrice($project, 1);
$this->assertNotNull($result);
$this->assertTrue(BigDecimal::of('27.00')->isEqualTo($result));
}
public function testCalculateUnitBuildPriceEqualsTotal(): void
{
$project = new Project();