name: stage-demand
description: |
  Demand (оптовая отгрузка юрлицу) на test.admin.food-market.kz.
  Создание Draft с DemandPayment (Cash/Card/BankTransfer/Credit),
  PaidAmount < Total для Credit (дебиторка). Post → Stock минус с
  MovementType.WholesaleSale. Multi-tenant. Edge: post больше остатка.

preconditions:
  reset_db: false
  smoke_login_super_admin: false

steps:
  - id: dm01_setup
    title: 2 org. У orgA — продукт qty=100, customer-юрлицо
  - id: dm02_create_draft_full_paid
    title: POST demand с Payment=Cash, PaidAmount=Total → 201
  - id: dm03_update_draft
    title: PUT — изменить строки (фикс EF8 уже применён к demands в TD-6) → 204
  - id: dm04_post_full_paid
    title: POST /post → 204; Stock -= qty; StockMovement type=WholesaleSale
  - id: dm05_credit_partial_payment
    title: POST demand с Payment=Credit + PaidAmount=0 (дебиторка) → 201, post → 204; долг = Total
  - id: dm06_post_more_than_stock
    title: Demand с qty > stock → 409 при post
  - id: dm07_unpost
    title: POST /unpost → 204; Stock восстановлен
  - id: dm08_multi_tenant_isolation
    title: Org B не видит demand org A
