Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle non existing price data #538

Merged
merged 1 commit into from
Sep 17, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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