"""Store Pricing Scheme logic.""" from pricing.api import cache from pricing.models import store_pricing_scheme def get_store_pricing_scheme_by_id(store_pricing_scheme_id): """Get one store pricing scheme by ID. Args: store_pricing_scheme_id (int): the ID of the store pricing scheme. Returns: response.Response: containing the store pricing scheme dict. """ result = store_pricing_scheme.get_store_pricing_scheme_by_id( store_pricing_scheme_id) if not result or not result.message: return result for tier in result.message['store_pricing_tiers']: for code in tier['store_pricing_tier_codes']: del code['territory_set'] return result def get_by_store_id(store_id): """Get a list of store pricing schemes by store ID. Args: store_id (int): the ID of the store. Returns: response.Response: containing the list of store pricing schemes. """ return store_pricing_scheme.get_by_store_id(store_id) def get_by_pricing_family_id(pricing_family_id): """Get a list of store pricing schemes by pricing family ID. Args: pricing_family_id (int): the ID of the pricing family. Returns: response.Response: containing the list of store pricing schemes. """ return store_pricing_scheme.get_by_pricing_family_id(pricing_family_id) def create_store_pricing_scheme(data): """Create a store pricing scheme. Args: data (dict): the data from which to create the store pricing scheme. Returns: response.Response: containing the created store pricing scheme dict. """ return store_pricing_scheme.create_store_pricing_scheme(data) def update_store_pricing_scheme_by_id(store_pricing_scheme_id, data): """Update a store pricing scheme. Args: store_pricing_scheme_id (int): the ID of the store pricing scheme. data (dict): the data from which to update the store pricing scheme. Returns: response.Response: containing the updated store pricing scheme. """ return store_pricing_scheme.update_store_pricing_scheme_by_id( store_pricing_scheme_id, data) @cache.memoize(3600) def get_by_pricing_family_and_store_id(pricing_family_id, store_id): """Get a store pricing scheme with pricing family id and store id. Args: pricing_family_id (int): the ID of the pricing family. store_id (int): the id of a store. Returns: response.Response: containing the store pricing scheme. """ return store_pricing_scheme.get_by_pricing_family_and_store_id( pricing_family_id, store_id)