Skip to content

Commit 0d8a402

Browse files
authored
Merge pull request #60 from ImMin5/feature-get-linked-account
Modify pay_as_you_go condition
2 parents f09369a + 5b677f5 commit 0d8a402

File tree

2 files changed

+44
-29
lines changed

2 files changed

+44
-29
lines changed

src/cloudforet/cost_analysis/manager/cost_manager.py

+7-4
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ def get_data(
9797

9898
def _make_cost_data(
9999
self, results: list, end: datetime, options: dict, tenant_id: str = None
100-
):
100+
) -> list:
101101
"""Source Data Model"""
102102

103103
costs_data = []
@@ -249,9 +249,12 @@ def _get_cost_from_result_with_options(self, result: dict, options: dict) -> flo
249249
return cost
250250

251251
def get_pay_as_you_go_cost(self, result: dict, cost: float = 0.0) -> float:
252-
if pay_g_billing_price := result.get("paygcostinbillingcurrency"):
253-
cost_pay_as_you_go = pay_g_billing_price
254-
elif pay_g_price := result.get("paygprice", 0.0):
252+
if "paygcostinbillingcurrency" in result:
253+
cost_pay_as_you_go = result.get("paygcostinbillingcurrency", 0.0)
254+
elif "paygprice" in result:
255+
pay_g_price = self._convert_str_to_float_format(
256+
result.get("paygprice", 0.0)
257+
)
255258
usage_quantity = self._convert_str_to_float_format(
256259
result.get("quantity", 0.0)
257260
)

src/cloudforet/cost_analysis/manager/job_manager.py

+37-25
Original file line numberDiff line numberDiff line change
@@ -73,11 +73,10 @@ def get_tasks(
7373
}
7474
}
7575
)
76-
changed.append({"start": start_month})
77-
synced_accounts.extend(
78-
{"account_id": tenant_id}
79-
for tenant_id in divided_customer_tenant_info
76+
synced_accounts = self._extend_synced_accounts(
77+
synced_accounts, divided_customer_tenant_info
8078
)
79+
changed.append({"start": start_month})
8180
if first_sync_tenants:
8281
first_sync_start_month = self._get_start_month(start=None)
8382
tasks.append(
@@ -91,9 +90,15 @@ def get_tasks(
9190
}
9291
}
9392
)
94-
changed.append({"start": first_sync_start_month})
95-
synced_accounts.extend(
96-
{"account_id": tenant_id} for tenant_id in first_sync_tenants
93+
for tenant_id in first_sync_tenants:
94+
changed.append(
95+
{
96+
"start": first_sync_start_month,
97+
"filter": {"additional_info.Tenant Id": tenant_id},
98+
}
99+
)
100+
synced_accounts = self._extend_synced_accounts(
101+
synced_accounts, first_sync_tenants
97102
)
98103
else:
99104
tasks = [
@@ -167,27 +172,34 @@ def _get_customer_tenants(
167172
if len(customer_tenants) == 0:
168173
raise ERROR_EMPTY_CUSTOMER_TENANTS(customer_tenants=customer_tenants)
169174

170-
if linked_accounts:
171-
linked_accounts_map = {
172-
linked_account["account_id"]: linked_account
173-
for linked_account in linked_accounts
174-
}
175-
176-
for customer_tenant_id in customer_tenants:
177-
if linked_account_info := linked_accounts_map.get(customer_tenant_id):
178-
if not linked_account_info.get("is_sync"):
179-
first_sync_customer_tenants.append(
180-
linked_account_info.get("account_id")
181-
)
182-
customer_tenants.remove(customer_tenant_id)
183-
else:
184-
_LOGGER.debug(
185-
f"[_get_customer_tenants] Customer tenant is not linked: {linked_account_info}"
186-
)
187-
customer_tenants.remove(customer_tenant_id)
175+
# if linked_accounts:
176+
# linked_accounts_map = {
177+
# linked_account["account_id"]: linked_account
178+
# for linked_account in linked_accounts
179+
# }
180+
#
181+
# for customer_tenant_id in customer_tenants:
182+
# if linked_account_info := linked_accounts_map.get(customer_tenant_id):
183+
# if not linked_account_info.get("is_sync"):
184+
# first_sync_customer_tenants.append(
185+
# linked_account_info.get("account_id")
186+
# )
187+
# customer_tenants.remove(customer_tenant_id)
188+
# else:
189+
# _LOGGER.debug(
190+
# f"[_get_customer_tenants] Customer tenant is not linked: {linked_account_info}"
191+
# )
192+
# customer_tenants.remove(customer_tenant_id)
188193

189194
return customer_tenants, first_sync_customer_tenants
190195

196+
@staticmethod
197+
def _extend_synced_accounts(synced_accounts: list, customer_tenants: list) -> list:
198+
synced_accounts.extend(
199+
{"account_id": tenant_id} for tenant_id in customer_tenants
200+
)
201+
return synced_accounts
202+
191203
@staticmethod
192204
def _get_divided_customer_tenants(customer_tenants_info: list) -> list:
193205
tenant_size = math.ceil(len(customer_tenants_info) / _TASK_LIST_SIZE)

0 commit comments

Comments
 (0)