Skip to content

1.9.2

βš™οΈ Patch 1.9.2 β€” Orders economics, Analysis Main/Stock & Amazon reports

Combined release of work previously drafted as 1.9.2–1.9.10 (includes the former 1.9.9 Amazon order-report 30-day / lookback fix).

πŸš€ Summary

Amazon

  • amazon_returns table + FBA customer returns import (GET_FBA_FULFILLMENT_CUSTOMER_RETURNS_DATA); cron yesterday; Profit tab manual import with ≀30-day batches.
  • refund_expenses on Amazon returns from Finances Transactions (abs(Refund RELEASED + Shipment RELEASED)); Plenty retours store package+extras handling cost the same way.
  • amazon_orders.has_retour when a return matches amazon_order_id (preserved on re-sync).
  • amazon_orders.brutto_buy_price / profit from article buy via fba_details and fee estimate.
  • Fee estimate prefers fba_details.international_pricing[marketplace] (VAT wedge + referral/DST + fulfillment/storage/…); falls back to ProductFees when pricing is missing.
  • Order report sync batched for SP-API limits; 16-day batches + ≀14-day lookback so total span stays within Amazon’s 30-day order-report cap (fixes empty DONE reports).

Plenty

  • plenty_orders: brutto_buy_price, fee_estimate_amount, profit.
  • Buy price: repricer_articles.brutto_buy_price only (shopping_table ignored); always 2dp HALF_UP rounding.
  • Bundle zero-price allocation (1:1 / value pack / mixed) via repricer_articles.
  • Channel fee + profit (Otto / Shopify / Kaufland / Amazon FBM + package cost) on upsert.

Analysis (multi-repricer)

  • Expandable Main/Stock rows + consumer-bundles table (sales, pro-rated profit, returns, bundle art).
  • KPIs prefer persisted order profit / brutto_buy_price (fallback to live fee stack when null).

✨ Details

Area Behavior
Amazon returns Report β†’ Finances refund_expenses β†’ amazon_returns; mark has_retour
Plenty retours Persist refund_expenses (= package + extras Γ— qty) at import
Analysis return cost Prefer Ξ£ refund_expenses; else live package_cost + extras
Amazon buy/profit buy_netto = brutto/1.19; profit = netto line margin qty Γ— (sell βˆ’ fee βˆ’ buy_netto)
Plenty profit Same: stored profit is netto margin (after VAT), not brutto
Amazon fee Prefer FBA international_pricing by ASIN+marketplace; else ProductFees
Amazon order batches ORDER_REPORT_BATCH_DAYS = 16 + lookback clamped to ≀30 calendar days
Plenty enrich order buy β†’ dedupe β†’ fee on priced β†’ freeze total_order_profit/total_order_fee β†’ fill parts β†’ ASIN fees
Plenty fees Otto provision%; Shopify 2.99%+€0.35; Kaufland fixed+variable; FBM referral/DST/extras + shipping
Bundle prices Fill zero parts from shell/peer; shells keep sell (order totals frozen earlier)
Plenty order profit total_order_profit = Ξ£ line profit per order_id (netto; on every line)
Plenty order fee total_order_fee = Ξ£ (fee_estimate_amount Γ— qty) per order_id (on every line)
Stock consumers API GET /articles/{sku}/stats/stock-consumers
Analysis profit Prefer plenty_orders / amazon_orders.profit; else unit_profit_for_channel

πŸ”§ Deploy

  1. Apply SQL (if not already):
-- docker/postgres/updates/amazon_returns_and_has_retour.sql
-- docker/postgres/updates/amazon_orders_buy_price_profit.sql
-- docker/postgres/updates/plenty_orders_buy_price_fee_profit.sql
-- docker/postgres/updates/plenty_orders_total_order_profit.sql
-- docker/postgres/updates/plenty_orders_total_order_fee.sql
-- docker/postgres/updates/amazon_plenty_refund_expenses.sql
  1. Redeploy service-omni, service-multi-repricer, frontend.

  2. Re-import Plenty / Amazon orders for historical ranges to backfill buy / fee / profit / total_order_profit (or truncate plenty_orders and refill).

βœ… Verify

  1. Profit tab β†’ Amazon returns import β†’ rows in amazon_returns, has_retour=true.
  2. Amazon orders sync over a long range β†’ non-zero rows; logs show report windows ≀ 30 days.
  3. Plenty re-import β†’ buy, fees, line profit, total_order_profit; gift-set shell sell cleared after component alloc; Ξ£ price_gross matches invoice.
  4. Analysis β†’ expand Main β†’ KPIs + consumer bundles; period_profit matches stored line profits when present.
  5. Tests:
  6. pytest backend/service_omni/app/tests/test_amazon_returns.py
  7. pytest backend/service_omni/app/tests/test_amazon_order_enrichment.py
  8. pytest backend/service_omni/app/tests/test_plenty_order_enrichment.py
  9. pytest backend/service_omni/app/tests/test_plenty_fee_estimation.py
  10. pytest backend/service_multi-repricer/app/tests/test_article_stats.py

Files touched (high level)

docker/postgres β€” amazon_returns, amazon_orders buy/profit, plenty_orders buy/fee/profit updates & table defs

service-omni β€” Amazon returns/orders sync & enrichment; Plenty order enrichment, fee estimation; shopping_table buy history; Profit/statistics APIs

service-multi-repricer β€” omni_sales schema mirror; article_stats stock-consumers + persisted profit preference

frontend β€” Profit tab Amazon returns/orders UI; Analysis expand + AnalysisStockExpandPanel

docs β€” this combined 1.9.2 note; Profit imports, order economics & Analysis