Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion connector/tests/test_mapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -679,7 +679,11 @@ class MyMapper(Component):

self._build_components(MyMapper)

partner = self.env.ref("base.res_partner_address_4")
# Create records instead of relying on demo data
parent = self.env["res.partner"].create({"name": "Deco Addict"})
partner = self.env["res.partner"].create(
{"name": "Test Child", "parent_id": parent.id}
)
mapper = self.comp_registry["my.mapper"](self.work)
map_record = mapper.map_record(partner)
expected = {"parent_name": "Deco Addict"}
Expand Down
101 changes: 101 additions & 0 deletions connector_amazon_spapi/CLAUDE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
# CLAUDE.md

This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.

## Overview

This is an Odoo 16 connector module for Amazon Seller Central SP-API integration. It handles order import, stock synchronization, competitive pricing, and shipment tracking using the OCA (Odoo Community Association) connector framework patterns.

## Development Commands

### Running Tests

```bash
# Full test suite (47+ tests)
invoke test --cur-file odoo/custom/src/connector/connector_amazon_spapi/__manifest__.py

# Specific test file
invoke test --cur-file odoo/custom/src/connector/connector_amazon_spapi/tests/test_backend.py

# With debugpy for VS Code debugging
invoke test --cur-file odoo/custom/src/connector/connector_amazon_spapi/__manifest__.py --debugpy
```

### Doodba Environment

```bash
cd /Users/dkendall/projects/odoo/ecom-odoo
invoke start # Start Docker containers
invoke stop # Stop containers
```

## Architecture

### OCA Connector Pattern

The module follows the OCA connector framework with three main component types:

1. **Adapters** (`components/backend_adapter.py`) - Encapsulate SP-API HTTP communication
- `AmazonOrdersAdapter` - Orders API endpoints
- `AmazonPricingAdapter` - Pricing API endpoints

2. **Mappers** (`components/mapper.py`) - Transform Amazon API responses to Odoo models
- `AmazonOrderImportMapper` - Maps orders to `sale.order`
- `AmazonOrderLineImportMapper` - Maps order items to `sale.order.line`
- `AmazonProductPriceImportMapper` - Maps pricing data

3. **Binder** (`components/binder.py`) - Maps external IDs (Amazon order IDs) to Odoo record IDs

### Data Binding Pattern

Models use `external.binding` to link Odoo records with Amazon entities:

```
amazon.backend (1 per integration)
└── amazon.marketplace (fetched from SP-API)
└── amazon.shop (marketplace + backend combination, sync operations)

amazon.sale.order (external.binding → sale.order)
amazon.product.binding (external.binding → product.product)
amazon.competitive.price (pricing history)
amazon.feed (bulk operations via Feeds API)
```

### Key Models

| Model | File | Purpose |
|-------|------|---------|
| `amazon.backend` | models/backend.py | Central auth config, LWA token management |
| `amazon.shop` | models/shop.py | Sync operations (orders, stock, prices) |
| `amazon.sale.order` | models/order.py | Order import, shipment tracking |
| `amazon.product.binding` | models/product_binding.py | Product-Amazon ASIN/SKU mappings |
| `amazon.feed` | models/feed.py | Feeds API for bulk operations |

### Async Operations

All sync operations use `queue_job` for async processing:
- `shop.action_sync_orders()` → queues `sync_orders()`
- `shop.action_push_stock()` → queues `push_stock()`
- Cron jobs in `data/ir_cron.xml` for scheduled syncs

### Read-Only Mode

Backend has a `read_only_mode` flag that logs operations instead of calling Amazon APIs - useful for testing without affecting the Amazon account.

## Testing

All tests mock external API calls (no real Amazon requests). Test fixtures are in `tests/common.py` with `CommonConnectorAmazonSpapi` base class.

Key test files:
- `test_backend.py` - Auth, token refresh, connectivity
- `test_shop.py` - Order sync, catalog sync
- `test_order.py` - Order creation, line item mapping
- `test_adapters.py` - API call handling
- `test_mapper.py` - Data transformation

## Dependencies

- `connector` (OCA connector framework)
- `queue_job` (async job processing)
- `sale_management`, `stock`, `product`, `delivery` (Odoo core)
- `requests` (HTTP client)
99 changes: 99 additions & 0 deletions connector_amazon_spapi/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
=======================
Amazon SP-API Connector
=======================

..
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:PLACEHOLDER_DIGEST
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png
:target: https://odoo-community.org/page/development-status
:alt: Beta
.. |badge2| image:: https://img.shields.io/badge/licence-LGPL--3-blue.png
:target: https://www.gnu.org/licenses/lgpl-3.0-standalone.html
:alt: License: LGPL-3
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fconnector-lightgray.png?logo=github
:target: https://github.com/OCA/connector/tree/16.0/connector_amazon_spapi
:alt: OCA/connector

|badge1| |badge2| |badge3|

Amazon Seller Central (SP-API) integration for Odoo 16.0, providing automated order import,
inventory synchronization, and pricing management following OCA Connector patterns.

**Table of contents**

.. contents::
:local:

Configuration
=============

To configure this module, you need to:

#. Go to Connectors > Amazon > Backends
#. Create a new backend with your SP-API credentials:

- LWA Client ID
- LWA Client Secret
- LWA Refresh Token
- AWS Role ARN (optional for certain API operations)

#. Create Marketplace records for each Amazon marketplace you sell in
#. Create Shop records linking marketplaces to your backend

Usage
=====

Order Import
------------

#. Navigate to Connectors > Amazon > Shops
#. Click "Sync Orders" on a shop record
#. Orders are fetched asynchronously via queue jobs
#. Check Connectors > Queue > Jobs to monitor progress

Stock & Price Sync
------------------

Stock and price synchronization features are planned for future releases.
See the TESTING_GUIDE.md for technical details on the implementation roadmap.

Bug Tracker
===========

Bugs are tracked on `GitHub Issues <https://github.com/OCA/connector/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 <https://github.com/OCA/connector/issues/new?body=module:%20connector_amazon_spapi%0Aversion:%2016.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.

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

Credits
=======

Authors
-------

* Odoo Community Association (OCA)

Maintainers
-----------

This module is maintained by the OCA.

.. image:: https://odoo-community.org/logo.png
:alt: Odoo Community Association
:target: https://odoo-community.org

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.

This module is part of the `OCA/connector <https://github.com/OCA/connector/tree/16.0/connector_amazon_spapi>`_ project on GitHub.

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