Skip to content

Commit

Permalink
Merge e605186 into c7fb58a
Browse files Browse the repository at this point in the history
  • Loading branch information
eeintech committed Aug 12, 2021
2 parents c7fb58a + e605186 commit 18168cf
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 33 deletions.
2 changes: 1 addition & 1 deletion kintree/config/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()])
Expand Down
37 changes: 18 additions & 19 deletions kintree/database/inventree_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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:
Expand All @@ -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,
Expand Down
20 changes: 13 additions & 7 deletions kintree/kintree_gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -536,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:
Expand Down Expand Up @@ -1031,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:
Expand All @@ -1054,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']

Expand Down
6 changes: 3 additions & 3 deletions kintree/search/digikey_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -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']
Expand Down
2 changes: 1 addition & 1 deletion poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -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
Expand Down

0 comments on commit 18168cf

Please sign in to comment.