Source code for q2_sdk.hq.hq_api.q2_api.GetAccountHistoryByIdWindowed

# This is an autogenerated file from the command "q2 generate_hq_api" and will be overwritten if run again

"""
Get host account history by host account id

Sample response (may differ slightly in your environment)

.. code-block:: xml

    <Q2API HqVersion="4.5.0.6023" HqAssemblyVersion="4.5.7849.32550" ServerDateTime="2021-08-17T18:42:47.9050136+00:00" AuditId="636017">
      <Result>
        <ErrorCode ErrorType="Success">0</ErrorCode>
        <ErrorDescription/>
        <HydraErrorReturnCode>0</HydraErrorReturnCode>
      </Result>
      <Data>
        <AllHostTransactions>
          <Transactions>
            <!--AllTransactionType indicates type of transaction (0 = Posted, 1 = Memo, 2 = Insufficient Funds -->
            <AllTransactionType>0</AllTransactionType>
            <TransactionID>59</TransactionID>
            <HostAccountID>5006</HostAccountID>
            <PostDate>2021-02-04T20:55:15+00:00</PostDate>
            <TxnAmount>3891.2500</TxnAmount>
            <Description>N9848 Q2 SOFTWAR DIR DEP 268904 10230 06/01/18</Description>
            <HostTranNumber>033</HostTranNumber>
            <DorC>C</DorC>
            <ShowImage>false</ShowImage>
            <HostTranCodeID>1</HostTranCodeID>
            <HostTranCode>D</HostTranCode>
            <OfxTrnType>CREDIT</OfxTrnType>
            <OfxCheckNumHandling>2</OfxCheckNumHandling>
            <ShowTransactionItemDetail>false</ShowTransactionItemDetail>
            <SignedTxnAmount>3891.2500</SignedTxnAmount>
            <StatementDescription>N9848 Q2 SOFTWAR DIR DEP 268904 10230 06/01/18</StatementDescription>
          </Transactions>
          <MatchingTransactionCount>
            <Count>1</Count>
          </MatchingTransactionCount>
        </AllHostTransactions>
      </Data>
    </Q2API>

"""

from dataclasses import dataclass

from typing import List, Optional, Union

from lxml import etree


from lxml.objectify import FloatElement, StringElement, IntElement, BoolElement

from q2_sdk.core.q2_logging.logger import Q2LoggerType
from q2_sdk.hq.models.hq_response import HqResponse
from q2_sdk.hq.models.hq_credentials import HqCredentials
from q2_sdk.hq.models.hq_params.base import BaseParameter


from q2_sdk.hq.models.hq_params.q2_api import Q2ApiParamsObj
from q2_sdk.hq.models.hq_request.q2_api import Q2ApiRequest


