From ffdbd902a57c992604875da59ca2a4b68fc0df3c Mon Sep 17 00:00:00 2001 From: Robin Michael Date: Mon, 26 Feb 2024 10:02:34 -0600 Subject: [PATCH] uniquely identify duplicate ids --- data_messages/Promotions.py | 10 +++++++++- data_messages/RateModifications.py | 8 +++++++- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/data_messages/Promotions.py b/data_messages/Promotions.py index 8facf57..d93d77c 100644 --- a/data_messages/Promotions.py +++ b/data_messages/Promotions.py @@ -1,4 +1,6 @@ import decimal +import uuid +from collections import Counter from dataclasses import dataclass import xmltodict @@ -377,6 +379,7 @@ def read_promotions(file_args: DataHandlers.DataFileArgs) -> (list[Promotion], F if len(file_promotions) == 0: return [], None + promotion_ids = [] for promotion in get_safe_list(file_promotions): discount = glom(promotion, 'Discount', default=None) if discount is None: @@ -384,8 +387,12 @@ def read_promotions(file_args: DataHandlers.DataFileArgs) -> (list[Promotion], F stacks = glom(promotion, 'Stacking') stacking_type = stacks.get("@type") if stacks is not None else None + promotion_id = promotion.get("@id") + id_counts = Counter(promotion_ids) + if id_counts[promotion_id] > 0: + promotion_id = f'{promotion_id}_{uuid.uuid4()}' promotions.append(Promotion(results.external_id, - promotion.get("@id"), + promotion_id, DateRange.parse_ranges(glom(promotion, 'BookingDates.DateRange', default=[])), DateRange.parse_ranges(glom(promotion, 'CheckinDates.DateRange', default=[])), DateRange.parse_ranges(glom(promotion, 'CheckoutDates.DateRange', default=[])), @@ -398,4 +405,5 @@ def read_promotions(file_args: DataHandlers.DataFileArgs) -> (list[Promotion], F discount.get("@fixed_price"), stacking_type, xmltodict.unparse({"Promotion": promotion}))) + promotion_ids.append(promotion_id) return promotions, results diff --git a/data_messages/RateModifications.py b/data_messages/RateModifications.py index a49b3ba..2418d4e 100644 --- a/data_messages/RateModifications.py +++ b/data_messages/RateModifications.py @@ -1,4 +1,6 @@ import decimal +import uuid +from collections import Counter from dataclasses import dataclass from decimal import Decimal @@ -360,13 +362,16 @@ def read_rate_modifications(file_args: DataHandlers.DataFileArgs) -> (list[RateM if len(itinerary) == 0: return [], None + rate_ids = [] new_modifiers = [] - for itinerary in get_safe_list(itinerary): multiplier = glom(itinerary, 'ModificationActions.PriceAdjustment', default=None) if multiplier is None: continue rate_id = glom(itinerary, '@id') + id_counts = Counter(rate_ids) + if id_counts[rate_id] > 0: + rate_id = f'{rate_id}_{uuid.uuid4()}' booking_dates = DateRange.parse_ranges(glom(itinerary, 'BookingDates.DateRange', default=[])) checkin_dates = DateRange.parse_ranges(glom(itinerary, 'CheckinDates.DateRange', default=[])) checkout_dates = DateRange.parse_ranges(glom(itinerary, 'CheckoutDates.DateRange', default=[])) @@ -383,4 +388,5 @@ def read_rate_modifications(file_args: DataHandlers.DataFileArgs) -> (list[RateM stay_requires, booking_window, xmltodict.unparse({"ItineraryRateModification": itinerary}))) + rate_ids.append(rate_id) return new_modifiers, results