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. inir.config_parameteror 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
| Flow | Direction | Mechanism |
|---|---|---|
| Leads into Odoo | Offertown → Odoo | A scheduled action (ir.cron) polls the referral list endpoint and creates crm.lead records. |
| Conversions back | Odoo → Offertown | An 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
Run a scheduled action every 5–15 minutes that keeps a watermark of the last successful sync:
- Call the list endpoint with
status=pending,dateFromset to the watermark,dateToset to the sync start time, andsortBy=createdAt&sortOrder=asc, paginating withpage/pageSize. If the response reportspagination.truncated: true, split the window and repeat. - For each referral whose
referralIdisn’t in Odoo yet, create acrm.leadusing the mapping below. Put a unique constraint onx_offertown_referral_idso replays are harmless no-ops. - Advance the watermark to the run’s
dateToonly 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 field | Odoo crm.lead field |
|---|---|
referralId | x_offertown_referral_id (custom, indexed) — the join key |
referralCode | x_offertown_referral_code (custom) — handy for support |
| — | name (required by crm.lead) — e.g. “Offertown referral — ” + friendName |
friendName / friendEmail / friendPhone | contact_name / email_from / phone |
friendPostCode / friendAddress / friendCity | zip / street / city — useful for serviceability checks |
referrerName / referrerEmail | x_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
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:
{
"conversionValue": 12999,
"currency": "EUR",
"externalTransactionId": "mydb-sale.order-4211",
"metadata": { "planName": "Fiber 100", "customerId": "C-1" }
}conversionValueis the customer’s monthly price, VAT included, in cents (EUR).externalTransactionIdis 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 thesale.orderdatabase 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. metadatais 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.planNameandcustomerIdare the named keys; other keys are shown as sent. Sendingmetadataon 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 answers409 NO_PENDING_REFERRALuntil your team reopens the lead in the dashboard. - On
429, honorRetry-Afterand 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
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.
{
"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."
}{
"data": {
"referralId": "jx7…",
"rewardsCancelled": 1,
"idempotent": false
}
}externalTransactionIdandreasonare required, and no fields other than these four are accepted.externalTransactionIdmust match the one sent toconvert(1–128 characters);reasonis stored with the cancelled reward for your records (1–500 characters) and is never shown to the referrer or the friend.referrerMessageandfriendMessageare optional (1–500 characters each).referrerMessageis read only by the referrer andfriendMessageonly 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.rewardsCancelledcounts the rewards this call cancelled: the referrer’s and, if there is one, the friend’s. It is0when the conversion’s rewards had not been created yet; none will be.- Repeating the call returns
200withidempotent: trueandrewardsCancelled: 0, so the action can retry on network errors. 409 REWARD_MATUREDmeans 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_CONVERTEDmeans no conversion was reported for this referral.409 TRANSACTION_MISMATCHmeans theexternalTransactionIddiffers from the one sent toconvert.404 NOT_FOUNDmeans the referral doesn’t exist or isn’t yours.- Cancellations count toward a limit of 60 referral writes per minute per partner; on
429, honorRetry-After.
When a lead is lost
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.
{
"reason": "outside_service_area",
"note": "The address is outside our network"
}reasonis required:outside_service_area,did_not_sign,already_customer,duplicate,not_eligibleorother. Map Odoo’s lost reasons onto these. The REST API reference lists which reason the referrer and the friend are shown.noteis optional, at most 500 characters, and required whenreasonisother. Your team reads it on the Leads page; the referrer and the friend never see it.- Repeating the call with the same
reasonreturns200withidempotent: trueand sends no second email, so the action can retry on network errors. A differentreasonanswers409 ALREADY_CLOSED. 409 ALREADY_CONVERTED,409 EXPIREDand409 NOT_PENDINGmean the lead is not pending, and nothing was changed.404 NOT_FOUNDmeans 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, honorRetry-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
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:
{
"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
- Create a test referral through your capture path (widget, hosted form, or the create endpoint).
- Wait for (or manually trigger) the sync cron — the lead appears in Odoo. (Self-captured leads from the create endpoint are already there.)
- Activate a test contract in Odoo and let the waiting period end — the automated action fires.
- Confirm the referral shows
convertedand a pending reward appears in your partner dashboard. - 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.
- Before the hold ends, call cancel with the same
externalTransactionIdand 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.