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

Add field restricted_to_companies for suppliers #37

Merged
merged 2 commits into from
May 28, 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
11 changes: 11 additions & 0 deletions oda_wd_client/service/resource_management/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,16 @@ 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 All @@ -94,6 +104,7 @@ class Supplier(WorkdayReferenceBaseModel):
iban: str | None = None
primary_tax_id: str | None = None
worktag_only: bool = False
restricted_to_companies: list[Organization] = []


class TaxRate(WorkdayReferenceBaseModel):
Expand Down
7 changes: 7 additions & 0 deletions oda_wd_client/service/resource_management/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
)
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 @@ -106,6 +107,11 @@ def workday_supplier_to_pydantic(data: dict) -> Supplier:
if _ref:
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]
# Type narrowing to remove falsy values
restricted_orgs = [org for org in _orgs if org]

return Supplier(
workday_id=sup_id,
reference_id=sup_data.get("Supplier_Reference_ID", None),
Expand All @@ -117,6 +123,7 @@ def workday_supplier_to_pydantic(data: dict) -> Supplier:
),
primary_tax_id=primary_tax_id,
worktag_only=sup_data["Worktag_Only"],
restricted_to_companies=restricted_orgs,
# Currency_ID _should_ be in accordance with ISO 4217
currency=get_id_from_list(currency_ref["ID"], "Currency_ID")
if currency_ref
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.0"
version = "0.2.1"
description = "A library for interacting with Workday from Python"
authors = [
"Karl Fredrik Haugland <[email protected]>",
Expand Down
Loading