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 configuration settings for IPNs #26

Merged
merged 1 commit into from
Mar 23, 2021
Merged
Show file tree
Hide file tree
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
32 changes: 22 additions & 10 deletions common/part_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,32 @@


def generate_part_number(category: str, part_pk: int) -> str:
''' Generate Internal Part Number (IPN) based on category '''
CATEGORY_CODES = config_interface.load_file(settings.CONFIG_CATEGORIES)['CODES']

for key in CATEGORY_CODES.keys():
if key in category:
break
''' Generate Internal Part Number (IPN) '''
try:
category_id = CATEGORY_CODES[key]
unique_id = str(part_pk).zfill(6)
variant_id = '00'
ipn = str(part_pk).zfill(settings.IPN_UNIQUE_ID_LENGTH)
except:
return None

return f'{category_id}-{unique_id}-{variant_id}'
if settings.IPN_USE_FIXED_PREFIX:
prefix_id = settings.IPN_PREFIX
else:
CATEGORY_CODES = config_interface.load_file(settings.CONFIG_CATEGORIES)['CODES']

for key in CATEGORY_CODES.keys():
if key in category:
break
try:
prefix_id = CATEGORY_CODES[key]
except:
return None

if prefix_id:
ipn = '-'.join([prefix_id, ipn])

if settings.IPN_USE_VARIANT_SUFFIX:
ipn = '-'.join([ipn, settings.IPN_VARIANT_SUFFIX])

return ipn

def compare(new_part_parameters: dict, db_part_parameters: dict, include_filters: list) -> bool:
''' Compare two InvenTree parts based on parameters (specs) '''
Expand Down
8 changes: 8 additions & 0 deletions config/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,14 @@ def create_user_config_files():
CONFIG_PARAMETERS_FILTERS = os.path.join(
CONFIG_USER_FILES, 'parameters_filters.yaml')

# INTERNAL PART NUMBERS
IPN_UNIQUE_ID_LENGTH = 6
IPN_USE_FIXED_PREFIX = False
if IPN_USE_FIXED_PREFIX:
IPN_PREFIX = ''
IPN_USE_VARIANT_SUFFIX = True
if IPN_USE_VARIANT_SUFFIX:
IPN_VARIANT_SUFFIX = '00'

# DIGI-KEY
# API storage path
Expand Down