""" Transaction Type Model ====================== Model function for getting transaction types from Snowflake. """ from ows_accounting.connectors import snowflake from ows_accounting.constants import header from ows_accounting.models.sql import transactiontype def get_transaction_types_with_sales( account_id, account_type, min_period, max_period): """Get transaction types that have sales. Args: account_id (int): account id. account_type (str): account type from GRASS. min_period (int): min accounting period id. max_period (int): max accounting period id. Returns: generator: generator of dictionaries of transaction type information. """ account_id_column = 'labelid' if account_type == header.GRASS_ACCOUNT_TYPE_SUBACCOUNT: account_id_column = 'subaccountid' sql = transactiontype.SQL_GET_TRANSACTIONTYPE transactiontype.SNOWFLAKE_TRANSACTIONTYPE_PARAMS.update( account_id_column=account_id_column) sql = sql.format(**transactiontype.SNOWFLAKE_TRANSACTIONTYPE_PARAMS) with snowflake.db_session() as session: results = session.execute( sql, {'account_id': account_id, 'min_period': min_period, 'max_period': max_period}).fetchall() results = [ {'transactiontypeabbr': result[1], 'transactiontypedesc': result[2]} for result in results] return results