Skip to content

Commit

Permalink
Add schema
Browse files Browse the repository at this point in the history
  • Loading branch information
edgarrmondragon committed Dec 17, 2024
1 parent 939005d commit a08efea
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 20 deletions.
36 changes: 26 additions & 10 deletions tap_intacct/streams.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import json
import logging
import re
import sys
import typing as t
import uuid
from datetime import datetime, timezone
Expand Down Expand Up @@ -39,6 +40,11 @@
WrongParamsError,
)

if sys.version_info < (3, 11):
from backports.datetime_fromisoformat import MonkeyPatch

MonkeyPatch.patch_fromisoformat()

if t.TYPE_CHECKING:
from singer_sdk.helpers.types import Context

Expand Down Expand Up @@ -81,10 +87,11 @@ class BaseIntacctStream(RESTStream[int], metaclass=abc.ABCMeta):
rest_method = "POST"
path = None

def __init__(self, *args: t.Any, **kwargs: t.Any) -> None:
def __init__(self, *args: t.Any, intacct_obj_name: str | None = None, **kwargs: t.Any) -> None:
"""Initialize stream."""
super().__init__(*args, **kwargs)
self.session_id = self._get_session_id()
self.intacct_obj_name = intacct_obj_name
self.datetime_fields = [
i for i, t in self.schema["properties"].items() if t.get("format", "") == "date-time"
]
Expand Down Expand Up @@ -459,14 +466,12 @@ class IntacctStream(BaseIntacctStream):
def __init__(
self,
*args: t.Any,
intacct_obj_name: str | None = None,
replication_key: str | None = None,
**kwargs: t.Any,
) -> None:
"""Initialize stream."""
super().__init__(*args, **kwargs)
self.primary_keys = KEY_PROPERTIES[self.name]
self.intacct_obj_name = intacct_obj_name
self.replication_key = replication_key

def _format_date_for_intacct(self, datetime: datetime) -> str:
Expand Down Expand Up @@ -580,21 +585,35 @@ class TrialBalancesStream(BaseIntacctStream):
"""

name = "trial_balances"
replication_key = "sss"
primary_keys = ("glaccountno",)

schema = th.PropertiesList(
th.Property("glaccountno", th.StringType),
th.Property("startbalance", th.NumberType),
th.Property("debits", th.NumberType),
th.Property("credits", th.NumberType),
th.Property("adjdebits", th.NumberType),
th.Property("adjcredits", th.NumberType),
th.Property("endbalance", th.NumberType),
th.Property("reportingbook", th.StringType),
th.Property("currency", th.StringType),
).to_dict()

def get_request_data(
self,
context: Context | None,
context: Context | None, # noqa: ARG002
next_page_token: int | None, # noqa: ARG002
) -> dict:
"""Generate request data for trial balances."""
start_date = self.get_starting_timestamp(context)
raw_start_date: str | None = self.config.get("start_date")
end_date = datetime.now(timezone.utc)

if not start_date:
if not raw_start_date:
msg = f"A starting timestamp is required for '{self.name}'"
raise RuntimeError(msg)

start_date = datetime.fromisoformat(raw_start_date)

start_date_obj = {
"year": start_date.year,
"month": start_date.month,
Expand All @@ -610,8 +629,5 @@ def get_request_data(
"get_trialbalance": {
"startdate": start_date_obj,
"enddate": end_date_obj,
"showzerobalances": True,
"showdeptdetail": True,
"showlocdetail": True,
}
}
11 changes: 1 addition & 10 deletions tap_intacct/tap.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,16 +102,7 @@ def discover_streams(self) -> list[streams.IntacctStream]:

discovered_streams.append(
streams.TrialBalancesStream(
tap=self,
name="trial_balances",
schema={
"properties": {
"sss": {
"type": "string",
"format": "date-time",
}
}
},
tap=self, name="trial_balances", intacct_obj_name="trialbalance"
)
)

Expand Down

0 comments on commit a08efea

Please sign in to comment.