Skip to content

Catalogue 0.1.10: Smart catalogues and discounts

Catalogue 0.1.10 adds smart catalogues, for items such as delivery whose cost depends on other catalogues, and a discount that applies after the markup.

Smart catalogues

The catalogue form gets a Kind choice between standard catalogues, whose items are priced directly, and smart ones, whose items reference other catalogues. A smart item has a Catalogue Rules section: tick the catalogues it applies to and give each a value in Percent (%) or Flat, with a Default Value and Default Unit for blank rows. The module stores the rules; turning them into an order price is left to the app. A catalogue that smart items refer to cannot be deleted for good.

Discounts and fixes

A catalogue has a Discount Percentage (0 to 100), applied after the markup, and an item can override it with Discount Override (%). Buttons show Saving… or Deleting… while they work, and a malformed delete request no longer crashes the page.

Upgrading

Needs PhoenixKit 1.7.102 or later for the V102 migration: run mix phoenix_kit.update first. Existing catalogues become standard ones with no discount.

Full release notes: Catalogue 0.1.10

0.1.10 · 20 April 2026

Added

  • Smart catalogues (kind: "smart") — catalogues whose items are priced as a rule-driven function of other catalogues. New CatalogueRule schema (phoenix_kit_cat_item_catalogue_rules) and put_catalogue_rules/3 replace-all API with duplicate detection, per-leg value/unit inheritance via CatalogueRule.effective/2, and smart_rules.synced activity logging (added/updated/removed counts). Requires phoenix_kit 1.7.102+ for the V102 migration.
  • Per-item discount override — nullable Item.discount_percentage (nil inherits the catalogue’s discount, any value including 0 overrides). Pricing chain is now base → markup → discount, exposed via Item.final_price/3, Item.effective_discount/2, Item.discount_amount/3, and the expanded Catalogue.item_pricing/1.
  • Smart-item defaults — Item.default_value / Item.default_unit as fallbacks when a CatalogueRule row has nil value/unit (lets a user set “5% across everything” once and override specific catalogues).
  • list_items_referencing_catalogue/1 + catalogue_reference_count/1 for warn-before-delete flows; permanently_delete_catalogue/2 now refuses with {:error, {:referenced_by_smart_items, count}} when smart items still reference the catalogue, unless force: true is passed.
  • list_catalogues(kind: :smart) filter; Catalogue.move_item_to_catalogue/3 for moving smart items across catalogues (categories don’t apply to smart items).
  • Scoped search: search_items/2 accepts :catalogue_uuids / :category_uuids filters composed via where dynamic; new scope_selector component pairs with it.
  • category_counts_by_catalogue/0 grouped-query helper.

Changed

  • Context split — extracted the monolithic catalogue.ex into 10 focused submodules (Rules, Search, Manufacturers, Suppliers, Links, Counts, PubSub, Translations, Helpers, ActivityLog). Public surface is unchanged — every caller still goes through Catalogue.* via defdelegate.
  • All form LiveViews (catalogue / category / item / manufacturer / supplier) migrated to Phoenix 1.7 component-style <.input> / <.select> / <.textarea> / <.checkbox> bindings. The multilang wrapper now scopes only translatable fields (name / description) — pricing, classification, and actions render as siblings so a language switch doesn’t re-mount them.

Fixed

  • Replace raising confirm_delete!/1 with a safe case-match + unexpected_confirm_event/2 fallback across all 5 delete handlers (item / category / catalogue / manufacturer / supplier). Malformed push events flash + log instead of crashing the LV.
  • Catalogue.ActivityLog.log/1 now rescues — activity-logging failures no longer crash the primary mutation, matching the AGENTS.md contract.
  • New log_operation_error/3 helper in both admin LVs — structured logs carrying actor_uuid, entity_type, entity_uuid, and Ecto.Changeset.traverse_errors-expanded field/message pairs so production incidents can be debugged from the log alone.
  • Search task-exit logs now include query, offset, and catalogue_uuid.
  • phx-disable-with on 9 destructive-action buttons (trash / restore on catalogue + category + item tables and cards) to prevent double-mutation on slow networks.

Catalogue 0.1.10. Install or update: {:phoenix_kit_catalogue, "~> 0.1"}, then mix deps.get && mix phoenix_kit.update. Full history: CHANGELOG.