fix(bill): expose usable template group ids
- bill templates 文本输出带 ID(组 ID,可直接用于 bill spec) - getFormSpecification 自动剥离版本后缀,兼容 <groupId>:<hash> - 修复 bill spec <模板ID> 返回 NOT FOUND
This commit is contained in:
1 parent
9d7df10994
commit
782466ad80
5 files changed
+15
-7
No files matched your search
@@ -53,7 +53,7 @@ export async function handleTemplates(ctx: BillActionContext): Promise<CliResult
|
||||
lines.push(`${group.name || "未分组"}`);
|
||||
for (const spec of group.specifications) {
|
||||
const inactiveMark = spec.active ? "" : "(已停用)";
|
||||
lines.push(` - ${spec.name}${inactiveMark} [${spec.type}]`);
|
||||
lines.push(` - ${spec.name}${inactiveMark} [${spec.type}] ID: ${spec.id}`);
|
||||
}
|
||||
lines.push("");
|
||||
}
|
||||
|
||||
@@ -578,8 +578,11 @@ export async function getFormSpecification(
|
||||
corpId: string,
|
||||
specificationId: string
|
||||
): Promise<FormSpecification | undefined> {
|
||||
const cleanId = specificationId.replace(/^\[|\]$/g, "").trim();
|
||||
if (!cleanId) return undefined;
|
||||
const rawId = specificationId.replace(/^\[|\]$/g, "").trim();
|
||||
if (!rawId) return undefined;
|
||||
// 服务端用于查询的是「规格组 ID」(`<groupId>`),版本化 ID 形如 `<groupId>:<hash>`;
|
||||
// 统一剥离版本后缀,保证 `bill templates` 返回的 ID 可直接用于 `bill spec`。
|
||||
const cleanId = rawId.split(":")[0];
|
||||
const response = await client.get(
|
||||
`api/form/v2/specifications/[${encodeURIComponent(cleanId)}]`,
|
||||
{
|
||||
|
||||
@@ -54,7 +54,8 @@ describe("normalizeTemplateGroups", () => {
|
||||
it("保留分组名与模板类型", () => {
|
||||
const result = normalizeTemplateGroups(raw);
|
||||
expect(result.groups[0].specifications[0]).toMatchObject({
|
||||
id: "a:1",
|
||||
id: "a",
|
||||
versionedId: "a:1",
|
||||
name: "AI合同审批单",
|
||||
type: "custom",
|
||||
group: "报销单拆单",
|
||||
|
||||
@@ -11,7 +11,10 @@ import type { KyInstance } from "ky";
|
||||
*/
|
||||
|
||||
export interface BillTemplateSpec {
|
||||
/** 规格组 ID(可直接用于 `bill spec <id>` / 创建单据) */
|
||||
id: string;
|
||||
/** 服务端返回的版本化 ID(`<groupId>:<versionHash>`) */
|
||||
versionedId: string;
|
||||
name: string;
|
||||
type: string;
|
||||
active: boolean;
|
||||
@@ -66,7 +69,8 @@ export function normalizeTemplateGroups(
|
||||
if (!includeInactive) continue;
|
||||
}
|
||||
specs.push({
|
||||
id: spec.id,
|
||||
id: spec.id.split(":")[0],
|
||||
versionedId: spec.id,
|
||||
name: spec.name,
|
||||
type: spec.type ?? "unknown",
|
||||
active,
|
||||
|
||||
Reference in new issue
Block a user