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

Add sanitization for the \x0a in the prices #173

Merged
merged 1 commit into from
Oct 14, 2023
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
13 changes: 9 additions & 4 deletions kintree/database/inventree_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -622,6 +622,13 @@ def create_supplier_part(part_id: int, manufacturer_name: str, manufacturer_mpn:
return False, False


def sanitize_price(price_in):
price = re.findall('\d+.\d+', price_in)[0]
price = price.replace(',', '.')
price = price.replace('\xa0', '')
return price


def update_price_breaks(supplier_part, price_breaks: dict) -> bool:
''' Update the Price Breaks associated with a supplier part '''
if not isinstance(supplier_part, SupplierPart):
Expand All @@ -643,8 +650,7 @@ def update_price_breaks(supplier_part, price_breaks: dict) -> bool:
price = price_breaks[quantity]
# remove everything but the numbers from the price break
if isinstance(price, str):
price = re.findall('\d+.\d+', price)[0]
price = price.replace(',', '.')
price = sanitize_price(price)
if quantity in price_breaks:
old_price_break.save(data={'price': price})
updated.append(quantity)
Expand All @@ -656,8 +662,7 @@ def update_price_breaks(supplier_part, price_breaks: dict) -> bool:
for quantity, price in price_breaks.items():
# remove everything but the numbers from the price break
if isinstance(price, str):
price = re.findall('\d+.\d+', price)[0]
price = price.replace(',', '.')
price = sanitize_price(price)
SupplierPriceBreak.create(inventree_api, {
'part': supplier_part.pk,
'quantity': quantity,
Expand Down
Loading