Skip to content

Odoo CRM guide

Connect an Odoo CRM to your Offertown program: referral leads flow into Odoo as CRM leads, and conversions flow back once the waiting period after a referred customer's activation has ended. Built entirely on the REST API — a small connector you control, no Offertown code inside your Odoo database.

Requirements

  • An approved Offertown partner account with an API key (oft_…) from the partner dashboard — keep it server-side, e.g. in ir.config_parameter or your connector’s settings.
  • Odoo 16 or newer. On odoo.sh or on-premise the connector is a small custom module; on Odoo Online (SaaS), where custom Python isn’t available, run the same logic as an external service talking to Odoo over its external API — note Odoo Online only exposes the external API on Custom plans.

How the integration fits together

FlowDirectionMechanism
Leads into OdooOffertown → OdooA scheduled action (ir.cron) polls the referral list endpoint and creates crm.lead records.
Conversions backOdoo → OffertownAn automated action fires when the waiting period after activation ends and calls the convert endpoint; if the contract later fails, it calls the cancel endpoint. A lead that is lost before a contract is closed with the close endpoint.

The join key is the Offertown referralId, stored in a custom field on the lead at import time. It travels with the record through your pipeline, so reporting the conversion later needs no fuzzy matching on emails or names.

Flow 1 — sync referrals into Odoo

GET/api/v1/partners/referrals

Run a scheduled action every 5–15 minutes that keeps a watermark of the last successful sync:

  1. Call the list endpoint with status=pending, dateFrom set to the watermark, dateTo set to the sync start time, and sortBy=createdAt&sortOrder=asc, paginating with page/pageSize. If the response reports pagination.truncated: true, split the window and repeat.
  2. For each referral whose referralId isn’t in Odoo yet, create a crm.lead using the mapping below. Put a unique constraint on x_offertown_referral_id so replays are harmless no-ops.
  3. Advance the watermark to the run’s dateTo only after the run completes successfully.

One subtlety: a referral can start as clicked and become pending later without its createdAt changing, and a friend who applies through the widget appears only once they confirm their email, so a creation-time watermark alone can miss late-identified leads. Add a periodic reconciliation pass (daily is fine) that re-queries status=pending over the full 90-day attribution window — the referralId dedupe makes it idempotent.

Offertown fieldOdoo crm.lead field
referralIdx_offertown_referral_id (custom, indexed) — the join key
referralCodex_offertown_referral_code (custom) — handy for support
—name (required by crm.lead) — e.g. “Offertown referral — ” + friendName
friendName / friendEmail / friendPhonecontact_name / email_from / phone
friendPostCode / friendAddress / friendCityzip / street / city — useful for serviceability checks
referrerName / referrerEmailx_offertown_referrer (custom) — who referred this lead
—source_id set to a fixed “Offertown Referral” utm.source, so referral pipeline performance is reportable inside Odoo

Two-way traceability: PATCH the referral’s externalSourceId with the Odoo lead ID after import (see the API reference). The optional capture fields (phone, address, sourceUrl) are present only when the friend provided them on the form. consentAt records the consent checkbox on Offertown-rendered forms; for programmatic captures that omit it, it is the submission timestamp rather than proof of consent.

Flow 2 — report conversions from Odoo

POST/api/v1/partners/referrals/{referralId}/convert

Attach an automated action to the end of your waiting period after activation (for example, 14 days after the customer’s service is activated), rather than to opportunity won or the contract signature. Odoo counts this period: Offertown does not see activation, so report the conversion when the period ends. The referral field lives on crm.lead, so propagate x_offertown_referral_id onto sale.order when the order is created from the opportunity. The action then calls:

