Skip to content

Commit

Permalink
👔 fix: Add parent orgs to Company
Browse files Browse the repository at this point in the history
  • Loading branch information
kiloreven committed Jul 10, 2024
1 parent 09ba8a4 commit 7d33d03
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 13 deletions.
2 changes: 2 additions & 0 deletions oda_wd_client/service/financial_management/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
WorkdayCurrencyHighAccuracy,
WorkdayReferenceBaseModel,
)
from oda_wd_client.service.resource_management._base_types import Organization

# All public imports should be done through oda_wd_client.types.financial_management
__all__: list = []
Expand Down Expand Up @@ -69,6 +70,7 @@ class Company(WorkdayReferenceBaseModel):
name: str | None = None
currency: Currency | None = None
country_code: str | None = Field(max_length=2, default=None)
parents: list[Organization] = []


class JournalSource(WorkdayReferenceBaseModel):
Expand Down
9 changes: 9 additions & 0 deletions oda_wd_client/service/financial_management/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
ProjectWorktag,
SpendCategory,
)
from oda_wd_client.service.resource_management._base_types import Organization
from oda_wd_client.service.resource_management.types import TaxApplicability


Expand Down Expand Up @@ -89,11 +90,19 @@ def workday_company_to_pydantic(data: dict) -> Company:
else:
country_code = None

parent_org_refs = cdata.get("Organization_Container_Reference", [])
parent_orgs = [
_org
for _org in [Organization.from_id_list(item["ID"]) for item in parent_org_refs]
if _org is not None
]

return Company(
workday_id=cdata["Organization_Data"]["ID"],
name=cdata["Organization_Data"]["Organization_Name"],
country_code=country_code,
currency=Currency(currency_code=currency_code) if currency_code else None,
parents=parent_orgs,
)


Expand Down
17 changes: 17 additions & 0 deletions oda_wd_client/service/resource_management/_base_types.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
"""
Some models are used both inside `resource_management` as well as other scopes. To avoid circular imports,
we put these in _base_types.py to allow them to be imported from inside other services.
"""
from typing import Literal

from oda_wd_client.base.types import WorkdayReferenceBaseModel


class Organization(WorkdayReferenceBaseModel):
"""
Reference: https://community.workday.com/sites/default/files/file-hosting/productionapi/Resource_Management/v42.1/Get_Suppliers.html#OrganizationObjectType # noqa
"""

_class_name = "OrganizationObject"
workday_id: str
workday_id_type: Literal["Organization_Reference_ID"] = "Organization_Reference_ID"
12 changes: 2 additions & 10 deletions oda_wd_client/service/resource_management/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
SpendCategory,
)

from ._base_types import Organization

# All public imports should be done through oda_wd_client.types.resource_management
__all__: list = []

Expand Down Expand Up @@ -73,16 +75,6 @@ class WorkdayID(str, Enum):
] = "Business_Entity_Status_Value_ID"


class Organization(WorkdayReferenceBaseModel):
"""
Reference: https://community.workday.com/sites/default/files/file-hosting/productionapi/Resource_Management/v42.1/Get_Suppliers.html#OrganizationObjectType # noqa
"""

_class_name = "OrganizationObject"
workday_id: str
workday_id_type: Literal["Organization_Reference_ID"] = "Organization_Reference_ID"


class Supplier(WorkdayReferenceBaseModel):
"""
Reference: https://community.workday.com/sites/default/files/file-hosting/productionapi/Resource_Management/v40.2/Get_Suppliers.html#SupplierType # noqa
Expand Down
9 changes: 6 additions & 3 deletions oda_wd_client/service/resource_management/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@
Currency,
SpendCategory,
)
from oda_wd_client.service.resource_management._base_types import Organization
from oda_wd_client.service.resource_management.exceptions import NoSupplierID
from oda_wd_client.service.resource_management.types import (
Organization,
PrepaidAmortizationType,
Supplier,
SupplierInvoice,
Expand Down Expand Up @@ -108,9 +108,12 @@ def workday_supplier_to_pydantic(data: dict) -> Supplier:
status_ref = _ref

restrict_org_refs = sup_data.get("Restricted_To_Companies_Reference", list())
_orgs = [Organization.from_id_list(item["ID"]) for item in restrict_org_refs]
restrict_orgs = [
Organization.from_id_list(item["ID"]) for item in restrict_org_refs
]

# Type narrowing to remove falsy values
restricted_orgs = [org for org in _orgs if org]
restricted_orgs = [org for org in restrict_orgs if org]

return Supplier(
workday_id=sup_id,
Expand Down

0 comments on commit 7d33d03

Please sign in to comment.