api.services.catalog_sync

Airtable writes for the product intake workflow (app.rewake.fr).

One product group = one Model, its Variations (+ their Specifications) and its Units. The app holds the workflow; this module turns a group into Airtable records and keeps them in step:

  • push create/update the group as a draft (À valider), §6E1-E2

  • validate Validé + convert an existing default Variation, §6E3

  • unvalidate back to À valider, refused once on Shopify, §6E4

  • cancel delete what the group created, with guards, §6E6

  • accessory read-merge-write of the Compatibilité row of a host, §6E5

Idempotency: every created record is remembered in a RefStore under the push’s idempotency key right after Airtable returns it, so a retry after a timeout or a partial failure reuses it instead of creating a duplicate.

Field names come from the raw Airtable schema (Architecture repo, schemas/raw/*.json). Variation Short description/Long description, Variant_value, ShopifyID and Status Shopify are lookups and are never written.

Attributes

Exceptions

PushIncomplete

A push failed midway. ids/written cover what was created or

CatalogSyncError

A refused operation the app should show to the user (HTTP 409).

Classes

AirtableGateway

AttachmentGateway

Plus Airtable's content API: a file appended to an attachment field.

RefStore

RedisRefStore

CatalogSync

Functions

entreprise_id(name) → str | None

The Entreprise record named exactly name (cached: it never moves).

model_fields(model) → dict[str, Any]

variation_fields(variation, model_id) → dict[str, Any]

spec_fields(spec, variation_id, *[, axis]) → dict[str, Any]

unit_fields(unit, variation_id) → dict[str, Any]

is_model_on_shopify(model_fields_) → bool

unit_commercial_lock(unit_fields_) → str | None

Why a Unit must not be deleted, or None.

Module Contents

api.services.catalog_sync.logger
api.services.catalog_sync.COMPAT_TABLE_NAME = 'Compatibilité'
api.services.catalog_sync.STATUS_FIELD = 'Statut validation Variation'
api.services.catalog_sync.STATUS_DRAFT = 'À valider'
api.services.catalog_sync.STATUS_VALIDATED = 'Validé'
api.services.catalog_sync.MODEL_NAME_FIELD = 'Modèle'
api.services.catalog_sync.MODEL_BRAND_FIELD = 'Marque'
api.services.catalog_sync.MODEL_TYPE_FIELD = 'Type'
api.services.catalog_sync.MODEL_SHOPIFY_ID_FIELD = 'ShopifyID'
api.services.catalog_sync.MODEL_SHOPIFY_LISTING_FIELD = 'Annonces Shopify'
api.services.catalog_sync.MODEL_IS_ACCESSORY_FIELD = 'is_accessory'
api.services.catalog_sync.MODEL_COMPAT_AS_HOST_FIELD = 'Équipements filles'
api.services.catalog_sync.VARIATION_MODEL_FIELD = 'Model'
api.services.catalog_sync.VARIATION_IS_VARIANT_FIELD = 'is_variant'
api.services.catalog_sync.VARIATION_UNITS_FIELD = 'Toutes les unités'
api.services.catalog_sync.SPEC_KEY_FIELD = 'clé'
api.services.catalog_sync.SPEC_VALUE_FIELD = 'valeur'
api.services.catalog_sync.SPEC_UNIT_FIELD = 'unité'
api.services.catalog_sync.SPEC_VARIATION_FIELD = 'Variation associée'
api.services.catalog_sync.SPEC_AXIS_VARIATION_FIELD = 'Spec_variant'
api.services.catalog_sync.UNIT_VARIATION_FIELD = 'Référence variant'
api.services.catalog_sync.UNIT_SERIAL_FIELD = 'Numéro de série'
api.services.catalog_sync.UNIT_AESTHETIC_FIELD = 'Etat esthétique'
api.services.catalog_sync.UNIT_FUNCTIONAL_FIELD = 'État fonctionnel'
api.services.catalog_sync.UNIT_WORKSHOP_NOTE_FIELD = 'Commentaire atelier (état & accessoires)'
api.services.catalog_sync.UNIT_HOST_FIELD = 'Modules/Accessoires/Consommables'
api.services.catalog_sync.UNIT_COMMERCIAL_STATUS_FIELD = 'Statut commercial'
api.services.catalog_sync.UNIT_OPERATION_FIELD = 'Opération reprise'
api.services.catalog_sync.UNIT_BUYBACK_PRICE_FIELD = 'Prix de rachat'
api.services.catalog_sync.UNIT_CLIENT_PHOTOS_FIELD = 'Photos client'
api.services.catalog_sync.UNIT_STORAGE_PLACE_FIELD = 'Lieu de stockage'
api.services.catalog_sync.UNIT_OPERATIONAL_STATUS_FIELD = 'Statut opérationnel'
api.services.catalog_sync.UNIT_RECEPTION_STORAGE_PLACE = 'Rewake'
api.services.catalog_sync.UNIT_RECEPTION_OPERATIONAL_STATUS = 'À inventorier'
api.services.catalog_sync.UNIT_RECEPTION_LOCATION = 'Réception'
api.services.catalog_sync.UNIT_PHOTOS_FIELD = 'Photos interne'
api.services.catalog_sync.EQUIPMENT_TABLE_NAME = 'Équipements liés aux propositions de reprises'
api.services.catalog_sync.EQUIPMENT_PRICE_FIELD = 'Prix de rachat'
api.services.catalog_sync.EQUIPMENT_PHOTOS_FIELD = 'Photos'
api.services.catalog_sync.UNIT_LOCKED_STATUSES
api.services.catalog_sync.COMPAT_HOST_FIELD = 'Machine mère'
api.services.catalog_sync.COMPAT_ACCESSORIES_FIELD = 'Machine fille'
api.services.catalog_sync.REF_TTL_SECONDS = 7776000
exception api.services.catalog_sync.PushIncomplete(ids: dict[str, str], written: dict[str, dict[str, Any]], cause: Exception)

Bases: Exception

A push failed midway. ids/written cover what was created or updated before the failure (also remembered under the idempotency key): retrying the same push resumes from there.

ids
written
cause
exception api.services.catalog_sync.CatalogSyncError(code: str, message: str, details: dict[str, Any] | None = None)

Bases: Exception

A refused operation the app should show to the user (HTTP 409).

code
message
details
api.services.catalog_sync.entreprise_id(name: str) → str | None

The Entreprise record named exactly name (cached: it never moves).

class api.services.catalog_sync.AirtableGateway

Bases: Protocol

get_record(table: str, record_id: str) → dict[str, Any]
create_record(table: str, fields: dict[str, Any]) → dict[str, Any]
update_record(table: str, record_id: str, fields: dict[str, Any]) → dict[str, Any]
delete_record(table: str, record_id: str) → None
class api.services.catalog_sync.AttachmentGateway

Bases: AirtableGateway, Protocol

Plus Airtable’s content API: a file appended to an attachment field.

upload_attachment(table_name: str, record_id: str, field: str, content: bytes, filename: str, content_type: str) → dict[str, Any]
class api.services.catalog_sync.RefStore

Bases: Protocol

get(key: str, ref: str) → str | None
set(key: str, ref: str, record_id: str) → None
class api.services.catalog_sync.RedisRefStore(client: redis.Redis[str])
client
get(key: str, ref: str) → str | None
set(key: str, ref: str, record_id: str) → None
api.services.catalog_sync.model_fields(model: api.domain.intake.ModelIn) → dict[str, Any]
api.services.catalog_sync.variation_fields(variation: api.domain.intake.VariationIn, model_id: str) → dict[str, Any]
api.services.catalog_sync.spec_fields(spec: api.domain.intake.SpecIn, variation_id: str, *, axis: bool = False) → dict[str, Any]
api.services.catalog_sync.unit_fields(unit: api.domain.intake.UnitValues, variation_id: str) → dict[str, Any]
api.services.catalog_sync.is_model_on_shopify(model_fields_: dict[str, Any]) → bool
api.services.catalog_sync.unit_commercial_lock(unit_fields_: dict[str, Any]) → str | None

Why a Unit must not be deleted, or None.

class api.services.catalog_sync.CatalogSync(gateway: AirtableGateway, refs: RefStore)
at
refs
push(req: api.domain.intake.PushRequest) → api.domain.intake.PushResult

Create or update the group. req.idempotency_key must be stable for the product group (not per attempt or revision): it scopes the ref -> record id memo that prevents duplicates on retry.

sync_unit(req: api.domain.intake.UnitSyncRequest) → api.domain.intake.UnitSyncResult

Create or complete the Unit of one received item. On creation it also gets its reprise, buy-back price and client photos.

remove_unit(unit_id: str) → None

Delete a Unit the app created (refused once engaged commercially).

restore_unit(unit_id: str, fields: dict[str, Any]) → bool

Give a pre-created reprise Unit its values back; False if gone.

model_on_shopify(model_id: str) → bool
validate(req: api.domain.intake.ValidateRequest) → dict[str, Any]
add_variant(model_id: str, axis: api.domain.intake.SpecIn, specs: list[api.domain.intake.SpecIn], convert_variation_id: str | None = None) → dict[str, Any]

A variant of an existing Model (commercial review): a new Variation (« À valider ») with its axis and specifications, or, with convert_variation_id, the Model’s default Variation turned into this variant (axis added). Idempotent per Model and axis value.

unvalidate(req: api.domain.intake.UnvalidateRequest) → dict[str, Any]
cancel(req: api.domain.intake.CancelRequest) → api.domain.intake.CancelResult

Add the accessory to the host’s Compatibilité row (rule 7).

Read-merge-write: the row is re-read right before the update and the accessory is appended to the current list, never written from a stale copy (Airtable replaces the whole link list on PATCH).