Fosi Fossil Service
Small teams. Open source. Built on Fossil.

IaC / SwiftFlow

High-performance WMS with wave picking, smart routing, and real-time inventory visibility.

Public | Owner: IaC | Default branch: trunk | Last update: 2026-10-23 14:37

Artifact 27bd4ed36051c7db9ee82e12146fb0adc1fa2cb81421decdc349503b2e32f4a6:


import gleam/list
import gleam/option.{None, Some}
import gleeunit
import gleeunit/should
import ql361api/goods
import ql361api/orders
import ql361api/purchases
import ql361api/store

pub fn main() -> Nil {
  gleeunit.main()
}

pub fn goods_page_decodes_real_field_names_test() {
  let body =
    "{\"type\":\"normal\",\"msg\":\"\",\"data\":{\"rowcount\":2,\"datasource\":[{\"gid\":11,\"code\":\"c001\",\"fullname\":\"测试商品\",\"commonunitbarcode\":\"6901234567890\",\"spec\":\"400g\",\"ufullname\":\"盒\",\"strshelflife\":\"180天\",\"shelflife\":180,\"gpcode\":\"A-01\",\"flag\":0,\"isparent\":0,\"modifytime\":\"2026-10-01 08:00:00\",\"createtime\":\"2026-01-01 00:00:00\"},{\"gid\":12,\"isparent\":1,\"fullname\":\"分类\"}]}}"

  let assert Ok(page) = goods.parse_goods_body(body)
  page.total |> should.equal(2)
  let assert Ok(item) = list_first(page.items)
  item.id |> should.equal(11)
  item.code |> should.equal("c001")
  item.barcode |> should.equal("6901234567890")
  item.disabled |> should.be_false
  item.is_category |> should.be_false
  item.modified_at |> should.equal("2026-10-01 08:00:00")
}

pub fn orders_page_accepts_integer_quantities_test() {
  let body =
    "{\"type\":\"normal\",\"msg\":\"\",\"data\":{\"rowcount\":1,\"datasource\":[{\"billid\":1898938789,\"billcode\":\"XSDD-1\",\"dfullname\":\"客户\",\"soutfullname\":\"门店\",\"soutid\":793208,\"billdate\":\"2026-10-01\",\"status\":20,\"statusname\":\"待发货\",\"qty\":22,\"totalmoney\":100}]}}"

  let assert Ok(page) = orders.parse_orders_body(body)
  page.total |> should.equal(1)
  let assert Ok(order) = list_first(page.items)
  order.bill_id |> should.equal(1_898_938_789)
  order.warehouse_id |> should.equal(793_208)
  order.total_qty |> should.equal(22.0)
  order.status |> should.equal(20)
}

pub fn purchase_order_uses_inbound_warehouse_test() {
  let body =
    "{\"type\":\"normal\",\"msg\":\"\",\"data\":{\"rowcount\":1,\"datasource\":[{\"billid\":1616111764,\"billcode\":\"CGDD-1\",\"dfullname\":\"供应商\",\"sinfullname\":\"总仓\",\"sinid\":793207,\"soutfullname\":\"\",\"soutid\":0,\"billdate\":\"2026-10-01\",\"status\":20,\"statusname\":\"待收货\",\"qty\":8,\"totalmoney\":30}]}}"
  let assert Ok(page) = purchases.parse_purchase_orders_body(body)
  let assert Ok(order) = list_first(page.items)
  order.supplier_name |> should.equal("供应商")
  order.warehouse_id |> should.equal(793_207)
  order.warehouse_name |> should.equal("总仓")
  order.status_name |> should.equal("待收货")
  let detail =
    "{\"type\":\"normal\",\"data\":{\"header\":{\"billid\":1616111764,\"billcode\":\"CGDD-1\",\"dfullname\":\"供应商\",\"sinfullname\":\"总仓\",\"sinid\":793207,\"status\":20,\"statusname\":\"待收货\",\"qty\":8},\"body0\":{\"datasource\":[{\"billdetailid\":9,\"skuid\":11,\"gcode\":\"c001\",\"gfullname\":\"商品\",\"barcode\":\"690\",\"qty\":8,\"gpcode\":\"默认货位\"}]}}}"
  let assert Ok(full) = purchases.parse_purchase_detail_body(detail)
  list.length(full.items) |> should.equal(1)
  let assert Ok(line) = list_first(full.items)
  line.base_qty |> should.equal(8.0)
  line.position_code |> should.equal("默认货位")
}

pub fn warehouse_list_skips_categories_test() {
  let body =
    "{\"type\":\"normal\",\"msg\":\"\",\"data\":{\"datasource\":[{\"sid\":1,\"code\":\"00002\",\"fullname\":\"总仓\",\"easycode\":\"ZC\",\"isparent\":0},{\"sid\":2,\"fullname\":\"分类\",\"isparent\":1}],\"rowcount\":2}}"
  let assert Ok(rows) = store.parse_warehouses(body)
  list.length(rows) |> should.equal(1)
  let assert Ok(warehouse) = list_first(rows)
  warehouse.id |> should.equal(1)
  warehouse.code |> should.equal("00002")
}

pub fn order_detail_decodes_lines_test() {
  let body =
    "{\"type\":\"normal\",\"msg\":\"\",\"data\":{\"header\":{\"billid\":7,\"billcode\":\"XSDD-7\",\"dfullname\":\"客户\",\"sfullname\":\"总仓\",\"soutid\":1,\"status\":20,\"qty\":2.5},\"body0\":{\"datasource\":[{\"billdetailid\":9,\"gcode\":\"c9\",\"gfullname\":\"商品\",\"barcode\":\"690\",\"mqty\":1,\"mufullname\":\"件\",\"qty\":10,\"bufullname\":\"盒\",\"gpcode\":\"\",\"sacode\":\"默认库区\"}]}}}"

  let assert Ok(order) = orders.parse_order_detail_body(body)
  order.bill_code |> should.equal("XSDD-7")
  order.warehouse_name |> should.equal("总仓")
  let assert Ok(item) = list_first(order.items)
  item.goods_code |> should.equal("c9")
  item.position_code |> should.equal("")
  item.base_qty |> should.equal(10.0)
  let _ = Some(None)
}

fn list_first(items) {
  case items {
    [first, ..] -> Ok(first)
    [] -> Error(Nil)
  }
}

Clone

You can clone this repository with the following command:

fossil clone https://fosi.dev/IaC/SwiftFlow

Contribute

The best way to contribute is through e-mail. See the project documentation for more details.