From 7e5f5351090c6bcc3d9ef213faad65449f6c416a Mon Sep 17 00:00:00 2001 From: eeintech Date: Thu, 12 Aug 2021 10:15:02 -0400 Subject: [PATCH 1/3] Updated link to manufacturer part using server hook implemented in https://github.com/inventree/InvenTree/pull/1947 --- kintree/config/settings.py | 2 +- kintree/database/inventree_api.py | 37 +++++++++++++++---------------- 2 files changed, 19 insertions(+), 20 deletions(-) diff --git a/kintree/config/settings.py b/kintree/config/settings.py index c362e720..8f72fc1b 100644 --- a/kintree/config/settings.py +++ b/kintree/config/settings.py @@ -10,7 +10,7 @@ version_info = { 'MAJOR_REVISION': 0, 'MINOR_REVISION': 4, - 'RELEASE_STATUS': 2, # Digit means stable version + 'RELEASE_STATUS': 3, # Digit means stable version } try: version = '.'.join([str(v) for v in version_info.values()]) diff --git a/kintree/database/inventree_api.py b/kintree/database/inventree_api.py index 619dcbc0..828f4848 100644 --- a/kintree/database/inventree_api.py +++ b/kintree/database/inventree_api.py @@ -388,11 +388,11 @@ def is_new_supplier_part(supplier_name: str, supplier_sku: str) -> bool: def create_manufacturer_part(part_id: int, manufacturer_name: str, manufacturer_mpn: str, description: str, datasheet: str) -> bool: ''' Create InvenTree manufacturer part - part_id: Part the manufacturer data is linked to - manufacturer: Company that manufactures the SupplierPart (leave blank if it is the sample as the Supplier!) - MPN: Manufacture part number - datasheet: Datasheet link - description: Descriptive notes field + part_id: Part the manufacturer data is linked to + manufacturer: Company that manufactures the SupplierPart (leave blank if it is the sample as the Supplier!) + MPN: Manufacture part number + datasheet: Datasheet link + description: Descriptive notes field ''' global inventree_api @@ -424,25 +424,24 @@ def create_manufacturer_part(part_id: int, manufacturer_name: str, manufacturer_ def create_supplier_part(part_id: int, manufacturer_name: str, manufacturer_mpn: str, supplier_name: str, supplier_sku: str, description: str, link: str) -> bool: ''' Create InvenTree supplier part - part_id: Part the supplier data is linked to - manufacturer_name: Manufacturer the supplier data is linked to - manufacturer_mpn: MPN the supplier data is linked to - supplier: Company that supplies this SupplierPart object - SKU: Stock keeping unit (supplier part number) - manufacturer: Company that manufactures the SupplierPart (leave blank if it is the sample as the Supplier!) - MPN: Manufacture part number - link: Link to part detail page on supplier's website - description: Descriptive notes field + part_id: Part the supplier data is linked to + manufacturer_name: Manufacturer the supplier data is linked to + manufacturer_mpn: MPN the supplier data is linked to + supplier: Company that supplies this SupplierPart object + SKU: Stock keeping unit (supplier part number) + manufacturer: Company that manufactures the SupplierPart (leave blank if it is the sample as the Supplier!) + MPN: Manufacture part number + link: Link to part detail page on supplier's website + description: Descriptive notes field ''' global inventree_api # Get Supplier ID supplier_id = get_company_id(supplier_name) - # Get Manufacturer ID - manufacturer_id = get_company_id(manufacturer_name) - if not manufacturer_id: - # Unset MPN + if not manufacturer_name or not manufacturer_mpn: + # Unset manufacturer data + manufacturer_name = None manufacturer_mpn = None if supplier_id: @@ -452,7 +451,7 @@ def create_supplier_part(part_id: int, manufacturer_name: str, manufacturer_mpn: supplier_part = SupplierPart.create(inventree_api, { 'part': part_id, - 'manufacturer': manufacturer_id, + 'manufacturer': manufacturer_name, 'MPN': manufacturer_mpn, 'supplier': supplier_id, 'SKU': supplier_sku, From cfa54baa1050dc2f8451b15312e9d48a2ee7b54b Mon Sep 17 00:00:00 2001 From: eeintech Date: Thu, 12 Aug 2021 11:08:48 -0400 Subject: [PATCH 2/3] Digi-Key API: raised logger output level to critical Reloading environmental variables when settings are changed --- kintree/kintree_gui.py | 1 + kintree/search/digikey_api.py | 6 +++--- poetry.lock | 2 +- pyproject.toml | 2 +- requirements.txt | 2 +- 5 files changed, 7 insertions(+), 6 deletions(-) diff --git a/kintree/kintree_gui.py b/kintree/kintree_gui.py index 48c9b6c2..29d8985a 100644 --- a/kintree/kintree_gui.py +++ b/kintree/kintree_gui.py @@ -110,6 +110,7 @@ def save_settings(user_settings: dict): } user_settings = {**user_settings, **new_settings} config_interface.dump_file(user_settings, settings.CONFIG_DIGIKEY_API) + digikey_api.setup_environment(force=True) if api_event == sg.WIN_CLOSED: search_api_window.close() diff --git a/kintree/search/digikey_api.py b/kintree/search/digikey_api.py index 22e09550..7d70eac3 100644 --- a/kintree/search/digikey_api.py +++ b/kintree/search/digikey_api.py @@ -29,7 +29,7 @@ def disable_api_logger(): # Digi-Key API logger - logging.getLogger('digikey.v3.api').setLevel(logging.WARNING) + logging.getLogger('digikey.v3.api').setLevel(logging.CRITICAL) # Disable DEBUG logging.disable(logging.DEBUG) @@ -44,8 +44,8 @@ def check_environment() -> bool: return True -def setup_environment() -> bool: - if not check_environment(): +def setup_environment(force=False) -> bool: + if not check_environment() or force: # SETUP the Digikey authentication see https://developer.digikey.com/documentation/organization#production digikey_api_settings = config_interface.load_file(settings.CONFIG_DIGIKEY_API) os.environ['DIGIKEY_CLIENT_ID'] = digikey_api_settings['DIGIKEY_CLIENT_ID'] diff --git a/poetry.lock b/poetry.lock index 42a1d6ed..691a6cfe 100644 --- a/poetry.lock +++ b/poetry.lock @@ -93,7 +93,7 @@ python-versions = ">=3.5" [[package]] name = "digikey-api" -version = "0.4.0" +version = "0.5.0" description = "Python client for Digikey API" category = "main" optional = false diff --git a/pyproject.toml b/pyproject.toml index 03e667c1..973b9ef0 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -12,7 +12,7 @@ keywords = ["inventree", "kicad", "component", "part", "create"] [tool.poetry.dependencies] python = ">=3.7,<3.10" -digikey-api = ">=0.4.0,<1.0" +digikey-api = ">=0.5.0,<1.0" fuzzywuzzy = ">=0.18.0,<1.0" inventree = ">=0.2.4,<1.0" multiprocess = ">=0.70.12.2,<0.71" diff --git a/requirements.txt b/requirements.txt index 75403295..aca6d638 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,4 +1,4 @@ -digikey-api>=0.4.0,<1.0 +digikey-api>=0.5.0,<1.0 fuzzywuzzy>=0.18.0,<1.0 inventree>=0.2.4,<1.0 multiprocess>=0.70.12.2,<0.71 From e6051865cbf01e0f60ac42f0626b1c6f1b6ba2d6 Mon Sep 17 00:00:00 2001 From: eeintech Date: Thu, 12 Aug 2021 11:54:14 -0400 Subject: [PATCH 3/3] Fixed bugs related to KiCad only part creation --- kintree/kintree_gui.py | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/kintree/kintree_gui.py b/kintree/kintree_gui.py index 29d8985a..09cd9433 100644 --- a/kintree/kintree_gui.py +++ b/kintree/kintree_gui.py @@ -537,7 +537,8 @@ def build_choices(items: dict, category: str, subcategory=None) -> list: for cat in items.keys(): if cat != category and cat != 'uncategorized': for key in items[cat].keys(): - more_choices.append(key) + if key not in choices and key not in more_choices: + more_choices.append(key) # Process uncategorized entries try: @@ -1032,13 +1033,13 @@ def main(): else: if not categories[0]: pseudo_categories = [symbol, None] - part_data = inventree_interface.translate_supplier_to_inventree(supplier=values['supplier'], - part_info=part_info, - categories=pseudo_categories) + part_data = inventree_interface.translate_form_to_inventree(part_info=part_info, + categories=pseudo_categories, + is_custom=CREATE_CUSTOM) else: - part_data = inventree_interface.translate_supplier_to_inventree(supplier=values['supplier'], - part_info=part_info, - categories=categories) + part_data = inventree_interface.translate_form_to_inventree(part_info=part_info, + categories=categories, + is_custom=CREATE_CUSTOM) part_data['parameters']['Symbol'] = symbol part_data['parameters']['Footprint'] = footprint if not part_data: @@ -1055,6 +1056,10 @@ def main(): part_data['IPN'] = part_data['name'] else: part_data['IPN'] = values['part_number'] + + # Replace spaces with hyphens + part_data['IPN'] = part_data['IPN'].replace(' ', '-') + if part_data['datasheet']: part_data['inventree_url'] = part_data['datasheet']