Skip to content

Commit

Permalink
Merge pull request #26 from cdwilson/cdwilson/configurable-ipns
Browse files Browse the repository at this point in the history
Add configuration settings for IPNs
  • Loading branch information
eeintech authored Mar 23, 2021
2 parents 114c6a9 + cfc51bd commit c92c7da
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 10 deletions.
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

0 comments on commit c92c7da

Please sign in to comment.