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 d646ab4a821bcd4ad33fdb39738b1c1697105a67354cbe0edec34f2c55dbb11a:


import gleam/list
import gleam/string
import ql361api/models.{type QlWarehouse}

/// 配置项按逗号或中文逗号分隔。空配置回退到总仓,避免误把全部门店库存拉进来。
pub fn parse_tokens(raw: String) -> List(String) {
  raw
  |> string.replace(",", ",")
  |> string.split(",")
  |> list.map(string.trim)
  |> list.filter(fn(token) { token != "" })
}

pub fn is_stock_warehouse(
  code: String,
  easycode: String,
  name: String,
  tokens: List(String),
) -> Bool {
  list.any(tokens, fn(token) {
    same(token, code) || same(token, easycode) || same(token, name) || string.contains(name, token)
  })
}

pub fn stock_warehouse_ids(
  warehouses: List(QlWarehouse),
  tokens: List(String),
) -> List(Int) {
  list.filter_map(warehouses, fn(warehouse) {
    case
      is_stock_warehouse(
        warehouse.code,
        warehouse.easycode,
        warehouse.fullname,
        tokens,
      )
    {
      True -> Ok(warehouse.id)
      False -> Error(Nil)
    }
  })
}

pub fn bill_in_stock_scope(
  warehouse_id: Int,
  warehouse_name: String,
  warehouses: List(QlWarehouse),
  tokens: List(String),
) -> Bool {
  case list.find(warehouses, fn(warehouse) { warehouse.id == warehouse_id }) {
    Ok(warehouse) ->
      is_stock_warehouse(
        warehouse.code,
        warehouse.easycode,
        warehouse.fullname,
        tokens,
      )
    Error(_) -> is_stock_warehouse("", "", warehouse_name, tokens)
  }
}

fn same(left: String, right: String) -> Bool {
  string.lowercase(left) == string.lowercase(right)
}

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.