api.scripts.variation_pricing ============================= .. py:module:: api.scripts.variation_pricing .. autoapi-nested-parse:: Variation prices from the discount grid (api/services/pricing.py). Writes each Variation's "Prix bon état €HT" and "Prix abimé €HT" from its "Prix de la variation" (hand edits are overwritten), then queues one ``update_product`` per Model on Shopify whose prices changed. The units' "Prix de vente HT" is an Airtable formula over these prices (by "Etat esthétique"), so nothing is written on the units. Two entry points: - ``record_id`` (a Variation id): sent by the Airtable automation when "Prix de la variation" changes; that Variation is recomputed now and its product updated. - no ``record_id`` (every day at 19:00 Europe/Paris, or on demand): recomputes every Variation, only when the grid changed since the last applied one. Only the values that differ are written. The first run (no snapshot yet) also updates every Shopify product, which pushes the prices of the new formula once. Attributes ---------- .. autoapisummary:: api.scripts.variation_pricing.logger api.scripts.variation_pricing.PRICE_FIELD api.scripts.variation_pricing.BON_FIELD api.scripts.variation_pricing.ABIME_FIELD api.scripts.variation_pricing.FIELDS api.scripts.variation_pricing.UPDATE_PRODUCT_DELAY_SECONDS Classes ------- .. autoapisummary:: api.scripts.variation_pricing.VariationPricing Functions --------- .. autoapisummary:: api.scripts.variation_pricing.price_updates api.scripts.variation_pricing.models_on_shopify Module Contents --------------- .. py:data:: logger .. py:data:: PRICE_FIELD :value: 'Prix de la variation' .. py:data:: BON_FIELD :value: 'Prix bon état €HT' .. py:data:: ABIME_FIELD :value: 'Prix abimé €HT' .. py:data:: FIELDS .. py:data:: UPDATE_PRODUCT_DELAY_SECONDS :value: 15 .. py:function:: price_updates(variations: list[dict[str, Any]], grid: api.services.pricing.PricingGrid) -> list[dict[str, Any]] [{"id", "fields"}] for each Variation whose bon/abimé prices differ from the grid's. A Variation without a positive price is left alone. .. py:function:: models_on_shopify(variations: list[dict[str, Any]]) -> list[str] Model ids (deduplicated, in order) of the Variations sold on an existing Shopify product -- the others have nothing to update (and an unset to_sell_on_shopify would only raise an alert per Model). .. py:class:: VariationPricing .. py:attribute:: name :value: 'variation_pricing' .. py:attribute:: schedule .. py:method:: is_configured() -> bool .. py:method:: run(previous_snapshot: dict[str, Any] | None = None, report_stage: api.scripts.base.StageReporter = lambda stage: None, **kwargs: Any) -> tuple[api.scripts.base.ScriptResult, dict[str, Any] | None]