1
0
forked from erp-dev/erp
Files
erpnew/docs/api_v1_pre_order_api.md

7.1 KiB
Raw Blame History

API v1预销售单 / 预采购单(前端对接)

本文档面向前端描述预销售单PreSalesOrder与预采购单PrePurchaseOrder的 API、字段与参数。

  • API 前缀:/api/v1/
  • 认证:接口均要求登录(IsAuthenticated)。
  • 权限:要求当前用户绑定员工(request.user.employee),否则返回 403

分页Limit/Offset

预销售单列表、预采购单列表均使用 DRF LimitOffsetPagination

  • limit:返回条数,默认 20,最大 100
  • offset:偏移量,默认 0

分页响应结构:

{
  "count": 123,
  "next": "http://.../api/v1/pre-sales-orders/?limit=20&offset=20",
  "previous": null,
  "results": [
    { "id": 1, "human_id": "YS...", "items": [] }
  ]
}

列表查询参数(已支持)

预销售单列表 GET /pre-sales-orders/

  • limit / offset
  • customer / customer_idint
  • warehouse / warehouse_idint
  • kindint
  • human_id__icontainsstring
  • created_at_fromdatetime 或 date
  • created_at_todatetime 或 date

预采购单列表 GET /pre-purchase-orders/

  • limit / offset
  • supplier / supplier_idint
  • warehouse / warehouse_idint
  • kindint
  • human_id__icontainsstring
  • created_at_fromdatetime 或 date
  • created_at_todatetime 或 date

预销售单 PreSalesOrder

1) 列表

  • GET /api/v1/pre-sales-orders/?limit=20&offset=0
  • 查询参数:
    • limit可选int默认 20最大 100
    • offset可选int默认 0
  • 响应:200 OK,分页结构,results 为预销售单数组

2) 创建

  • POST /api/v1/pre-sales-orders/

请求体参数JSON

  • customer / customer_id必填int客户 ID
  • warehouse / warehouse_id必填int仓库 ID
  • kind可选int预销售单类型
    • 1:大货
    • 2:样板
    • 默认 1
  • remarks可选string
  • items必填array非空明细列表

items[] 字段:

  • product_id / product必填int产品 ID
  • quantity必填string 或 number数量会被转换为 Decimal
  • unit可选string单位为空时会尝试使用产品默认单位
  • product_name可选string产品名称弱关联承载
  • color可选string
  • spec可选string
  • quantity_of_rolls可选string各条数数量原样保存
  • num_of_rolls可选int条数必须 > 0默认 1
  • order_quantity可选int下单数量必须为非负整数
  • remarks可选string明细备注

响应:201 CREATED,返回预销售单详情(含 items)。

示例请求:

{
  "customer": 1,
  "warehouse": 2,
  "kind": 1,
  "remarks": "预销售单备注",
  "items": [
    {
      "product_id": 10,
      "quantity": "12.5",
      "unit": "米",
      "order_quantity": 7,
      "remarks": "明细备注"
    }
  ]
}

3) 详情

  • GET /api/v1/pre-sales-orders/{id}/
  • 响应:200 OK,返回预销售单详情

4) 更新(全量/部分)

  • PUT /api/v1/pre-sales-orders/{id}/
  • PATCH /api/v1/pre-sales-orders/{id}/

请求体参数:

  • customer / customer_id可选int
  • warehouse / warehouse_id可选int
  • kind可选int
  • remarks可选string
  • items必填array非空更新时必须提供否则会返回 400

响应:200 OK,返回更新后的详情。

5) 删除

  • DELETE /api/v1/pre-sales-orders/{id}/
  • 响应:204 NO CONTENT

预销售单字段说明(响应)

预销售单对象字段(results[] 与详情一致):

  • idint主键
  • human_idstring人类可读编号YSYYYYMMDD000001
  • merchantint所属商户 ID
  • merchantint商户 ID调试字段
  • customerint客户 ID
  • customer_namestring只读
  • warehouseint仓库 ID
  • warehouse_namestring只读
  • operatorint|null经办人员工ID创建时由后端从登录用户推导
  • operator_namestring只读
  • kindint类型1/2
  • remarksstring|null
  • created_atdatetime string
  • itemsarray明细只读

items[] 字段(响应):

  • idint
  • product_idint|null
  • product_namestring
  • colorstring|null
  • quantitystring|null通常为两位小数"20.00"
  • unitstring
  • specstring|null
  • remarksstring|null

预采购单 PrePurchaseOrder

1) 列表

  • GET /api/v1/pre-purchase-orders/?limit=20&offset=0
  • 查询参数:
    • limit可选int默认 20最大 100
    • offset可选int默认 0
  • 响应:200 OK,分页结构

2) 创建

  • POST /api/v1/pre-purchase-orders/

请求体参数JSON

  • supplier / supplier_id必填int供应商 ID
  • warehouse / warehouse_id必填int仓库 ID
  • kind可选int预采购单类型
    • 1:大货
    • 2:样板
    • 默认 1
  • remarks可选string
  • items必填array非空明细列表字段同预销售明细

响应:201 CREATED,返回预采购单详情(含 items)。

示例请求:

{
  "supplier": 1,
  "warehouse": 2,
  "kind": 1,
  "remarks": "预采购单备注",
  "items": [
    {
      "product_id": 10,
      "quantity": "12.5",
      "unit": "米",
      "order_quantity": 7,
      "remarks": "明细备注"
    }
  ]
}

3) 详情

  • GET /api/v1/pre-purchase-orders/{id}/
  • 响应:200 OK

4) 更新(全量/部分)

  • PUT /api/v1/pre-purchase-orders/{id}/
  • PATCH /api/v1/pre-purchase-orders/{id}/

请求体参数:

  • supplier / supplier_id可选int
  • warehouse / warehouse_id可选int
  • kind可选int
  • remarks可选string
  • items必填array非空更新时必须提供否则会返回 400

响应:200 OK

5) 删除

  • DELETE /api/v1/pre-purchase-orders/{id}/
  • 响应:204 NO CONTENT

预采购单字段说明(响应)

预采购单对象字段(results[] 与详情一致):

  • idint
  • human_idstring人类可读编号YCYYYYMMDD000001
  • merchantint
  • merchantint商户 ID调试字段
  • supplierint
  • supplier_namestring只读
  • warehouseint
  • warehouse_namestring只读
  • operatorint|null
  • operator_namestring只读
  • kindint1/2
  • remarksstring|null
  • created_at
  • itemsarray只读

items[] 字段同预销售明细响应。


错误响应约定(两类接口通用)

  • 400 BAD REQUEST:参数校验失败
    • 示例:{"error": "items 需要为非空数组"}
  • 401 UNAUTHORIZED:未登录
  • 403 FORBIDDEN:无员工信息/无权限
    • 示例:{"error": "无权限访问"}
  • 404 NOT FOUND:订单不存在
    • 示例:{"error": "预销售单不存在"} / {"error": "预采购单不存在"}