feat(订单成本口径): B 界面 —— 「库存成本」列 + 单位成本改为「(采购+库存)÷销量」真实均价
承接后端 `9ab7564`(API 已返回 `stock_cover_cost`),界面补齐,使开发者定稿的口径**看得见**:
行真实成本 = 采购成本 + 库存成本;**单位成本 = 两者相加 ÷ 销量**。
改动:
- `columns.ts`:`getCostMgmtSkuColumns` 在「采购成本」后新增「库存成本」列(`t('finance.cost.col.stockCoverCost')`),
同步 deprecated 常量;**列序 key 升版 v3 → v4**(否则老用户浏览器里存的列序看不到新列)。
- `types.ts`:`CostMgmtSkuColumnId` 增 `'stock_cover_cost'`;`SkuCostDetail` 增 `stock_cover_cost?: number`。
- `CostAccountingPanel.tsx`:行映射补 `stock_cover_cost`;新增 `case 'stock_cover_cost'` 单元格;
**单位成本改用 `realCost = purchaseAmt + stockCoverAmt`**(原先只用采购额 ÷ 销量 ⇒ 全额抵扣行会显示 ¥0)。
例:30 斤里抵 20 斤(批次均值 ¥40)+ 采 10 斤(¥30)⇒ 单位成本 = 70 ÷ 30 = **¥2.3333**。
- 三语:`finance.cost.col.stockCoverCost` = 库存成本 / Inventory cost / Biaya stok。
- 新增 `src/pages/finance/costAccounting/skuCostStockCoverColumn.contract.test.ts` 4 例锁住上述契约。
验证:
- 前端全量 **2 failed / 160 passed(162 文件)** —— 与本次改动前**完全一致**(两项均为既有红:
`SystemConfig.allowZeroCost`(HEAD 就红)与并发未跟踪的 `PickingManagement.outboundPhotoPreview`);
新增契约测试 4/4 通过。
- `tsc --noEmit`(web)0;webpack 重编译成功,并在**实际下发的 chunk**
`src_pages_finance_CostManagement_tsx.bundle.js` 里核到 `stock_cover_cost` / `cost.col.stockCoverCost` /
`stockCoverAmt` / `realCost`。
- 后端真库实测(`9ab7564` 提交信息内):BR002 三行全额抵扣行 → 采购 ¥0 + 库存成本 ¥32/¥60/¥45
⇒ 真实均价 ¥4/¥2/¥3。
- 门禁 8 通过 / 1 已知红 / 1 未执行,与基线一致。
提交范围:`src/utils/workflowApi.ts` 用**选择性暂存**(HEAD + 仅本次 DTO 那一处),
**未夹带**并发会话在该文件的未提交改动(其 `demandTaskId` 仍留在工作区)。
⏭ 仍未做:商品成本**导出明细**(`getSkuDirectCostLines`)仍是全量口径且无库存成本列 ⇒ 与页面暂不一致;
「库存抵扣」第三分类 + 订单行供应商第三取值(C 块)需与界面同批落地。
This commit is contained in:
@@ -90,6 +90,7 @@ export const finance: MessageDict = {
|
||||
'cost.col.quantity': 'Qty',
|
||||
'cost.col.unit': 'Unit',
|
||||
'cost.col.purchaseCost': 'Purchase cost',
|
||||
'cost.col.stockCoverCost': 'Inventory cost',
|
||||
'cost.col.unitCost': 'Unit cost',
|
||||
'cost.status.pending': 'Pending review',
|
||||
'cost.status.posted': 'Posted',
|
||||
|
||||
@@ -90,6 +90,7 @@ export const finance: MessageDict = {
|
||||
'cost.col.quantity': 'Qty',
|
||||
'cost.col.unit': 'Satuan',
|
||||
'cost.col.purchaseCost': 'Biaya pembelian',
|
||||
'cost.col.stockCoverCost': 'Biaya stok',
|
||||
'cost.col.unitCost': 'Biaya satuan',
|
||||
'cost.status.pending': 'Menunggu tinjauan',
|
||||
'cost.status.posted': 'Terbukukan',
|
||||
|
||||
@@ -90,6 +90,7 @@ export const finance: MessageDict = {
|
||||
'cost.col.quantity': '销量',
|
||||
'cost.col.unit': '单位',
|
||||
'cost.col.purchaseCost': '采购成本',
|
||||
'cost.col.stockCoverCost': '库存成本',
|
||||
'cost.col.unitCost': '单位成本',
|
||||
'cost.status.pending': '待审核',
|
||||
'cost.status.posted': '已入账',
|
||||
|
||||
@@ -1827,6 +1827,8 @@ export const CostAccountingPanel: React.FC<CostAccountingPanelProps> = ({
|
||||
unit: String(row.unit || '').trim() || undefined,
|
||||
weight: safeAmount(row.weight ?? row.quantity, 0),
|
||||
purchase_cost: safeAmount(row.purchase_cost, 0),
|
||||
// 库存成本(账本 inventory_cover):与采购成本并列,两者相加 = 行真实成本
|
||||
stock_cover_cost: safeAmount(row.stock_cover_cost, 0),
|
||||
settled_processing_cost: safeAmount(row.settled_processing_cost, 0),
|
||||
purchase_self_cost: safeAmount(row.purchase_self_cost, 0),
|
||||
purchase_supplier_cost: safeAmount(row.purchase_supplier_cost, 0),
|
||||
@@ -4186,8 +4188,15 @@ export const CostAccountingPanel: React.FC<CostAccountingPanelProps> = ({
|
||||
) : (
|
||||
panel.rows.map((sku) => {
|
||||
const purchaseAmt = panel.amountOf(sku);
|
||||
const stockCoverAmt = safeAmount(sku.stock_cover_cost, 0);
|
||||
/**
|
||||
* **单位成本 = 行真实成本 ÷ 销量 =(采购成本 + 库存成本)÷ 销量**
|
||||
* (开发者 2026-10-14 定稿:如 30 斤里抵 20 斤、采 10 斤,
|
||||
* 真实成本价 =(抵扣金额 + 采购金额)÷ 30)。
|
||||
*/
|
||||
const realCost = purchaseAmt + stockCoverAmt;
|
||||
const unit =
|
||||
sku.quantity > 0 ? purchaseAmt / sku.quantity : safeAmount(sku.unit_cost, 0);
|
||||
sku.quantity > 0 ? realCost / sku.quantity : safeAmount(sku.unit_cost, 0);
|
||||
return (
|
||||
<tr
|
||||
key={`${panel.key}-${sku.sku_code}-${sku.is_extra_dish ? 'extra' : 'base'}-${sku.purchase_self_cost > 0 ? 'self' : 'sup'}`}
|
||||
@@ -4236,6 +4245,15 @@ export const CostAccountingPanel: React.FC<CostAccountingPanelProps> = ({
|
||||
¥{purchaseAmt.toLocaleString()}
|
||||
</td>
|
||||
);
|
||||
case 'stock_cover_cost':
|
||||
return (
|
||||
<td
|
||||
key={col.id}
|
||||
className="px-3 py-3 text-sm text-gray-600 text-right"
|
||||
>
|
||||
¥{stockCoverAmt.toLocaleString()}
|
||||
</td>
|
||||
);
|
||||
case 'unit_cost':
|
||||
return (
|
||||
<td key={col.id} className="px-3 py-3 text-sm text-gray-600 text-right">
|
||||
|
||||
@@ -158,6 +158,7 @@ export const COST_MGMT_SKU_COLUMNS: Array<TableColumnDef<CostMgmtSkuColumnId>> =
|
||||
{ id: 'quantity', label: '销量' },
|
||||
{ id: 'unit', label: '单位' },
|
||||
{ id: 'purchase_cost', label: '采购成本' },
|
||||
{ id: 'stock_cover_cost', label: '库存成本' },
|
||||
{ id: 'unit_cost', label: '单位成本' },
|
||||
];
|
||||
|
||||
@@ -168,8 +169,9 @@ export function getCostMgmtSkuColumns(t: TFn): Array<TableColumnDef<CostMgmtSkuC
|
||||
{ id: 'quantity', label: t('finance.cost.col.quantity') },
|
||||
{ id: 'unit', label: t('finance.cost.col.unit') },
|
||||
{ id: 'purchase_cost', label: t('finance.cost.col.purchaseCost') },
|
||||
{ id: 'stock_cover_cost', label: t('finance.cost.col.stockCoverCost') },
|
||||
{ id: 'unit_cost', label: t('finance.cost.col.unitCost') },
|
||||
];
|
||||
}
|
||||
|
||||
export const COST_MGMT_SKU_COLUMN_ORDER_KEY = 'table_column_order:cost-mgmt-sku:v3';
|
||||
export const COST_MGMT_SKU_COLUMN_ORDER_KEY = 'table_column_order:cost-mgmt-sku:v4';
|
||||
|
||||
@@ -0,0 +1,45 @@
|
||||
import { readFileSync } from 'node:fs';
|
||||
import { describe, expect, it } from 'vitest';
|
||||
|
||||
/**
|
||||
* 「订单商品成本」新增 **库存成本** 列 + **单位成本 = 行真实成本 ÷ 销量**
|
||||
* (开发者 2026-10-14 定稿,见
|
||||
* docs/design/20261014-订单成本排除独立进货与库存成本分类.md §5.1)。
|
||||
*
|
||||
* 口径:行真实成本 = 采购成本(缺口量 × unit_cost)+ 库存成本(账本 `inventory_cover` 结转额);
|
||||
* 真实成本价 = 两者相加 ÷ 销量。
|
||||
*/
|
||||
const read = (rel: string) => readFileSync(new URL(rel, import.meta.url), 'utf8');
|
||||
|
||||
describe('商品成本:库存成本列与真实均价', () => {
|
||||
const columns = read('./columns.ts');
|
||||
const types = read('./types.ts');
|
||||
const panel = read('./CostAccountingPanel.tsx');
|
||||
const api = read('../../../utils/workflowApi.ts');
|
||||
|
||||
it('列定义与列 id 都已登记(含列序 key 升版)', () => {
|
||||
expect(columns).toContain("{ id: 'stock_cover_cost', label: t('finance.cost.col.stockCoverCost') }");
|
||||
expect(types).toContain("| 'stock_cover_cost'");
|
||||
expect(types).toContain('stock_cover_cost?: number');
|
||||
// 持久化的列序要升版,否则老用户看不到新列
|
||||
expect(columns).toContain("COST_MGMT_SKU_COLUMN_ORDER_KEY = 'table_column_order:cost-mgmt-sku:v4'");
|
||||
});
|
||||
|
||||
it('单位成本用「采购 + 库存」真实成本,不再只用采购', () => {
|
||||
expect(panel).toContain('const stockCoverAmt = safeAmount(sku.stock_cover_cost, 0)');
|
||||
expect(panel).toContain('const realCost = purchaseAmt + stockCoverAmt');
|
||||
expect(panel).toMatch(/sku\.quantity > 0 \? realCost \/ sku\.quantity/);
|
||||
expect(panel).toContain("case 'stock_cover_cost':");
|
||||
});
|
||||
|
||||
it('接口类型带 stock_cover_cost', () => {
|
||||
expect(api).toContain('stock_cover_cost?: number');
|
||||
});
|
||||
|
||||
it('三语词条齐(库存成本 / Inventory cost / Biaya stok)', () => {
|
||||
const locale = (l: string) => read(`../../../i18n/locales/${l}/finance.ts`);
|
||||
expect(locale('zh-CN')).toContain("'cost.col.stockCoverCost': '库存成本'");
|
||||
expect(locale('en')).toContain("'cost.col.stockCoverCost': 'Inventory cost'");
|
||||
expect(locale('id')).toContain("'cost.col.stockCoverCost': 'Biaya stok'");
|
||||
});
|
||||
});
|
||||
@@ -57,6 +57,8 @@ export type CostMgmtSkuColumnId =
|
||||
| 'quantity'
|
||||
| 'unit'
|
||||
| 'purchase_cost'
|
||||
/** 库存成本(账本 inventory_cover 结转额):与采购成本并列,两者相加 = 行真实成本 */
|
||||
| 'stock_cover_cost'
|
||||
| 'unit_cost';
|
||||
|
||||
export interface CostDetail {
|
||||
@@ -100,6 +102,14 @@ export interface SkuCostDetail {
|
||||
unit?: string;
|
||||
weight: number;
|
||||
purchase_cost: number;
|
||||
/**
|
||||
* **库存成本** = 该 SKU 在本窗口内经库存抵扣拿到的那部分货的成本
|
||||
* (账本 `cost_details.inventory_cover` 的结转额)。
|
||||
* 与 `purchase_cost`(缺口量 × unit_cost)并列:行真实成本 = 两者相加,
|
||||
* 单位成本 = 两者相加 ÷ 数量。见
|
||||
* docs/design/20261014-订单成本排除独立进货与库存成本分类.md §5.1
|
||||
*/
|
||||
stock_cover_cost?: number;
|
||||
/**
|
||||
* 仓内加工行的加工结算成本(后端 processing_settled_unit_cost × 数量)。
|
||||
* 仅排行展示与毛利率使用,不计入采购成本合计(原料已按自采计价)。
|
||||
|
||||
@@ -4744,6 +4744,14 @@ export interface SkuDirectCostDto {
|
||||
quantity: number;
|
||||
weight: number;
|
||||
purchase_cost: number;
|
||||
/**
|
||||
* **库存成本** = 该 SKU 在本窗口内经库存抵扣拿到的那部分货的成本
|
||||
* (账本 `cost_details.inventory_cover` 的结转额)。
|
||||
* 与 `purchase_cost`(缺口量 × unit_cost)并列:**行真实成本 = 两者相加**,
|
||||
* `unit_cost` = 两者相加 ÷ 销量。见
|
||||
* docs/design/20261014-订单成本排除独立进货与库存成本分类.md §5.1
|
||||
*/
|
||||
stock_cover_cost?: number;
|
||||
purchase_self_cost?: number;
|
||||
purchase_supplier_cost?: number;
|
||||
labor_sorting_cost: number;
|
||||
|
||||
Reference in New Issue
Block a user