Request body
{
  "conversionValue": 12999,
  "currency": "EUR",
  "externalTransactionId": "mydb-sale.order-4211",
  "metadata": { "planName": "Fiber 100", "customerId": "C-1" }
}
  • conversionValue is the customer’s monthly price, VAT included, in cents (EUR).
  • externalTransactionId is your order reference and the idempotency key. Retries with the same ID safely return the original result, so the action can retry on network errors without risking double rewards. Use a globally unique reference built from the database name and the sale.order database ID, as above — order names alone are not guaranteed to be unique.
  • Reusing a transaction ID against a different referral is rejected with 409 DUPLICATE_CONVERSION.
  • metadata is optional: a JSON object of up to 4096 characters. It is kept on the referral and shown to your reward approvers on the conversion’s card on the Rewards page. planName and customerId are the named keys; other keys are shown as sent. Sending metadata on convert replaces any metadata set earlier.
  • A lead closed because the friend did not become a customer, by your team in the dashboard or by Odoo with the close call below, has the status not_customer. Converting it answers 409 NO_PENDING_REFERRAL until your team reopens the lead in the dashboard.
  • On 429, honor Retry-After and retry — writes are limited to 30 per minute per IP, and conversion reporting to 60 per minute per partner.

What happens next: the conversion lands as a pending reward that you approve in the partner dashboard. Approval starts the hold — your program’s maturityDays, counted from the moment you approve, not from the conversion. During the hold you are not charged for the reward. Until the hold ends, a failed contract can be cancelled with the call below or in the dashboard; after it, the reward is owed and cancel answers 409 REWARD_MATURED. A new program starts with a 3-day hold, and you can set 0 to 90 days on Program Settings. With 0 days, an approval is final at once. Billing at maturity is described under money flow in the overview.

When your program gives the friend a reward, the conversion has two lines in the dashboard, the friend’s reward and the referrer’s, and you approve or reject each on its own. The referrer is paid for any signed contract; reject only the friend’s reward when the contract does not qualify for it. The friend’s reward is charged, with the referrer’s, only if you approve it, and you can still reject it until the referrer reward’s hold ends. Rejecting the referrer’s reward rejects the friend’s too. Both decisions are made in the dashboard only; the API does not approve or reject rewards.

“Approve” can be unavailable on both lines of a conversion that reads “Waiting for the friend to create their Offertown account”: the friend has not created their Offertown account yet, and the friend got an email asking them to. Rejecting the friend’s reward releases the referrer’s reward, which you can then approve.

When a contract fails

POST/api/v1/partners/referrals/{referralId}/cancel

If a contract you reported is later cancelled or terminated, call cancel with the same externalTransactionId you sent to convert. Offertown cancels the referrer’s reward, expires the friend’s reward if it hasn’t been used, and reverses the commission. The referral itself stays converted; reading it afterwards shows a rewardsCancelledAt field (epoch ms) that marks the cancellation.

Request body
{
  "externalTransactionId": "mydb-sale.order-4211",
  "reason": "Contract terminated by the customer",
  "referrerMessage": "The contract you recommended was cancelled, so no reward is due.",
  "friendMessage": "Your contract was cancelled within the first 30 days, so the offer does not apply."
}
Response — 200
{
  "data": {
    "referralId": "jx7…",
    "rewardsCancelled": 1,
    "idempotent": false
  }
}
  • externalTransactionId and reason are required, and no fields other than these four are accepted. externalTransactionId must match the one sent to convert (1–128 characters); reason is stored with the cancelled reward for your records (1–500 characters) and is never shown to the referrer or the friend.
  • referrerMessage and friendMessage are optional (1–500 characters each). referrerMessage is read only by the referrer and friendMessage only by the friend, as “Their reason: …” on their own pages. Without one, that person reads only that the reward was cancelled. A message is ignored when the call does not end that person’s reward, and a repeated call does not change it.
  • rewardsCancelled counts the rewards this call cancelled: the referrer’s and, if there is one, the friend’s. It is 0 when the conversion’s rewards had not been created yet; none will be.
  • Repeating the call returns 200 with idempotent: true and rewardsCancelled: 0, so the action can retry on network errors.
  • 409 REWARD_MATURED means a reward for this conversion is already owed: its hold period has ended, it has been paid, or it is being funded. Nothing was changed, and retrying won’t help. Send the case to a person; the reward stays payable under your partner agreement.
  • 409 NOT_CONVERTED means no conversion was reported for this referral. 409 TRANSACTION_MISMATCH means the externalTransactionId differs from the one sent to convert. 404 NOT_FOUND means the referral doesn’t exist or isn’t yours.
  • Cancellations count toward a limit of 60 referral writes per minute per partner; on 429, honor Retry-After.

