"""Interface for the ows-product-physical microservice.""" from oto import response from owsrequest import request as requests from pricing.constants import error from pricing.constants import service_name def add_change_history(product_id, store_id, new_price): """Add change history to reflect price update for a product. Args: product_id (int): the product identifier. store_id (int): the store id for which the price has changed. new_price (str): the new price code. Returns: response.Response: Indicates whether the change history was added. """ path = '/product/{product_id}/change_history'.format(product_id=product_id) data = { 'store_id': store_id, 'new_price': new_price, 'field_name': 'wholesale_price' } try: prod_phys_response = requests.post( service_name.OWS_PRODUCT_PHYSICAL, path, json=data) if prod_phys_response.status_code not in [200, 201]: return response.create_error_response( status=500, code=error.INTERNAL_ERROR, message='error writing product physical change history') return response.Response() except Exception as err: return response.create_error_response(500, err)