Odoo Community Association

Mercado Libre Connector

Alpha License: AGPL-3 OCA/connector-mercadolibre Translate me on Weblate Try me on Runboat

Connect an Odoo company to a Mercado Libre seller account.

This is the core of the connector. It stores the seller backend, authorizes the application with OAuth 2.0, refreshes access tokens, and receives Mercado Libre notifications. Listing, stock, and sale synchronization live in connector_mercadolibre_product and connector_mercadolibre_sale.

A notification is stored and acknowledged in the HTTP request. The work runs afterwards in an OCA queue job.

Important

This is an alpha version, the data model and design can change at any time without warning. Only for development or testing purpose, do not use in production. More details on development status

Table of contents

Installation

Install this module together with OCA connector 19.0. connector depends on component, component_event, and queue_job.

The HTTP client uses the Python package requests.

Enable the job runner. In odoo.conf:

[queue_job]
channels = root:2,root.mercadolibre.import:2,root.mercadolibre.export:1,root.mercadolibre.webhook:2

Start Odoo with --load=base,web,queue_job and more than one worker.

Configuration

  1. Create an application in Mercado Libre (My Applications) with write scope and a redirect URI that points at this database, for example https://example.com/mercadolibre/oauth/callback.
  2. Set the notification callback to https://example.com/mercadolibre/notification/<backend-database-id>. Subscribe the topics the installed addons handle. The core stores every topic; product and sale addons consume items, stock-location, orders_v2, shipments, and payments.
  3. Grant operators Mercado Libre / User and administrators Mercado Libre / Manager.
  4. Open Mercado Libre / Configuration / Backends, create a backend, set the company, the site (MLA, MLB, MLM, …), the client id, the client secret, and the redirect URI.
  5. Click Connect and authorize the seller. The backend stores the seller id returned by /users/me and the token pair.
  6. A scheduled action refreshes the access token before the six-hour expiry. When Mercado Libre rejects the refresh token, the backend moves to Error and an administrator reconnects the seller.

Usage

Open Mercado Libre / Operations / Notifications to see the callbacks Mercado Libre has posted. Each row is dispatched by a job on the root.mercadolibre.webhook channel.

A topic with no installed handler is marked Skipped. Installing a later addon adds a handler component; the controller stays unchanged.

Refresh token on the backend asks Mercado Libre for a new access token immediately. Disconnect deletes the stored tokens.

Development

The backend model mercadolibre.backend is the component collection. Dispatch loads every component with usage notification.handler on mercadolibre.notification and keeps the one whose _topic equals the payload topic. A handler with an empty _topic marks the notification skipped.

_apply_on has to be an Odoo model name. The Mercado Libre topic is not a model, so a later addon selects its topic with _topic.

Register a handler for one topic in another addon:

class OrderNotificationHandler(Component):
    _name = "mercadolibre.notification.handler.orders"
    _inherit = "mercadolibre.notification.handler"
    _apply_on = "mercadolibre.notification"
    _usage = "notification.handler"
    _topic = "orders_v2"

    def handle(self):
        notification = self.work.notification
        ...

The HTTP adapter usage is backend.adapter. Child adapters inherit mercadolibre.adapter and set the resource path. Token refresh takes a row lock on the backend because the refresh token is single-use.

Set QUEUE_JOB__NO_DELAY=1 to run jobs inline while developing.

Known issues / Roadmap

  • connector_mercadolibre_product binds listings and exports price and seller-warehouse stock.
  • connector_mercadolibre_sale imports orders, packs, and shipments.
  • Questions, claims, shipping labels, promotions, payouts, country fiscal documents, and Global Selling (/marketplace) are further addons. Each one adds components and does not change this controller.

Bug Tracker

Bugs are tracked on GitHub Issues. In case of trouble, please check there if your issue has already been reported. If you spotted it first, help us to smash it by providing a detailed and welcomed feedback.

Do not contact contributors directly about support or help with technical issues.

Credits

Authors

  • Gray Matter Logic

Maintainers

This module is maintained by the OCA.

Odoo Community Association

OCA, or the Odoo Community Association, is a nonprofit organization whose mission is to support the collaborative development of Odoo features and promote its widespread use.

Current maintainer:

max3903

This module is part of the OCA/connector-mercadolibre project on GitHub.

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.