diff --git a/src/Services/ProjectSystem/ProjectBuildHelper.php b/src/Services/ProjectSystem/ProjectBuildHelper.php index e011d980..090f9e66 100644 --- a/src/Services/ProjectSystem/ProjectBuildHelper.php +++ b/src/Services/ProjectSystem/ProjectBuildHelper.php @@ -242,7 +242,11 @@ final readonly class ProjectBuildHelper * taking bulk pricing into account for N builds. */ 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()); diff --git a/tests/Services/ProjectSystem/ProjectBuildHelperTest.php b/tests/Services/ProjectSystem/ProjectBuildHelperTest.php index a30380db..1e311730 100644 --- a/tests/Services/ProjectSystem/ProjectBuildHelperTest.php +++ b/tests/Services/ProjectSystem/ProjectBuildHelperTest.php @@ -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();