[docs] class Operand: NE = "NE" EQ = "EQ" GE = "GE" LE = "LE" GT = "GT" LT = "LT" BeginsWith = "BeginsWith" EndsWith = "EndsWith" Contains = "Contains" IsNull = "IsNull" NotNull = "NotNull" IN = "IN"
[docs] class FilterItem(BaseParameter): def __init__( self, is_or_operator_not_and: bool, operand: Operand, parens_before: int, parens_after: int, field_name: Optional[str] = None, comparison_value: Optional[str] = None, not_before_paren: Optional[bool] = False, ): self.is_or_operator_not_and = is_or_operator_not_and self.field_name = field_name self.operand = operand self.comparison_value = comparison_value self.parens_before = parens_before self.parens_after = parens_after self.not_before_paren = not_before_paren
[docs] def serialize_as_xml(self): root = etree.Element("FilterItem") elem = etree.SubElement(root, "IsOrOperatorNotAnd") elem.text = str(self.is_or_operator_not_and.real) elem = etree.SubElement(root, "FieldName") elem.text = str(self.field_name) elem = etree.SubElement(root, "Operand") elem.text = str(self.operand) elem = etree.SubElement(root, "ComparisonValue") elem.text = str(self.comparison_value) elem = etree.SubElement(root, "ParensBefore") elem.text = str(self.parens_before) elem = etree.SubElement(root, "ParensAfter") elem.text = str(self.parens_after) elem = etree.SubElement(root, "NotBeforeParen") elem.text = str(self.not_before_paren.real) return root
[docs] def serialize_as_json(self): return { "IsOrOperatorNotAnd": self.is_or_operator_not_and, "FieldName": self.field_name, "Operand": self.operand, "ComparisonValue": self.comparison_value, "ParensBefore": self.parens_before, "ParensAfter": self.parens_after, "NotBeforeParen": self.not_before_paren, }
[docs] class OptionalFilter(BaseParameter): def __init__(self, filter_item: Optional[List[FilterItem]] = None): self.filter_item = filter_item
[docs] def serialize_as_xml(self): root = etree.Element("OptionalFilter") if self.filter_item is not None: for elem in self.filter_item: root.append(elem.serialize_as_xml()) return root
[docs] def serialize_as_json(self): return [x.serialize_as_json() for x in self.filter_item]
[docs] class SortItem(BaseParameter): def __init__(self, ascending_sort: bool, field_name: Optional[str] = None): self.field_name = field_name self.ascending_sort = ascending_sort
[docs] def serialize_as_xml(self): root = etree.Element("SortItem") elem = etree.SubElement(root, "FieldName") elem.text = str(self.field_name) elem = etree.SubElement(root, "AscendingSort") elem.text = str(self.ascending_sort.real) return root
[docs] def serialize_as_json(self): return { "FieldName": self.field_name, "AscendingSort": self.ascending_sort, }
[docs] class OptionalSort(BaseParameter): def __init__(self, sort_item: Optional[List[SortItem]] = None): self.sort_item = sort_item
[docs] def serialize_as_xml(self): root = etree.Element("OptionalSort") if self.sort_item is not None: for elem in self.sort_item: root.append(elem.serialize_as_xml()) return root
[docs] def serialize_as_json(self): return [x.serialize_as_json() for x in self.sort_item]
[docs] class ParamsObj(Q2ApiParamsObj): """Parameters definition for GetAccountHistoryByIdWindowed""" def __init__( self, logger: Q2LoggerType, host_account_id: int, page_size: int, page_number: int, perform_history_lookup: bool, perform_memo_lookup: bool, perform_nsf_lookup: bool, optional_filter: Optional[OptionalFilter] = None, optional_sort: Optional[OptionalSort] = None, hq_credentials: Optional[HqCredentials] = None, ): """ :param logger: Reference to calling request's logger (self.logger in your extension) :param host_account_id: Q2_HostAccount.HostAccountID :param page_size: The number of results to return per page :param page_number: The starting point of the page :param perform_history_lookup: If True the account information will be retrieved :param perform_memo_lookup: :param perform_nsf_lookup: :param optional_filter: :param optional_sort: OptionalSort object that contains a list of SortItem objects :param hq_credentials: Defaults to settings.HQ_CREDENTIALS """ super().__init__(logger, hq_credentials) self.request_params.update({ "HostAccountId": host_account_id, "PageSize": page_size, "PageNumber": page_number, "OptionalFilter": optional_filter, "OptionalSort": optional_sort, "PerformHistoryLookup": perform_history_lookup, "PerformMemoLookup": perform_memo_lookup, "PerformNsfLookup": perform_nsf_lookup, })
[docs] @dataclass class MatchingTransactionCount: Count: IntElement
[docs] @dataclass class Transactions: AllTransactionType: IntElement Description: StringElement DorC: StringElement HostAccountID: IntElement HostTranCode: StringElement HostTranCodeID: IntElement HostTranNumber: StringElement OfxCheckNumHandling: IntElement OfxTrnType: StringElement PostDate: StringElement ShowImage: BoolElement ShowTransactionItemDetail: BoolElement SignedTxnAmount: FloatElement StatementDescription: StringElement TransactionID: IntElement TxnAmount: FloatElement
[docs] @dataclass class AllHostTransactions: MatchingTransactionCount: Union[ MatchingTransactionCount, List[MatchingTransactionCount] ] Transactions: Union[Transactions, List[Transactions]]
[docs] @dataclass class Data: AllHostTransactions: Union[AllHostTransactions, List[AllHostTransactions]]
[docs] class ResultNode: def __init__(self): self.Data = Data()
[docs] class HqResponse(HqResponse): def __init__(self, raw_response: Union[str, dict]): super().__init__(raw_response) self.result_node: ResultNode = None
[docs] async def execute(params_obj: ParamsObj, use_json=False, **kwargs) -> HqResponse: """ This is the default way to submit the request to HQ. In theory, both json and soap payloads are equally accepted by HQ, though several variables may affect that (HQ version, Q2SDK implementation bugs, etc). This should not affect anything about the way your code deals with the data. In fact, the only difference to consuming extensions is the logging. Basically, call this with default parameters unless you find a compelling reason not to. :param params_obj: Object containing everything necessary to call this HQ endpoint :param use_json: If True, will call HQ's .ashx (json) endpoint instead of .asmx (soap) """ request = Q2ApiRequest("GetAccountHistoryByIdWindowed", use_json=use_json, **kwargs) return await request.execute(params_obj, **kwargs)
[docs] async def get_soap(params_obj: ParamsObj, **kwargs) -> HqResponse: """Deprecated. Please use execute instead""" params_obj.logger.warning( "GetAccountHistoryByIdWindowed.get_soap is deprecated. Please use GetAccountHistoryByIdWindowed.execute instead." ) return await execute(params_obj, **kwargs)
[docs] async def get_json(params_obj: ParamsObj, **kwargs) -> HqResponse: """Deprecated. Please use execute instead""" params_obj.logger.warning( "GetAccountHistoryByIdWindowed.get_json is deprecated. Please use GetAccountHistoryByIdWindowed.execute instead." ) return await execute(params_obj, use_json=True, **kwargs)
[docs] def build_json(params_obj: ParamsObj): return Q2ApiRequest.build_json(params_obj)
[docs] def build_soap(params_obj: ParamsObj): return Q2ApiRequest("GetAccountHistoryByIdWindowed", use_json=False).build_soap( params_obj )