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_returnstable + FBA customer returns import (GET_FBA_FULFILLMENT_CUSTOMER_RETURNS_DATA); cron yesterday; Profit tab manual import with β€30-day batches.refund_expenseson Amazon returns from Finances Transactions (abs(Refund RELEASED + Shipment RELEASED)); Plenty retours store package+extras handling cost the same way.amazon_orders.has_retourwhen a return matchesamazon_order_id(preserved on re-sync).amazon_orders.brutto_buy_price/profitfrom article buy viafba_detailsand 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
DONEreports).
Plenty
plenty_orders:brutto_buy_price,fee_estimate_amount,profit.- Buy price:
repricer_articles.brutto_buy_priceonly (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¶
- 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
-
Redeploy service-omni, service-multi-repricer, frontend.
-
Re-import Plenty / Amazon orders for historical ranges to backfill buy / fee / profit /
total_order_profit(or truncateplenty_ordersand refill).
β Verify¶
- Profit tab β Amazon returns import β rows in
amazon_returns,has_retour=true. - Amazon orders sync over a long range β non-zero rows; logs show report windows β€ 30 days.
- Plenty re-import β buy, fees, line
profit,total_order_profit; gift-set shell sell cleared after component alloc;Ξ£ price_grossmatches invoice. - Analysis β expand Main β KPIs + consumer bundles;
period_profitmatches stored line profits when present. - Tests:
pytest backend/service_omni/app/tests/test_amazon_returns.pypytest backend/service_omni/app/tests/test_amazon_order_enrichment.pypytest backend/service_omni/app/tests/test_plenty_order_enrichment.pypytest backend/service_omni/app/tests/test_plenty_fee_estimation.pypytest 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
Related docs¶
- Profit imports, order economics & Analysis β four Profit imports, buy/fee/profit math, cron pipeline, Analysis Main/Stock usage
- Plenty orders & retours
- Statistics endpoints
- Article sales & profit statistics