Skip to content

Commit

Permalink
Fix Mouser price format
Browse files Browse the repository at this point in the history
  • Loading branch information
SergeoLacruz committed Jun 1, 2024
1 parent aad39d7 commit c260a64
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions inventree_supplier_panel/supplier_panel.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
import requests
import json
import os
import locale
import re


class SupplierCartPanel(PanelMixin, SettingsMixin, InvenTreePlugin, UrlsMixin):
Expand Down Expand Up @@ -372,11 +372,10 @@ def get_mouser_partdata(self, sku):
# We need a Mouser specific modification to the price answer because they put
# funny things inside like an EURO sign and they use , instead of .
def reformat_mouser_price(self, price):
locale.setlocale(locale.LC_NUMERIC, 'de_DE.UTF-8')
locale.setlocale(locale.LC_MONETARY, 'de_DE.UTF-8')
conv = locale.localeconv()
new_price = locale.atof(price.strip(conv['currency_symbol']))
return new_price
price = price.replace(',', '.')
non_decimal = re.compile(r'[^\d.]+')
price = float(non_decimal.sub('', price))
return price

# ------------------------------- get_mouser_package --------------------------
# Extracts the available packages from the Mouser part data json
Expand Down Expand Up @@ -472,12 +471,13 @@ def get_digikey_partdata(self, sku):
# replace invalid characters in the partnumber
sku = quote(sku)
url = f'https://api.digikey.com/Search/v3/Products/{sku}'
country_code = self.COUNTRY_CODES[InvenTreeSetting.get_setting('INVENTREE_DEFAULT_CURRENCY')]
header = {
'Authorization': f"{'Bearer'} {self.get_setting('DIGIKEY_TOKEN')}",
'X-DIGIKEY-Client-Id': self.get_setting('DIGIKEY_CLIENT_ID'),
'Content-Type': 'application/json',
'X-DIGIKEY-Locale-Currency': InvenTreeSetting.get_setting('INVENTREE_DEFAULT_CURRENCY'),
'X-DIGIKEY-Locale-Site': 'DE',
'X-DIGIKEY-Locale-Site': country_code,
'X-DIGIKEY-Locale-Language': 'EN'
}
response = self.get_request(url, headers=header)
Expand Down

0 comments on commit c260a64

Please sign in to comment.