Files
Odoo-Modules/fusion_centralize_billing
gsinghpal 5605012245 fix(billing): importer review fixes — surface failures, validate, dedupe
Resolves findings from the post-build review:
- C1: a partial import was indistinguishable from success. action_run_import
  now logs failed rows at ERROR (survives nexa's log_level=warn) and the
  wizard shows red/amber banners with failed/skipped counts.
- H3: an unrecognized billing_cycle silently fell back to monthly (wrong
  plan AND price). Now raised per-row -> failed[], never silently mis-billed.
- M5: a NULL plan price silently became a $0 line. Prices now preserve
  NULL-vs-0.0; a missing price for the subscription's cycle is failed[].
- H2: post-connect query/schema errors now become a clean UserError, not a
  raw SQL traceback (matches the connection-error path).
- M4: per-row failures now record the exception type and log a traceback.
- MED#3: charge plan_id set explicitly False so re-runs re-assert the
  shadow-safe NULL even if it was changed between runs.
- HIGH-edge: re-run only rewrites x_fc_* on existing subs; partner_id/plan_id/
  line are set at creation only (never rewrite immutable fields).
- account_link: partner email match is now case-insensitive (=ilike) to avoid
  duplicate partners against a differently-cased pre-existing partner.

Shadow-safety invariant unchanged and re-confirmed. 52/52 green on odoo-trial.
2026-05-27 13:44:51 -04:00
..

Fusion Centralized Billing (fusion_centralize_billing)

Centralized billing engine that makes this Odoo 19 Enterprise instance the single billing brain for every NexaSystems service — NexaCloud hosting, NexaDesk chat, NexaMaps API, custom apps, and memberships. It replaces Lago and absorbs NexaCloud's home-grown Stripe billing into one customer ledger and one accounting system.

Design spec: docs/superpowers/specs/2026-05-27-nexa-billing-centralized-design.md

Status: SCAFFOLD. Models + security + the API auth shell are in place and the module installs. The usage engine, full inbound API, and webhook processor are stubs to be implemented from the writing-plans output.

Why this module is small

We build only the metering + integration layer. Everything financial — recurring invoicing, HST tax, proration, dunning, customer portal, credit notes, Stripe — is native Odoo Enterprise (sale_subscription, account_accountant, payment_stripe), already installed and running.

Design decisions (locked)

  1. Odoo fully replaces Lago (we build the metered-billing engine; Lago is decommissioned last).
  2. One unified res.partner per client; separate invoice per service.
  3. Apps drive, Odoo is the billing system of record — apps call the inbound API (as they call Lago today); Odoo bills and webhooks back.
  4. Odoo owns the billing catalog; apps own feature entitlements (shared plan_code).
  5. Pilot = NexaCloud, phased dual-run cutover.
  6. Aggregate-push usage ingestion (periodic counters, not a raw-event firehose).

Models (fusion.billing.*)

Model Purpose
fusion.billing.service One source app; bearer API key (hashed) + webhook config.
fusion.billing.account.link External account id → one res.partner (identity resolution).
fusion.billing.metric Billable metric + aggregation (sum/max/last/unique).
fusion.billing.charge Plan + metric → included quota + overage pricing.
fusion.billing.usage Aggregated per-period usage rollups (idempotent).
fusion.billing.webhook Outbound lifecycle event queue (HMAC + retry).
fusion.billing.reconciliation Dual-run Odoo-vs-app delta during cutover.

Odoo 19 note (verified): a subscription is a sale.order with is_subscription=True (plan_idsale.subscription.plan). There is no sale.subscription model. fusion.billing.usage.subscription_id therefore points at sale.order.

Inbound API

Lago-shaped REST under /api/billing/v1/*, bearer auth. Endpoints mirror NexaDesk's existing lago-client.ts so migration is a thin client swap. /health works today; the rest return 501 until implemented.

Relationship to fusion_api

fusion_api manages outbound provider keys (OpenAI, Maps, Twilio) + cost tracking — i.e. COGS. This module tracks customer revenue. Complementary: feed fusion_api cost into margin reporting; reuse its daily-rollup aggregation pattern.

Dependencies

account_accountant, sale_subscription, sale_management, payment_stripe.

Local dev

docker exec odoo-nexa-app odoo -d nexamain -u fusion_centralize_billing --stop-after-init
# tests (once added):
docker exec odoo-nexa-app odoo -d nexamain --test-enable --test-tags /fusion_centralize_billing -u fusion_centralize_billing --stop-after-init

Canadian English, CAD, HST via account.tax. New fields on native models use the x_fc_* prefix.