Voile.Utils.ItemHelper (Voile v0.1.27)

Copy Markdown View Source

Summary

Functions

Extracts the barcode prefix from a collection UUID. The barcode prefix is the last 12 characters of the UUID (the final block).

Generate a compact barcode string from an item_code.

Generates a unique collection UUID that doesn't collide with existing barcode prefixes. Takes a function that checks if a barcode prefix exists and generates new UUIDs until a unique one is found.

Functions

default_item_params(collection_id, location_id, index)

extract_barcode_prefix(collection_id)

Extracts the barcode prefix from a collection UUID. The barcode prefix is the last 12 characters of the UUID (the final block).

Examples

iex> extract_barcode_prefix("b371e6aa-3fb1-48cf-8439-90373dfcd91a")
"90373dfcd91a"

iex> extract_barcode_prefix("invalid")
nil

generate_barcode_from_item_code(item_code)

Generate a compact barcode string from an item_code.

New Format (preferred for new items)

Combines unix timestamp (milliseconds) + collection UUID segment + item index. Example: 17738990974338c87c8d23358001

  • 1773899097433 = unix timestamp in milliseconds
  • 8c87c8d23358 = last 12 chars of collection UUID
  • 001 = item index (padded to 3 digits)

Old Format (backward compatibility)

Falls back to extracting UUID last block + sequence for older item_codes. Example: 8c87c8d23358001

Item Code Format

Expected: unit-type-collection_uuid-timestamp-index Example: curatorian-book-c1fcfbee-8674-4ee1-bc30-8c87c8d23358-1773899097433-000

generate_inventory_code(unit, type, collection, sequential_number)

generate_item_code(unit, type, collection, time_identifier, index)

generate_unique_collection_uuid(check_exists_fn, max_attempts \\ 100)

Generates a unique collection UUID that doesn't collide with existing barcode prefixes. Takes a function that checks if a barcode prefix exists and generates new UUIDs until a unique one is found.

Parameters

  • check_exists_fn: A function that takes a barcode prefix and returns true if it exists
  • max_attempts: Maximum number of attempts (default: 100)

Returns

  • - A unique UUID
  • - If unable to find unique UUID after max attempts