From cfc107c181eaef4210d1c9cd8ea2d0b83dafab08 Mon Sep 17 00:00:00 2001 From: Drahma Date: Thu, 28 Nov 2024 20:20:42 +0200 Subject: [PATCH 1/2] HP-2250/Fix_behat_test_at_billing-mrdp --- tests/behat/bootstrap/BillingContext.php | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/tests/behat/bootstrap/BillingContext.php b/tests/behat/bootstrap/BillingContext.php index 38711a9a..a94600d3 100644 --- a/tests/behat/bootstrap/BillingContext.php +++ b/tests/behat/bootstrap/BillingContext.php @@ -150,6 +150,22 @@ public function progressivePrice($type, $price, $currency, $unit, $sign, $quanti } } + /** + * @Given /^build progressive price/ + */ + public function buildProgressivePrices() + { + foreach ($this->progressivePrice as $type => $price) { + $this->fullPrice([ + 'type' => $type, + 'price' => 0, + 'currency' => $price['currency'], + 'unit' => $price['unit'], + 'data' => ['thresholds' => $price['thresholds'], 'class' => 'ProgressivePrice'], + ]); + } + } + /** * @Given /^remove and recreate tariff plan (\S+)/ */ From ece2df77b3ed375b400ca284cf12021798279675 Mon Sep 17 00:00:00 2001 From: Drahma Date: Tue, 31 Dec 2024 15:42:10 +0200 Subject: [PATCH 2/2] HP-2250/Fixed convert unit in progressive price --- src/price/ProgressivePrice.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/price/ProgressivePrice.php b/src/price/ProgressivePrice.php index baabf712..5de7d1b3 100644 --- a/src/price/ProgressivePrice.php +++ b/src/price/ProgressivePrice.php @@ -49,10 +49,10 @@ public function getThresholds(): ProgressivePriceThresholdList */ public function calculateUsage(QuantityInterface $quantity): ?QuantityInterface { - $usage = $quantity->subtract($this->prepaid); + $usage = $quantity->convert($this->prepaid->getUnit())->subtract($this->prepaid); if ($usage->isPositive()) { - return $quantity; + return $usage; } return Quantity::create($this->prepaid->getUnit()->getName(), 0);