PhoenixKitCatalogue.Catalogue.Suppliers (PhoenixKitCatalogue v0.12.0)

Copy Markdown View Source

Suppliers — delivery companies linked to manufacturers via the many-to-many phoenix_kit_cat_manufacturer_suppliers table.

Same lifecycle as manufacturers: hard-delete only, "active" / "inactive" status.

Cross-module supplier resolution

resolve/1 and list_all/1 provide a unified view of suppliers across sources (local cat_suppliers + CRM when available). CRM access is guarded via Code.ensure_loaded? / function_exported? — the CRM module is an optional runtime dependency and may not be present.

Public surface is re-exported from PhoenixKitCatalogue.Catalogue.

Summary

Functions

Returns the current junction row for an item/supplier pair, or nil.

Returns a changeset for tracking supplier changes.

Hard-deletes a supplier from the database.

Fetches a supplier by UUID. Returns nil if not found.

Fetches a supplier by UUID. Raises Ecto.NoResultsError if not found.

Lists all suppliers from all available sources as normalized maps.

Lists all suppliers, ordered by name.

Returns the primary supplier-info row for an item, or nil if none is marked primary.

Resolves a supplier UUID to a unified map regardless of source.

Delegates to ItemSupplierInfos.revise_unit_cost/3.

Updates a supplier with the given attributes.

Functions

active_info_for(item_uuid, supplier_uuid)

Returns the current junction row for an item/supplier pair, or nil.

"Current" means valid_to is nil. This is the function warehouse calls to check whether a receipt line's unit price diverges from the catalogued cost for the same supplier.

change_supplier(supplier, attrs \\ %{})

Returns a changeset for tracking supplier changes.

create_supplier(attrs, opts \\ [])

Creates a supplier.

Required attributes

  • :name — supplier name (1-255 chars)

Optional attributes

  • :description, :website, :contact_info, :notes
  • :status"active" (default) or "inactive"
  • :data — flexible JSON map

delete_supplier(supplier, opts \\ [])

Hard-deletes a supplier from the database.

get_supplier(uuid)

@spec get_supplier(Ecto.UUID.t()) :: PhoenixKitCatalogue.Schemas.Supplier.t() | nil

Fetches a supplier by UUID. Returns nil if not found.

get_supplier!(uuid)

Fetches a supplier by UUID. Raises Ecto.NoResultsError if not found.

list_all(opts \\ [])

@spec list_all(keyword()) :: [map()]

Lists all suppliers from all available sources as normalized maps.

Each entry has keys :uuid, :name, :email, :phone, :website, :source (:crm_company | :crm_contact | :local). CRM companies then CRM contacts are listed first (when available), then local suppliers ordered by name.

CRM access is guarded — when PhoenixKitCRM.PartyRoles is not loaded, only local suppliers are returned.

list_suppliers(opts \\ [])

@spec list_suppliers(keyword()) :: [PhoenixKitCatalogue.Schemas.Supplier.t()]

Lists all suppliers, ordered by name.

Options

  • :status — filter by status (e.g. "active", "inactive").

primary_for_item(item_uuid)

@spec primary_for_item(Ecto.UUID.t()) ::
  PhoenixKitCatalogue.Schemas.ItemSupplierInfo.t() | nil

Returns the primary supplier-info row for an item, or nil if none is marked primary.

resolve(uuid)

@spec resolve(Ecto.UUID.t()) :: {:ok, map()} | :error

Resolves a supplier UUID to a unified map regardless of source.

Returns {:ok, map} with keys :uuid, :name, :email, :phone, :website, :source (:crm | :local), or :error when the supplier cannot be found in any source.

The CRM branch reports the generic :crm tag rather than :crm_company / :crm_contactPhoenixKitCRM.PartyRoles.get_supplier/1 resolves either roleable type in one call but its return shape doesn't say which; list_all/1 (backed by per-type role listings) is the source for the more specific tags used elsewhere in this module.

CRM lookup is guarded — when PhoenixKitCRM.PartyRoles is not loaded (the CRM module is an optional runtime dependency), the CRM path is skipped and only local suppliers are checked.

revise_unit_cost(info, new_cost, opts \\ [])

Delegates to ItemSupplierInfos.revise_unit_cost/3.

This is the stable public surface that warehouse and other consumers should call. See ItemSupplierInfos.revise_unit_cost/3 for full documentation.

update_supplier(supplier, attrs, opts \\ [])

Updates a supplier with the given attributes.