"""Utility functions for sales sheets generation.""" from salessheets.constants import field_const from salessheets.constants import localized_template def extract_price_data_for_localized_template(template_details, pricing_data): """Get localized pricing data. Extract name of field that should be used in the localized sheet and the template related pricing data from according field of ows-pricing response. Args: template_details (dict): Template details data from db for the product. pricing_data (dict): Response from ows-pricing for the product. Returns: tuple: A label that should be used in pricing part of the sheet and according pricing data. """ # For Overridden Prices, we always want to show a Price Code. store_pricing_tier = pricing_data.get( localized_template.STORE_PRICING_TIER_SOURCE) region_name = template_details.get(field_const.NAME) if 'custom' in store_pricing_tier.lower(): custom_price_label = '{price_field_name} {price_value}'.format( price_field_name=localized_template.NAME_PRICING_MAPPING.get( region_name), price_value=localized_template.PRICE ) return custom_price_label, pricing_data.get( localized_template.PRICE_CODE_SOURCE) region_price_data = localized_template.REGION_PRICING_MAPPING.get( region_name) sheet_label = '{price_field_name} {price_value}'.format( price_field_name=localized_template.NAME_PRICING_MAPPING.get( region_name), price_value=region_price_data.sheet_label ) price = pricing_data.get(region_price_data.price_source_field) return sheet_label, price def compose_address_for_localized( template_name, contact_data_format_mapping, contact_data): """ Composes the contact data string for Localized Sales Sheet. Args: template_name (str): name of template. contact_data_format_mapping (dict): mapping between template name and correct address string format. contact_data (dict): contact data containing the predefined list of fields. Returns: String: formatted string containing the address data specific for every country. """ contact_info_string = contact_data_format_mapping[template_name].format( apartment=contact_data[field_const.APARTMENT], street=contact_data[field_const.STREET], city=contact_data[field_const.CITY], state=contact_data[field_const.STATE], postal_code=contact_data[field_const.POSTAL_CODE], country=contact_data[field_const.COUNTRY], telephone=contact_data[field_const.TELEPHONE]) return contact_info_string