from argparse import _SubParsersAction
from functools import partial
from typing import List
from lxml.objectify import IntElement, StringElement
from q2_sdk.core.dynamic_imports import (
api_ExecuteStoredProcedure as ExecuteStoredProcedure,
)
from .db_object import DbObject
from .representation_row_base import RepresentationRowBase
from q2_sdk.tools.decorators import dev_only
[docs]
class HostTransactionHistoryRow(RepresentationRowBase):
# object name: type hinting = "column name in the db response"
TransactionID: IntElement = "TransactionID"
HostAccountID: IntElement = "HostAccountID"
PostDate: StringElement = "PostDate"
HostTranNumber: IntElement = "HostTranNumber"
HostTranCode: StringElement = "HostTranCode"
InsertDate: StringElement = "InsertDate"
HostPostDate: StringElement = "HostPostDate"
RunningBalance: IntElement = "RunningBalance"
TxnAmount: IntElement = "TxnAmount"
CheckNumber: IntElement = "CheckNumber"
[docs]
class HostTransactionHistory(DbObject):
# GET_BY_NAME_KEY = "column in the db response"
NAME = "HostTransactionHistory"
REPRESENTATION_ROW_CLASS = HostTransactionHistoryRow
[docs]
def add_arguments(self, parser: _SubParsersAction):
subparser = parser.add_parser("get_host_transaction_history")
subparser.set_defaults(parser="get")
subparser.set_defaults(func=partial(self.get, serialize_for_cli=True))
subparser.add_argument(
"transaction_id", type=int, help="Q2_HostTransactionHistory.TransactionID"
)
subparser = parser.add_parser("normalize_sandbox_postdates")
subparser.set_defaults(parser="normalize_sandbox_postdates")
subparser.set_defaults(func=partial(self.get))
[docs]
async def get(
self, transaction_id: int, serialize_for_cli=False
) -> List[HostTransactionHistoryRow]:
assert isinstance(transaction_id, int), (
"Please supply a valid transaction id. It must be passed as an int."
)
response = await self.call_hq(
"sdk_GetHostTransactionHistory",
ExecuteStoredProcedure.SqlParameters([
ExecuteStoredProcedure.SqlParam(
ExecuteStoredProcedure.DataType.BigInt,
"transaction_id",
transaction_id,
)
]),
)
if serialize_for_cli:
columns = [
"TransactionID",
"HostAccountID",
"PostDate",
"HostTranNumber",
"HostTranCode",
"InsertDate",
"HostPostDate",
"RunningBalance",
"TxnAmount",
"CheckNumber",
]
response = self.serialize_for_cli(response, columns)
return response
[docs]
@dev_only
async def normalize_sandbox_postdates(self):
return await self.call_hq("sdk_NormalizeSandboxPostdates")