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

Added payroll summary stream. #22

Merged
merged 2 commits into from
May 14, 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
4 changes: 3 additions & 1 deletion tap_restaurant365/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,11 @@ def get_new_paginator(self) -> BaseAPIPaginator:

def get_starting_time(self, context):
start_date = self.config.get("start_date")
rep_key = None
if start_date:
start_date = parser.parse(self.config.get("start_date"))
rep_key = self.get_starting_timestamp(context) + timedelta(seconds=1)
if context:
rep_key = self.get_starting_timestamp(context) + timedelta(seconds=1)
return rep_key or start_date

def get_url_params(
Expand Down
78 changes: 78 additions & 0 deletions tap_restaurant365/streams.py
Original file line number Diff line number Diff line change
Expand Up @@ -650,3 +650,81 @@ def get_url_params(
if skip > 0:
params["$skip"] = skip
return params

class PayrollSummaryStream(LimitedTimeframeStream):
"""Define custom stream."""

name = "payroll_summary"
path = "/PayrollSummary"
primary_keys = None
replication_key = None
pagination_date = None
schema = th.PropertiesList(
th.Property("employeeID", th.StringType),
th.Property("location", th.StringType),
th.Property("locationNumber", th.StringType),
th.Property("jobCode", th.StringType),
th.Property("payRate", th.NumberType),
th.Property("regularHours", th.NumberType),
th.Property("overtimeHours", th.NumberType),
th.Property("doubleOvertime", th.NumberType),
th.Property("breakPenalty", th.NumberType),
th.Property("grossReceipts", th.NumberType),
th.Property("splitShiftPenalty", th.NumberType),
th.Property("chargeTips", th.NumberType),
th.Property("declaredTips", th.NumberType),
th.Property("percentageOfSales", th.NumberType),
th.Property("percent", th.IntegerType),
th.Property("payrollStart", th.DateTimeType),
th.Property("payrollEnd", th.DateTimeType),
).to_dict()
def get_next_page_token(
self, response: requests.Response, previous_token: t.Optional[t.Any]
) -> t.Optional[t.Any]:
"""
Return a token for identifying next page or None if no more pages.

The token is a datetime object that is used to filter the next page
of results. The token is calculated by adding the days_delta
parameter to the previous token. If the new token is in the future,
the pagination is disabled.

Args:
response: The response object from the latest request.
previous_token: The token from the previous page, or None if
this is the first page.

Returns:
A token for the next page, or None if no more pages are available.
"""
today = datetime.today() # noqa: DTZ002
if self.pagination_date:
previous_token = self.pagination_date
if isinstance(previous_token,str):
previous_token = parser.parse(previous_token)
# Add a day to previous token
next_token = previous_token + timedelta(days=1)
next_token = next_token.replace(tzinfo=None)

# Disable pagination if the next token's date is in the future
if (today - next_token).days < 0:
return None
# Return the next token and the current skip value
return next_token


def get_url_params(
self,
context: dict | None, # noqa: ARG002
next_page_token: Any | None, # noqa: ANN401
) -> dict[str, Any]:

params: dict = {}
token_date = None
if next_page_token:
token_date = next_page_token
start_date = token_date or self.get_starting_time(context)
end_date = start_date + timedelta(days=self.days_delta)
self.pagination_date = end_date
params["$filter"] = f"payrollStart ge {start_date.strftime('%Y-%m-%dT%H:%M:%SZ')} and payrollEnd le {end_date.strftime('%Y-%m-%dT23:59:59Z')}"
return params
1 change: 1 addition & 0 deletions tap_restaurant365/tap.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ def discover_streams(self) -> list[streams.Restaurant365Stream]:
streams.StockCountStream(self),
streams.TransactionsStream(self),
streams.TransactionDetailsStream(self),
streams.PayrollSummaryStream(self),
]


Expand Down
Loading