feat(库存): 入库时间取该批次最早一次入库流水(stock_in/inspection_in),列表返回 inbound_at;撤销用创建时间兜底
CI / server typecheck + tests (push) Canceled after 0s
CI / web typecheck + tests + miniprogram syntax (push) Canceled after 0s
CI / eslint (观察项,C7 骨架) (push) Canceled after 0s
CI / npm audit (critical 硬拦) (push) Canceled after 0s

This commit is contained in:
Ubuntu
2026-10-20 22:19:52 +08:00
parent eab91c266e
commit e2909a88fb
3 changed files with 16 additions and 4 deletions
+11 -2
View File
@@ -161,6 +161,13 @@ export async function listInventoryForManagement(
LEFT JOIN skus sk ON sk.sku_code = inv.sku_code
LEFT JOIN categories cat ON cat.category_code = sk.category_code
LEFT JOIN suppliers sup ON sup.supplier_code = inv.supplier_code
LEFT JOIN LATERAL (
SELECT to_char(min(l.created_at), 'YYYY-MM-DD') AS inbound_at
FROM inventory_logs l
WHERE l.branch_code = inv.branch_code
AND l.batch_no = inv.batch_no
AND l.operation_type IN ('stock_in', 'inspection_in')
) inb ON TRUE
`;
const statsParams: unknown[] = [];
@@ -218,7 +225,7 @@ export async function listInventoryForManagement(
const listParams = [...params, pageSize, offset];
const listResult = await pool.query(
`SELECT inv.*,
`SELECT inv.*, inb.inbound_at AS inbound_at,
-- 批次产地(2026-10-21 批次级产地):批次优先,空则前端按商品档案默认值展示;
-- 返回固定键名 batch_origin(弹窗回显读 (item as any).batch_origin)
COALESCE(inv.origin, '') AS batch_origin,
@@ -229,7 +236,7 @@ export async function listInventoryForManagement(
sk.origin,
cat.category_name,
sup.company_name AS supplier_name,
EXISTS (
(
SELECT count(*)::int FROM inventory_batch_report_matches m WHERE m.inventory_id = inv.id
) AS batch_report_count
${fromSql}
@@ -342,6 +349,8 @@ export async function listInventoryForManagement(
shelf_life: item.shelf_life == null ? null : String(item.shelf_life),
/** 是否存在已确认的入库批次报告关联(供列表标注「缺少批次报告」) */
has_batch_report: Number(item.batch_report_count || 0) > 0,
/** 入库时间 = 该批次**最早一次**入库流水(stock_in / inspection_in)的日期;无流水则 null */
inbound_at: item.inbound_at ? String(item.inbound_at) : null,
batch_report_count: Number(item.batch_report_count || 0),
/** 批次级产地(空串 = 未设置;前端弹窗回显与「留空走商品默认」共用该键) */
batch_origin: item.batch_origin == null ? '' : String(item.batch_origin),
@@ -287,6 +287,7 @@ type ManualPickRow = {
sku_name?: string;
production_date?: string;
inbound_at?: string | null;
created_at?: string | null;
available_qty?: number;
unit?: string;
storage_zone?: string;
@@ -375,7 +376,7 @@ const ManualBatchPicker: React.FC<{
{t('inventory.batchReport.candidateBatch')}: {r.batch_no || '—'}
</span>
<span className="app-foreground-muted">
{r.inbound_at ? `${t('inventory.batchReport.inboundAt')} ${r.inbound_at}` : '—'}{r.production_date ? ` · ${t('inventory.col.prodDate')} ${String(r.production_date).slice(0, 10)}` : ''}
{r.inbound_at ? `${t('inventory.batchReport.inboundAt')} ${r.inbound_at}${r.production_date ? ` · ` : ''}` : ''}{r.production_date ? `${t('inventory.col.prodDate')} ${String(r.production_date).slice(0, 10)}` : (r.inbound_at ? '' : '—')}
</span>
<span className="app-foreground-muted">
{r.available_qty ?? '—'} {r.unit || ''}
@@ -475,7 +476,7 @@ const ReportCard: React.FC<{
{t('inventory.batchReport.candidateBatch')}: {c.batch_no || '—'}
</span>
<span className="app-foreground-muted">
{c.inbound_at ? `${t('inventory.batchReport.inboundAt')} ${c.inbound_at}` : '—'}{c.production_date ? ` · ${t('inventory.col.prodDate')} ${String(c.production_date).slice(0, 10)}` : ''}
{c.inbound_at ? `${t('inventory.batchReport.inboundAt')} ${c.inbound_at}${c.production_date ? ` · ` : ''}` : ''}{c.production_date ? `${t('inventory.col.prodDate')} ${String(c.production_date).slice(0, 10)}` : (c.inbound_at ? '' : '—')}
</span>
<span className="app-foreground-muted">
{c.available_qty ?? '—'} {c.unit || ''}
+2
View File
@@ -3932,6 +3932,8 @@ export interface InventoryBatchReportCandidate {
production_date: string | null;
/** 入库时间(列表展示用;2026-10-20 起展示入库时间而非生产日期) */
inbound_at?: string | null;
/** 批次落库时间(解析链路只返回这个字段,前端用它兜底显示"入库时间") */
created_at?: string | null;
available_qty: number | null;
unit: string | null;
spec: string | null;