Skip to content

Commit

Permalink
💥 improvement: Completed pydantic 2 upgrades
Browse files Browse the repository at this point in the history
  • Loading branch information
kiloreven committed Feb 15, 2024
1 parent 28d9786 commit 2459576
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 15 deletions.
7 changes: 6 additions & 1 deletion oda_wd_client/base/types.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
from base64 import b64encode
from datetime import date
from decimal import Decimal
from enum import Enum
from typing import Annotated, Self

import magic
from pydantic import BaseModel, BeforeValidator
from pydantic import BaseModel, BeforeValidator, Field
from suds import sudsobject

from oda_wd_client.base.api import WorkdayClient
Expand All @@ -14,6 +15,10 @@

WorkdayDate = Annotated[date, BeforeValidator(parse_workday_date)]
WorkdayOptionalDate = Annotated[date | None, BeforeValidator(parse_workday_date)]
# https://github.com/pydantic/pydantic/discussions/7962#discussioncomment-7939114
WorkdayCurrency = Annotated[Decimal, Field(max_digits=18, decimal_places=3)]
# Workday has multiple currency definitions depending on location
WorkdayCurrency2 = Annotated[Decimal, Field(max_digits=26, decimal_places=6)]


class WorkdayReferenceBaseModel(BaseModel):
Expand Down
7 changes: 3 additions & 4 deletions oda_wd_client/service/financial_management/types.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
from datetime import date, datetime
from decimal import Decimal
from enum import Enum
from typing import Literal

from pydantic import BaseModel, Field

from oda_wd_client.base.types import WorkdayReferenceBaseModel
from oda_wd_client.base.types import WorkdayCurrency2, WorkdayReferenceBaseModel

# All public imports should be done through oda_wd_client.types.financial_management
__all__: list = []
Expand Down Expand Up @@ -170,8 +169,8 @@ class JournalEntryLineData(BaseModel):
"""

ledger_account: LedgerAccount
debit: Decimal | None = None
credit: Decimal | None = None
debit: WorkdayCurrency2 | None = None
credit: WorkdayCurrency2 | None = None
cost_center: CostCenterWorktag | None = None
spend_category: SpendCategory | None = None
memo: str
Expand Down
24 changes: 15 additions & 9 deletions oda_wd_client/service/resource_management/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,15 @@
from enum import Enum
from typing import Literal

from pydantic import BaseModel, Field

from oda_wd_client.base.types import File, WorkdayDate, WorkdayReferenceBaseModel
from pydantic import BaseModel

from oda_wd_client.base.types import (
File,
WorkdayCurrency,
WorkdayCurrency2,
WorkdayDate,
WorkdayReferenceBaseModel,
)
from oda_wd_client.service.financial_management.types import (
Company,
CostCenterWorktag,
Expand Down Expand Up @@ -176,7 +182,7 @@ class SupplierInvoiceLine(BaseModel):
"""

order: int | None = None
quantity: Decimal = Field(max_digits=22, decimal_places=2, default=Decimal(0))
quantity: WorkdayCurrency = Decimal(0)
description: str = "-No description-"
tax_rate_options_data: TaxRateOptionsData | None = None
tax_applicability: TaxApplicability | None = None
Expand All @@ -185,10 +191,10 @@ class SupplierInvoiceLine(BaseModel):
cost_center: CostCenterWorktag | None = None
project: ProjectWorktag | None = None
# Incl. VAT
gross_amount: Decimal = Field(max_digits=18, decimal_places=3)
gross_amount: WorkdayCurrency
# Excl. VAT
net_amount: Decimal | None = Field(max_digits=18, decimal_places=3, default=None)
tax_amount: Decimal | None = Field(max_digits=18, decimal_places=3, default=None)
net_amount: WorkdayCurrency | None = None
tax_amount: WorkdayCurrency | None = None
budget_date: date | None = None


Expand All @@ -204,8 +210,8 @@ class BaseSupplierInvoice(WorkdayReferenceBaseModel):
currency: Currency
supplier: Supplier
due_date: WorkdayDate
total_amount: Decimal = Field(max_digits=26, decimal_places=6)
tax_amount: Decimal = Field(max_digits=26, decimal_places=6)
total_amount: WorkdayCurrency2
tax_amount: WorkdayCurrency2
tax_option: TaxOption | None = None
additional_reference_number: str | None = None
additional_type_reference: AdditionalReferenceType | None = None
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.1.0a0"
version = "0.1.0a1"
description = "A library for interacting with Workday from Python"
authors = [
"Karl Fredrik Haugland <karlfredrik.haugland@oda.com>",
Expand Down

0 comments on commit 2459576

Please sign in to comment.