mix phoenix_kit_crm.import_suppliers_from_catalogue (PhoenixKitCRM v0.3.3)

Copy Markdown View Source

Imports catalogue suppliers into CRM companies and grants them the supplier role. This is a one-time backfill task following the SAP-CVI pattern.

Behaviour

  • Dry-run by default: pass --apply to write changes.
  • Idempotent: rows with a non-null crm_company_uuid are skipped and reported as already-linked.
  • Catalogue-absent guard: if phoenix_kit_cat_suppliers does not exist the task exits with a clear message rather than crashing.
  • Inactive suppliers are still imported (they may appear on posted documents); they are flagged in the report.

Matching logic (per supplier row)

  1. Normalize the candidate email: regex-extract from free-text contact_info, downcase and trim.
  2. Normalize the website: strip scheme (https?://) and leading www., downcase.
  3. Match an existing CRM company by email first (citext equality), then by normalized website if no email match. Otherwise create a new company.

Usage

mix phoenix_kit_crm.import_suppliers_from_catalogue           # dry-run
mix phoenix_kit_crm.import_suppliers_from_catalogue --apply   # write

Summary

Functions

Extracts the first email-like token from a free-text contact_info string. Returns the downcased, trimmed email or nil.

Strips https?:// scheme and leading www. from a URL, then downcases. Returns nil for nil/empty input.

Functions

extract_email(text)

@spec extract_email(String.t() | nil) :: String.t() | nil

Extracts the first email-like token from a free-text contact_info string. Returns the downcased, trimmed email or nil.

normalize_website(url)

@spec normalize_website(String.t() | nil) :: String.t() | nil

Strips https?:// scheme and leading www. from a URL, then downcases. Returns nil for nil/empty input.