Skip to content

Commit

Permalink
Handle non existing price data (#538)
Browse files Browse the repository at this point in the history
  • Loading branch information
Bouni authored Sep 17, 2024
1 parent b0cef60 commit f2b5919
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions partselector.py
Original file line number Diff line number Diff line change
Expand Up @@ -645,6 +645,8 @@ def update_subcategories(self, *_):
def get_price(self, quantity, prices) -> float:
"""Find the price for the number of selected parts accordning to the price ranges."""
price_ranges = prices.split(",")
if not price_ranges[0]:
return -1.0
min_quantity = int(price_ranges[0].split("-")[0])
if quantity <= min_quantity:
range, price = price_ranges[0].split(":")
Expand Down Expand Up @@ -680,8 +682,13 @@ def populate_part_list(self, parts, search_duration):
item = [str(c) for c in p]
pricecol = 8 # Must match order in library.py search function
price = round(self.get_price(len(self.parts), item[pricecol]), 3)
sum = round(price * len(self.parts), 3)
item[pricecol] = f"{len(self.parts)} parts: ${price} each / ${sum} total"
if price > 0:
sum = round(price * len(self.parts), 3)
item[pricecol] = (
f"{len(self.parts)} parts: ${price} each / ${sum} total"
)
else:
item[pricecol] = "Error in price data"
self.part_list.AppendItem(item)

def select_part(self, *_):
Expand Down

0 comments on commit f2b5919

Please sign in to comment.