From 7c39d45ed7e8d48f0f48b596c780c0f0b5093032 Mon Sep 17 00:00:00 2001 From: T0jan Date: Mon, 29 Jan 2024 17:13:55 +0100 Subject: [PATCH 1/5] fix pricing requests for TME --- kintree/search/tme_api.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/kintree/search/tme_api.py b/kintree/search/tme_api.py index 55117b4a..43f9cae7 100644 --- a/kintree/search/tme_api.py +++ b/kintree/search/tme_api.py @@ -53,7 +53,7 @@ def setup_environment(force=False) -> bool: # Based on TME API snippets mentioned in API documentation: https://developers.tme.eu/documentation/download # https://github.com/tme-dev/TME-API/blob/master/Python/call.py -def tme_api_request(endpoint, tme_api_settings, part_number, api_host='https://api.tme.eu', format='json'): +def tme_api_request(endpoint, tme_api_settings, part_number, api_host='https://api.tme.eu', format='json', **kwargs): TME_API_TOKEN = tme_api_settings.get('TME_API_TOKEN', None) TME_API_SECRET = tme_api_settings.get('TME_API_SECRET', None) @@ -61,6 +61,8 @@ def tme_api_request(endpoint, tme_api_settings, part_number, api_host='https://a params['Country'] = tme_api_settings.get('TME_API_COUNTRY', 'US') params['Language'] = tme_api_settings.get('TME_API_LANGUAGE', 'EN') params['SymbolList[0]'] = part_number + if kwargs.get('currency', None): + params['Currency'] = kwargs.get('currency') if not TME_API_TOKEN and not TME_API_SECRET: TME_API_TOKEN = os.environ.get('TME_API_TOKEN', None) TME_API_SECRET = os.environ.get('TME_API_SECRET', None) @@ -136,7 +138,7 @@ def search_product(response): part_info['parameters'][param['ParameterName']] = param['ParameterValue'] # query the prices - response = download(tme_api_request('/Products/GetPrices', tme_api_settings, part_number)) + response = download(tme_api_request('/Products/GetPrices', tme_api_settings, part_number, currency='USD')) # check if accidentally no data returned if response is None or response['Status'] != 'OK': return part_info From 296fd916d4602be4ae623613292587f6fa796951 Mon Sep 17 00:00:00 2001 From: T0jan Date: Tue, 30 Jan 2024 15:45:42 +0100 Subject: [PATCH 2/5] Make the MPN checks more descriptive --- kintree/gui/views/main.py | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/kintree/gui/views/main.py b/kintree/gui/views/main.py index edc41941..a8f24788 100644 --- a/kintree/gui/views/main.py +++ b/kintree/gui/views/main.py @@ -360,15 +360,20 @@ def run_search(self, e): self.push_data() self.page.splash.visible = False - if not self.data['manufacturer_part_number'] and not self.data['custom_part']: + if not self.data['supplier_part_number'] and not self.data['custom_part']: self.show_dialog( d_type=DialogType.ERROR, message='Part not found', ) + elif not self.data['manufacturer_part_number']: + self.show_dialog( + d_type=DialogType.ERROR, + message='Found part has no manufacturer part number', + ) elif self.data['searched_part_number'].lower() != self.data['manufacturer_part_number'].lower(): self.show_dialog( d_type=DialogType.WARNING, - message='Found part number does not match the requested part number', + message='Found manufacturer part number does not match the requested part number', ) self.page.update() return @@ -915,7 +920,7 @@ def check_snapeda(self, e): if not data_from_views.get('Part Search', {}).get('manufacturer_part_number', ''): self.show_dialog( d_type=DialogType.ERROR, - message='Missing Part Data', + message='Missing Manufacturer Part Number', ) return @@ -1203,7 +1208,7 @@ def create_part(self, e=None): part_number = data_from_views['Part Search'].get('manufacturer_part_number', None) if not custom: if not part_number: - self.show_dialog(DialogType.ERROR, 'Missing Part Number') + self.show_dialog(DialogType.ERROR, 'Missing Manufacturer Part Number') return else: # Update IPN (later overwritten) From 80c60b8ccbf2f3ae539208e316c7cf37ad77ae37 Mon Sep 17 00:00:00 2001 From: eeintech Date: Sat, 3 Feb 2024 14:43:57 -0500 Subject: [PATCH 3/5] Fix #205 --- kintree/database/inventree_interface.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kintree/database/inventree_interface.py b/kintree/database/inventree_interface.py index a065f6e7..27992491 100644 --- a/kintree/database/inventree_interface.py +++ b/kintree/database/inventree_interface.py @@ -457,7 +457,7 @@ def inventree_fuzzy_company_match(name: str) -> str: for company_name in inventree_companies.keys(): cprint(f'{name.lower()} == {company_name.lower()} % {fuzz.partial_ratio(name.lower(), company_name.lower())}', silent=settings.HIDE_DEBUG) - if fuzz.partial_ratio(name.lower(), company_name.lower()) == 100: + if fuzz.partial_ratio(name.lower(), company_name.lower()) == 100 and len(name) == len(company_name): return company_name return name From 8e3179edf6ea8812bb6801246fb9645b49156779 Mon Sep 17 00:00:00 2001 From: eeintech Date: Sat, 3 Feb 2024 15:46:22 -0500 Subject: [PATCH 4/5] Fix configuration overwrite, fix sizing of Save button --- kintree/config/config_interface.py | 9 ++++++--- kintree/gui/views/common.py | 2 +- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/kintree/config/config_interface.py b/kintree/config/config_interface.py index 6d6c0849..df81cfdc 100644 --- a/kintree/config/config_interface.py +++ b/kintree/config/config_interface.py @@ -62,9 +62,12 @@ def load_config(path): template_data = load_file(os.path.join(path, filename)) try: user_data = load_file(os.path.join(path_to_user_files, filename)) - # Join user data to template data - user_settings = {**template_data, **user_data} - except TypeError: + if list(template_data.keys()) == list(user_data.keys()): + # Join user data to template data + user_settings = {**template_data, **user_data} + else: + user_settings = user_data + except (TypeError, AttributeError): cprint(f'[INFO]\tCreating new {filename} configuration file', silent=silent) # Config file does not exists user_settings = template_data diff --git a/kintree/gui/views/common.py b/kintree/gui/views/common.py index c594df32..65c8dee1 100644 --- a/kintree/gui/views/common.py +++ b/kintree/gui/views/common.py @@ -17,7 +17,7 @@ 'dropdown_width': 600, 'dropdown_dense': False, 'searchfield_width': 300, - 'button_width': 100, + 'button_width': 110, 'button_height': 56, 'icon_size': 40, 'text_size': 16, From 1a385edc1f5dbfa0946b8b118d512fb3902c11b4 Mon Sep 17 00:00:00 2001 From: eeintech Date: Sat, 3 Feb 2024 15:57:02 -0500 Subject: [PATCH 5/5] Fix #192 --- kintree/config/config_interface.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kintree/config/config_interface.py b/kintree/config/config_interface.py index df81cfdc..acae3dc1 100644 --- a/kintree/config/config_interface.py +++ b/kintree/config/config_interface.py @@ -28,7 +28,7 @@ def dump_file(data: dict, file_path: str) -> bool: ''' Safe dump YAML file ''' with open(file_path, 'w') as file: try: - yaml.safe_dump(data, file, default_flow_style=False) + yaml.safe_dump(data, file, default_flow_style=False, allow_unicode=True) except yaml.YAMLError as exc: print(exc) return False