"""Payment Model Model function for getting payment information. """ from ows_accounting import response from ows_accounting.models.sql import payment as payment_sql from ows_accounting.utils import mysql def _fetchall(sql, **args): """Query database and fetch all result. Args: sql (str): sql query. args (dict): dictionary of parameters. Example: dict(vendor_id=vendor_id) Returns: tuple: all rows of tuple of results. None if no result found. """ with mysql.db_session() as session: result = session.execute(sql, args) return result.fetchall() def get_vendor_payments(vendor_id, periods): """Get payments info by vendor_id. Args: vendor_id (int): vendor_id. periods (list): list of accounting periods. Returns: Response object: Response object with list of payment info entries. for vend_contact_id. 404 response if not found. """ if periods: result = _fetchall( payment_sql.SQL_GET_VENDOR_PAYMENTS, vendor_id=vendor_id, periods=periods) if result: return response.Response({'items': result}) return response.Response({'items': []})