"""Model for ows-pricing.""" from oto import response from owsrequest import request from daemonJwtHandler import daemon_handler from salessheets import config from salessheets.connectors import loggly from salessheets.constants import errors from salessheets.constants import field_const from salessheets.constants import ows_services logger = loggly.get_current_logger() def get_pricing_for_pricing_family_by_product_and_store_ids( product_id, pricing_family_id, store_id): """Get pricing from ows-pricing. Args: product_id (int): product_id to get price code for. pricing_family_id (int): pricing_family_id to get price code for, usually 2 is used for digital products and 4 for physical. store_id (int): store_id to get price code for. Returns: Response: list of product's pricing data. """ url = '/pricing_family/{0}/product/{1}/store/{2}/pricing'.format( pricing_family_id, product_id, store_id) authorization = daemon_handler.daemon_handler( ows_services.OWS_PRICING) price_code_response = request.process( application=ows_services.APPLICATION_NAME, environment=config.ENVIRONMENT, method=ows_services.SERVICE_CALL_METHOD_GET, service_name=ows_services.OWS_PRICING, path=url, authorization_header=authorization, isDaemon=True) if price_code_response.status_code != 200: logger.warning( ('Could not retrieve pricing data for product_id {0} in store {1}' ' from ows-pricing.').format(product_id, store_id)) return response.create_error_response( status=price_code_response.status_code, message=price_code_response.content, code=errors.ERROR_CODE_OWS_PRICING_ERROR) return response.Response( message=price_code_response.json().get(field_const.ITEMS)[0])