Skip to content

Commit 7cdaf7c

Browse files
committed
MPT-10795 fix trial calculation and exchange rates client
1 parent c9b6747 commit 7cdaf7c

File tree

4 files changed

+18
-18
lines changed

4 files changed

+18
-18
lines changed

ffc/billing/process_billing.py

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -567,7 +567,7 @@ def generate_refunds(
567567
refund_lines = []
568568
trial_days: set[int] = set()
569569
trial_start_date, trial_end_date = get_trial_dates(agreement=agreement)
570-
if trial_start_date and trial_end_date:
570+
if trial_start_date and trial_end_date and trial_end_date >= self.billing_start_date.date():
571571
trial_info = self.get_trial_info(
572572
trial_start_date,
573573
trial_end_date,
@@ -664,18 +664,11 @@ async def generate_refund_lines(
664664
f"{linked_datasource_id}-{idx:02d}",
665665
datasource_id,
666666
organization_id,
667-
date(
668-
self.billing_start_date.year,
669-
self.billing_start_date.month,
670-
min(daily_expenses.keys()),
671-
),
672-
date(
673-
self.billing_start_date.year,
674-
self.billing_start_date.month,
675-
max(daily_expenses.keys()),
676-
),
667+
refund.start_date,
668+
refund.end_date,
677669
-refund_in_target_currency,
678670
datasource_name,
671+
refund.description,
679672
)
680673
)
681674

ffc/clients/exchage_rates.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ async def fetch_exchange_rates(self, currency) -> dict[str, Any]:
2121
if currency in self.exchage_rates_cache:
2222
return self.exchage_rates_cache[currency]
2323
response = await self.httpx_client.get(
24-
f"{settings.EXTENSION_CONFIG["EXCHANGE_RATES_BASE_URL"]}/latest/{currency}"
24+
f"{settings.EXTENSION_CONFIG["EXCHANGE_RATES_API_TOKEN"]}/latest/{currency}"
2525
)
2626
response.raise_for_status()
2727
exchange_rates = response.json()

tests/ffc/test_exchange_rates_client.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,10 @@
55

66
@pytest.fixture()
77
def exchange_rates_client_settings(settings):
8-
settings.EXTENSION_CONFIG = {"EXCHANGE_RATES_BASE_URL": "https://local.local"}
8+
settings.EXTENSION_CONFIG = {
9+
"EXCHANGE_RATES_BASE_URL": "https://local.local",
10+
"EXCHANGE_RATES_API_TOKEN": "api-token"
11+
}
912
return settings
1013

1114

@@ -25,7 +28,9 @@ async def test_fetch_exchange_rates_cached(mocked_exchange_rates_client, exchang
2528
async def test_fetch_exchange_rates_no_cached(
2629
httpx_mock, mocked_exchange_rates_client, exchange_rates, exchange_rates_client_settings
2730
):
28-
httpx_mock.add_response(method="GET", url="https://local.local/latest/USD", json=exchange_rates)
31+
httpx_mock.add_response(
32+
method="GET", url="https://local.local/api-token/latest/USD", json=exchange_rates,
33+
)
2934
response = await mocked_exchange_rates_client.fetch_exchange_rates(currency="USD")
3035
assert response == exchange_rates
3136
assert mocked_exchange_rates_client.exchage_rates_cache["USD"] == exchange_rates

tests/ffc/test_process_billing.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -477,8 +477,9 @@ async def test_generate_datasource_charges_with_daily_expenses(
477477
'"34654563488"}, "search": {"subscription": {"criteria": '
478478
'"subscription.externalIds.vendor", "value": "FORG-4801-6958-2949"}, "item": '
479479
'{"criteria": "item.externalIds.vendor", "value": ""}}, "period": {"start": '
480-
'"2025-06-01", "end": "2025-06-30"}, "price": {"unitPP": "-39.1447", "PPx1": '
481-
'"-39.1447"}, "quantity": 1, "description": {"value1": "Test", "value2": ""}, '
480+
'"2025-06-01", "end": "2025-06-15"}, "price": {"unitPP": "-39.1447", "PPx1": '
481+
'"-39.1447"}, "quantity": 1, "description": {"value1": "Test", "value2": '
482+
'"Refund due to trial period (from 01 Jun 2025 to 15 Jun 2025)"}, '
482483
'"segment": "COM"}\n'
483484
)
484485
assert (
@@ -588,8 +589,9 @@ async def test_generate_datasource_charges_with_no_entitlement(
588589
'"34654563488"}, "search": {"subscription": {"criteria": '
589590
'"subscription.externalIds.vendor", "value": "FORG-4801-6958-2949"}, "item": '
590591
'{"criteria": "item.externalIds.vendor", "value": ""}}, "period": {"start": '
591-
'"2025-06-01", "end": "2025-06-30"}, "price": {"unitPP": "-39.1447", "PPx1": '
592-
'"-39.1447"}, "quantity": 1, "description": {"value1": "Test", "value2": ""}, '
592+
'"2025-06-01", "end": "2025-06-15"}, "price": {"unitPP": "-39.1447", "PPx1": '
593+
'"-39.1447"}, "quantity": 1, "description": {"value1": "Test", "value2": '
594+
'"Refund due to trial period (from 01 Jun 2025 to 15 Jun 2025)"}, '
593595
'"segment": "COM"}\n'
594596
)
595597

0 commit comments

Comments
 (0)