Skip to content

Commit

Permalink
uniquely identify duplicate ids
Browse files Browse the repository at this point in the history
  • Loading branch information
Siliconrob committed Feb 26, 2024
1 parent 9ae5150 commit ffdbd90
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
10 changes: 9 additions & 1 deletion data_messages/Promotions.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import decimal
import uuid
from collections import Counter
from dataclasses import dataclass

import xmltodict
Expand Down Expand Up @@ -377,15 +379,20 @@ 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:
continue
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=[])),
Expand All @@ -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
8 changes: 7 additions & 1 deletion data_messages/RateModifications.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import decimal
import uuid
from collections import Counter
from dataclasses import dataclass
from decimal import Decimal

Expand Down Expand Up @@ -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=[]))
Expand All @@ -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

0 comments on commit ffdbd90

Please sign in to comment.