When a lead is lost

POST/api/v1/partners/referrals/{referralId}/close

When Odoo marks a lead as lost before any contract is signed, call close so the lead does not stay pending on Offertown. It does what closing the lead on the Leads page of your dashboard does: the referral becomes not_customer, the referrer and the friend each get an email that the application ended without a reward, and no reward or charge is created. Send it only for a lead that is still pending; a contract that fails after convert is cancelled with the call above.

Request body
{
  "reason": "outside_service_area",
  "note": "The address is outside our network"
}
  • reason is required: outside_service_area, did_not_sign, already_customer, duplicate, not_eligible or other. Map Odoo’s lost reasons onto these. The REST API reference lists which reason the referrer and the friend are shown.
  • note is optional, at most 500 characters, and required when reason is other. Your team reads it on the Leads page; the referrer and the friend never see it.
  • Repeating the call with the same reason returns 200 with idempotent: true and sends no second email, so the action can retry on network errors. A different reason answers 409 ALREADY_CLOSED.
  • 409 ALREADY_CONVERTED, 409 EXPIRED and 409 NOT_PENDING mean the lead is not pending, and nothing was changed. 404 NOT_FOUND means the referral doesn’t exist or isn’t yours.
  • The API does not reopen a lead. A lead closed by mistake is reopened by an Admin of your team on the Leads page.
  • Closes count toward the limit of 60 referral writes per minute per partner; on 429, honor Retry-After.

Rewards

Odoo builds nothing for rewards. When a reward matures, Offertown charges you for it and credits it to the referrer’s Offertown balance, which they spend on brand codes from other brands, not with you. Your staff have nothing to redeem, and Odoo needs no referrer records, reward tracking or discount lines.

Capturing leads on your own Odoo website

POST/api/v1/partners/referrals

If you host the referral signup form yourself (for example an Odoo website form), configure your program’s partner-hosted signup URL in the dashboard: referral links then redirect to your page with ?ref_code=… attached. Capture the code with the form and register the lead server-side:

Request body
{
  "referrerIdentifier": "a1b2c3d4",
  "friendEmail": "ana@example.com",
  "friendName": "Ana",
  "externalSourceId": "odoo-lead-4211"
}

referrerIdentifier is the ref_code from the URL, and externalSourceId is your crm.lead ID, for traceability. Copy the referralId from the response into the lead’s x_offertown_referral_id — Flow 2 needs it to report the conversion later. This replaces Flow 1 for leads you capture yourself: the referral is created attributed and already in your CRM. Partners using the embeddable widget or Offertown-hosted forms instead pick leads up via Flow 1 polling.

Testing the loop end-to-end

  1. Create a test referral through your capture path (widget, hosted form, or the create endpoint).
  2. Wait for (or manually trigger) the sync cron — the lead appears in Odoo. (Self-captured leads from the create endpoint are already there.)
  3. Activate a test contract in Odoo and let the waiting period end — the automated action fires.
  4. Confirm the referral shows converted and a pending reward appears in your partner dashboard.
  5. Approve the reward in the dashboard — its hold starts now. If the conversion has a friend’s reward, decide it too: the confirmation asks you to approve or reject it. Until the test friend has created their Offertown account, “Approve” is unavailable; rejecting the friend’s reward releases the referrer’s reward.
  6. Before the hold ends, call cancel with the same externalTransactionId and confirm the reward shows cancelled. Your API key is live, so a test reward left to mature is charged like any other. With a hold of 0 days the approval is final at once, so test with a hold of 1 day or more, or call cancel while the reward is still pending, before you approve it.

Full API details

Authentication, rate limits, error shapes, and every endpoint used above are documented in the REST API reference.