Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

👔 fix: Add parent orgs to Company #38

Merged
merged 2 commits into from
Jul 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "oda-wd-client"
version = "0.2.1"
version = "0.2.2"
description = "A library for interacting with Workday from Python"
authors = [
"Karl Fredrik Haugland <[email protected]>",
Expand Down
Loading