API Reference

Convenience collection of all main service classes

class django_ctb.services.PartSatisfactionManager(*, part: Part, project_build: ProjectBuild)

Manages satisfaction of combined demand for parts in a project build. This is a receptacle in which to accumulate project parts which use a common part, then to assess the stock of said part (or it’s equivalents), finally creating reservations or shortages.

Use add_project_part to accumulate project parts, then use ensure_reservation to create a reservation (and inventory actions).

__init__(*, part: Part, project_build: ProjectBuild)

Provide a part and a project build. Then use add_project_part to add any project parts which call for the same part. Once all project parts are tabulated, call ensure_reservation to create the actual reservation.

add_project_part(*, project_part: ProjectPart)

Add a project part for consideration in this manager. Increases the number of needed parts, and tracks the project part itself for association to the reservation (should it come to pass).

ensure_reservation() ProjectBuildPartReservation

Idempotent creation of reservations for an individual part to satisfy build. Creates inventory actions to trace the reservation, and alters inventory line quantities to suit.

static find_equivalent_parts(*, part: Part, depth: int = 0, maxdepth: int = 5) set[Part]

Recursively searches for equivalent parts.

property unfulfilled: int

Number of parts required for the build which are not yet covered by reserved stock.

class django_ctb.services.ProjectBuildPartReservationService

Handles deletion of Project Build Part Reservations and restocking of inventory lines

delete_reservation(reservation: ProjectBuildPartReservation)

Deletes reservation after crediting inventory lines and deleting inventory actions. Will not act on a utilized reservation.

delete_reservations(reservations: list[ProjectBuildPartReservation] | QuerySet)

Deletes reservations after crediting inventory lines and deleting inventory actions. Will not act on a utilized reservation.

class django_ctb.services.ProjectBuildService

Service for clearing and completing project builds.

cancel_build(build_pk)

Finds a project build by PK then removes any reservations or shortages associated with the project. Removes cleared status.

Ignores any project build which is marked completed.

clear_to_build(build_pk)

Finds a project build by PK then reserves sufficient stock of parts to complete a project, or—barring availability—reserves stock of parts which are pletiful enough to complete the project build and creates shortages for those unfortunate parts which have low stocks.

Ignores any project build which is completed.

complete_build(build_pk)

Finds a project build by PK then marks it complete. This will mark any reservation associated with the project as utilized. Will only find project builds which are not complete and have been cleared.

class django_ctb.services.ProjectVersionBomService

Downloads BOM from repo at specified commit and creates project parts for each line.

sync(project_version_pk)

Finds a project version by PK then downloads BOM from repository and creates project parts for each row. BOM rows which cannot be matched to any part in the system will be flagged with a missing_part_description. Parts available through supported vendors (Mouser) will be autopopulated provided the PartNum is known.

Rows referencing footprints which are configured with implicit project parts will cause additional project parts to be created to represent the implicit parts.

Upon completion of the sync process the commit hash where the BOM was found will be saved and the project version will be marked synced.

class django_ctb.services.VendorOrderService

Service for creating vendor orders, and seeing their fulfillment through to altering inventory stock. Provides traceability through inventory actions.

complete_order(order_pk)

Looks up a vendor order by PK then updates inventory lines for each part in the order, creates inventory action with change details. Marks vendor order as fulfilled.

Ignores any vendor order marked fulfilled.

generate_vendor_orders(build_pk)

Looks up a project build by PK then creates or updates vendor orders and order lines to cover shortfalls for the given project build. Searches for appropriate vendors for each part. Will silently ignore parts that don’t have vendors.

Ignores any project build which is completed.

Services for interacting with the Mouser Search API

class django_ctb.mouser.services.MouserPartService

Service for interacting with local instances of Mouser Part data

create_vendor_part(row: BillOfMaterialsRow) VendorPart

Creates new vendor part for a BOM row, initiates job to populate part data from Mouser API

class django_ctb.mouser.services.MouserService

Get data from the Mouser API to create parts

exception MissingPart

The part cannot be located in the Mouser Search API

populate(vendor_part_pk: int)

Populate given vendor part with data from Mouser Search API

Services for interacting with the GitHub API

class django_ctb.github.services.GithubService

Service for interacting with the GitHub API. Doesn’t use a client, just calls directly for these minimal public endpoints.

base_url: str = 'https://api.github.com'
get_commit_hash_for_ref(*, user: str, repo: str, commit_ref: str) str

Find the commit has for the given commit_ref. Uses the Github API to check, in this order, if commit_ref is:

  • A commit hash

  • A branch name

  • A tag

The commit hash will be derived from the resource it represents.