Source code for q2_sdk.hq.models.policy_data

from dataclasses import asdict, dataclass, fields

EXCLUDED_COMPARISON_FIELDS = [
    "TransactionTypeID",
    "GroupID",
    "UserID",
    "CustomerID",
    "UserRoleID",
    "CompanyID",
]


[docs] @dataclass class BasePolicyData:
[docs] @classmethod def from_kwargs(cls, **kwargs): """Hydrates the class from kwargs, skipping any that aren't in the model""" return cls(**{k: kwargs[k] for k in kwargs if k in cls.__match_args__})
[docs] @dataclass class GeneratedTransactionRights(BasePolicyData): PolicyIdentifier: str = None TransactionTypeID: int = None ShortName: str = None GroupID: int = None CustomerID: int = None UserID: int = None UserRoleID: int = None CompanyID: int = None Enabled: bool = None Authorize: bool = None Cancel: bool = None Create: bool = None CreateRestricted: bool = None Update: bool = None View: bool = None LimitPerTransaction: float = None LimitPerDay: float = None LimitPerMonth: float = None LimitPerAcctPerDay: float = None CountPerDay: int = None CountPerMonth: int = None CountPerAcctPerDay: int = None DualApprovalLimit: float = None TokenRequiredLimit: float = None DraftLimit: float = None SourceAccounts: str = None DestinationAccounts: str = None RuleData: str = None def __eq__(self, other): valid_types = (int, bool, float) cls_fields = fields(self.__class__) valid = True for field in cls_fields: this_var = field.name if field.type in valid_types and this_var not in EXCLUDED_COMPARISON_FIELDS: self_value = getattr(self, this_var) other_value = getattr(other, this_var) valid = self_value == other_value if not valid: break return valid def __ne__(self, other): valid_types = (int, bool, float) cls_fields = fields(self.__class__) valid = False for field in cls_fields: this_var = field.name if field.type in valid_types and this_var not in EXCLUDED_COMPARISON_FIELDS: self_value = getattr(self, this_var) other_value = getattr(other, this_var) valid = self_value != other_value if valid: break return valid def __ge__(self, other): valid_types = (int, float) cls_fields = fields(self.__class__) valid = True for field in cls_fields: this_var = field.name self_value = getattr(self, this_var) other_value = getattr(other, this_var) if field.type in valid_types and this_var not in EXCLUDED_COMPARISON_FIELDS: if self_value is None: self_value = 0 if other_value is None: other_value = 0 valid = self_value >= other_value elif field.type is bool: if self_value is None: self_value = False if other_value is None: other_value = False if self_value == other_value: valid = True elif not self_value and other_value: valid = False if not valid: break return valid def __le__(self, other): valid_types = (int, float) cls_fields = fields(self.__class__) valid = True for field in cls_fields: this_var = field.name self_value = getattr(self, this_var) other_value = getattr(other, this_var) if field.type in valid_types and this_var not in EXCLUDED_COMPARISON_FIELDS: if self_value is None: self_value = 0 if other_value is None: other_value = 0 valid = self_value <= other_value elif field.type is bool: if self_value is None: self_value = False if other_value is None: other_value = False if self_value == other_value: valid = True elif self_value and not other_value: valid = False if not valid: break return valid
[docs] @dataclass class Subsidiaries(BasePolicyData): PolicyIdentifier: str = None SubsidiaryID: int = None Name: str = None
[docs] @dataclass class Account(BasePolicyData): PolicyIdentifier: str = None CustomerAccountID: int = None HostAccountID: int = None CustomerAccess: int = None PolicyReferenceID: int = None PolicyAccess: int = None AccountNumberInternal: str = None AccountNumberExternal: str = None AccountDesc: str = None StatusDescription: str = None ProductTypeName: str = None ProductName: str = None ABA: str = None IsExternalAccount: bool = None ProductTypeID: int = None ProductID: int = None
[docs] @dataclass class Features(BasePolicyData): PolicyIdentifier: str = None GroupID: int = None CustomerID: int = None UserID: int = None UserRoleID: int = None CompanyID: int = None PropertyID: int = None Enabled: bool = None PropertyName: str = None CategoryShortName: str = None CategoryDescription: str = None AllowView: bool = None AllowEdit: bool = None UserPropertyDataID: int = None
[docs] @dataclass class Data(BasePolicyData): PolicyIdentifier: str = None PolicyDataType: str = None PolicyTypeId: int = None Description: str = None HasPendingChange: int = None Enabled: bool = None IsTreasury: bool = None IsTemplate: bool = None IsOpenBanking: bool = None
[docs] @dataclass class User: ID: int GeneratedTransactionRights: list[GeneratedTransactionRights] = None TransactionRightsShortNameMapping: dict[str, GeneratedTransactionRights] = None Subsidiaries: list[Subsidiaries] = None Accounts: list[Account] = None AccountIdMapping: dict[int, Account] = None Features: list[Features] = None FeaturesShortNameMapping: dict[str, Features] = None Data: list[Data] = None
[docs] @dataclass class Customer: ID: int GeneratedTransactionRights: list[GeneratedTransactionRights] = None TransactionRightsShortNameMapping: dict[str, GeneratedTransactionRights] = None Subsidiaries: list[Subsidiaries] = None Accounts: list[Account] = None AccountIdMapping: dict[int, Account] = None Features: list[Features] = None FeaturesShortNameMapping: dict[str, Features] = None Data: list[Data] = None
[docs] @dataclass class Group: ID: int GeneratedTransactionRights: list[GeneratedTransactionRights] = None TransactionRightsShortNameMapping: dict[str, GeneratedTransactionRights] = None Subsidiaries: list[Subsidiaries] = None Accounts: list[Account] = None AccountIdMapping: dict[int, Account] = None Features: list[Features] = None FeaturesShortNameMapping: dict[str, Features] = None Data: list[Data] = None
[docs] @dataclass class Company: ID: int GeneratedTransactionRights: list[GeneratedTransactionRights] = None TransactionRightsShortNameMapping: dict[str, GeneratedTransactionRights] = None Subsidiaries: list[Subsidiaries] = None Accounts: list[Account] = None AccountIdMapping: dict[int, Account] = None Features: list[Features] = None FeaturesShortNameMapping: dict[str, Features] = None Data: list[Data] = None
[docs] @dataclass class UserRole: ID: int GeneratedTransactionRights: list[GeneratedTransactionRights] = None TransactionRightsShortNameMapping: dict[str, GeneratedTransactionRights] = None Subsidiaries: list[Subsidiaries] = None Accounts: list[Account] = None AccountIdMapping: dict[int, Account] = None Features: list[Features] = None FeaturesShortNameMapping: dict[str, Features] = None Data: list[Data] = None
[docs] @dataclass class PolicyData: User: User = None Customer: Customer = None Group: Group = None Company: Company = None UserRole: UserRole = None def to_dict(self) -> dict: pd_dict = {} # looping through each entity in PolicyData dataclass for entity in fields(self): # retrieving values assigned to that entity (ID, GeneratedTransactionRights, TransactionRightsShortNameMapping, etc) entity_info = getattr(self, entity.name) # if None, skip field. Otherwise, add the field name as a key in the dictionary if not entity_info: continue pd_dict[entity.name] = {} # converting values into a dictionary and adding it to pd_dict for policy, policy_details in asdict(entity_info).items(): pd_dict[entity.name][policy] = policy_details return pd_dict