{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://artifacts.apis.io/akeda-ru/json-schema/akeda-ru-docflow-sales-order-schema.json",
  "title": "DocflowSalesOrder",
  "x-generated": "2026-11-10",
  "x-method": "derived",
  "x-generator": "derive-json-schema.py",
  "x-source": "openapi/akeda-ru-app-runtime-api-openapi.yml#/components/schemas/DocflowSalesOrder",
  "type": "object",
  "additionalProperties": false,
  "required": [
    "id",
    "company_id",
    "contact_id",
    "title",
    "status",
    "scenario",
    "steps",
    "currency",
    "prices_include_vat",
    "items",
    "amount",
    "goods_amount",
    "service_amount",
    "paid_amount",
    "shipped_amount",
    "invoiced_amount",
    "closed_amount",
    "payment_status",
    "shipment_status",
    "created_at",
    "updated_at"
  ],
  "properties": {
    "id": {
      "$ref": "#/$defs/UUID"
    },
    "company_id": {
      "$ref": "#/$defs/UUID"
    },
    "contact_id": {
      "$ref": "#/$defs/UUID"
    },
    "contract_document_id": {
      "$ref": "#/$defs/UUID"
    },
    "channel_id": {
      "$ref": "#/$defs/UUID",
      "description": "Канал продаж заказа (ERP-2885); нет поля — канала нет"
    },
    "consignee_contact_id": {
      "description": "Грузополучатель — карточка филиала или склада покупателя; по ней УПД пишет ГрузПолуч. Пусто — сам покупатель",
      "allOf": [
        {
          "$ref": "#/$defs/UUID"
        }
      ]
    },
    "consignee_name": {
      "type": "string",
      "description": "Название карточки грузополучателя"
    },
    "number": {
      "type": "string"
    },
    "title": {
      "type": "string"
    },
    "status": {
      "type": "string",
      "enum": [
        "draft",
        "confirmed",
        "done",
        "cancelled"
      ]
    },
    "status_id": {
      "$ref": "#/$defs/UUID"
    },
    "status_name": {
      "type": "string",
      "description": "Имя статуса, которое придумал кабинет"
    },
    "funnel_id": {
      "$ref": "#/$defs/UUID"
    },
    "scenario": {
      "type": "string",
      "enum": [
        "self_service",
        "one_off_sale",
        "contract_sale"
      ]
    },
    "steps": {
      "type": "array",
      "items": {
        "type": "string"
      }
    },
    "currency": {
      "type": "string"
    },
    "manager": {
      "type": "string"
    },
    "comment": {
      "type": "string"
    },
    "external_id": {
      "type": "string"
    },
    "buyer": {
      "$ref": "#/$defs/DocflowSalesOrderBuyer"
    },
    "acquiring_amount": {
      "type": "string",
      "description": "Сколько подтвердил эквайринг — списания минус возвраты"
    },
    "order_date": {
      "type": "string",
      "format": "date"
    },
    "ship_date": {
      "type": "string",
      "format": "date"
    },
    "due_date": {
      "type": "string",
      "format": "date"
    },
    "discount": {
      "type": "string"
    },
    "prices_include_vat": {
      "type": "boolean"
    },
    "items": {
      "type": "array",
      "items": {
        "$ref": "#/$defs/DocflowSalesOrderItem"
      }
    },
    "amount": {
      "type": "string"
    },
    "goods_amount": {
      "type": "string"
    },
    "service_amount": {
      "type": "string"
    },
    "paid_amount": {
      "type": "string",
      "description": "Сколько денег пришло на счёт по продаже или закупке"
    },
    "shipped_amount": {
      "type": "string"
    },
    "invoiced_amount": {
      "type": "string"
    },
    "closed_amount": {
      "type": "string"
    },
    "payment_status": {
      "type": "string",
      "enum": [
        "unpaid",
        "partial",
        "paid"
      ]
    },
    "shipment_status": {
      "type": "string",
      "enum": [
        "not_shipped",
        "partial",
        "shipped"
      ]
    },
    "company_name": {
      "type": "string"
    },
    "contact_name": {
      "type": "string"
    },
    "contract_title": {
      "type": "string"
    },
    "company_archived": {
      "type": "boolean"
    },
    "contact_archived": {
      "type": "boolean"
    },
    "created_at": {
      "type": "string",
      "format": "date-time"
    },
    "updated_at": {
      "type": "string",
      "format": "date-time"
    }
  },
  "$defs": {
    "DocflowSalesOrderBuyer": {
      "type": "object",
      "additionalProperties": false,
      "description": "Как покупатель представился в продаже или закупке",
      "properties": {
        "name": {
          "type": "string"
        },
        "phone": {
          "type": "string"
        },
        "email": {
          "type": "string"
        }
      }
    },
    "DocflowSalesOrderItem": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "id",
        "title",
        "kind",
        "quantity",
        "price",
        "position"
      ],
      "properties": {
        "id": {
          "$ref": "#/$defs/UUID"
        },
        "product_id": {
          "$ref": "#/$defs/UUID"
        },
        "title": {
          "type": "string"
        },
        "kind": {
          "type": "string"
        },
        "unit": {
          "type": "string"
        },
        "quantity": {
          "type": "string"
        },
        "price": {
          "type": "string"
        },
        "discount": {
          "type": "string"
        },
        "vat_rate": {
          "type": "string"
        },
        "position": {
          "type": "integer"
        },
        "amount": {
          "type": "string"
        }
      }
    },
    "UUID": {
      "type": "string",
      "format": "uuid"
    }
  }
}