""" Transaction Types Logic ======================= Manages the retrieval of transaction types relevant to the account and requested statement period. """ from ows_accounting.logic.samples import transaction_type_fixtures from ows_accounting.models import transaction_types as model from ows_accounting.presentation import transaction_types as presentation from ows_accounting.response import Response from ows_accounting.validation import validators def get_transaction_types(account_id, account_type, periods): """Retrieve list of transaction types for account and periods. Args: account_id (int): id of account. account_type (string): 'vendor' or 'subaccount'. periods (list): a list of string period ids. Returns: Response: list of transaction types. """ validation = validators.validate_account_type(account_type) if not validation: return validation periods = sorted(periods) trans_types = model.get_transaction_types_with_sales( account_id, account_type, periods[0], periods[-1]) return Response(dict(items=presentation.long_and_short_names(trans_types))) def get_sample_transaction_types(): """Sample response until we implement actual transaction types retrieval. Returns: dict: sample response containing transaction types. """ results = { 'items': transaction_type_fixtures.transaction_types} return results