From 5dd169832cab9f1645b441419ad64e53746a43ff Mon Sep 17 00:00:00 2001 From: Ubuntu Date: Wed, 4 Nov 2026 12:49:27 +0800 Subject: [PATCH] =?UTF-8?q?feat(=E5=95=86=E5=93=81=E7=AE=A1=E7=90=86):=20?= =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E4=BB=93=E5=86=85=E5=8A=A0=E5=B7=A5=E5=8E=9F?= =?UTF-8?q?=E6=9D=90=E6=96=99=20BOM=20=E9=85=8D=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/i18n/locales/en/products.ts | 3 ++ src/i18n/locales/id/products.ts | 3 ++ src/i18n/locales/zh-CN/products.ts | 3 ++ src/pages/products/SkuManagement.tsx | 53 ++++++++++++++++++++++++++++ src/utils/productCatalog.ts | 4 +++ 5 files changed, 66 insertions(+) diff --git a/src/i18n/locales/en/products.ts b/src/i18n/locales/en/products.ts index 6f6fc38..bcf2372 100644 --- a/src/i18n/locales/en/products.ts +++ b/src/i18n/locales/en/products.ts @@ -373,4 +373,7 @@ export const products: MessageDict = { 'units.toast.opFail': 'Operation failed', 'form.processingBomCreateMaterial': 'Create raw material', 'form.processingBomCreateMaterialNamed': 'Create "{name}"', + 'form.processingBomTitle': 'In-house processing raw material (BOM)', + 'form.processingBomHint': 'Configure raw material so orders using in-house processing auto-create raw purchase drafts.', + 'form.processingBomMaterialPh': 'Raw material SKU', }; diff --git a/src/i18n/locales/id/products.ts b/src/i18n/locales/id/products.ts index 10f4808..4d16a2f 100644 --- a/src/i18n/locales/id/products.ts +++ b/src/i18n/locales/id/products.ts @@ -377,4 +377,7 @@ export const products: MessageDict = { 'units.toast.opFail': 'Operasi gagal', 'form.processingBomCreateMaterial': 'Buat bahan baku', 'form.processingBomCreateMaterialNamed': 'Buat "{name}"', + 'form.processingBomTitle': 'Bahan baku proses (BOM)', + 'form.processingBomHint': 'Atur bahan baku agar pesanan proses gudang otomatis membuat draf pembelian.', + 'form.processingBomMaterialPh': 'SKU bahan baku', }; diff --git a/src/i18n/locales/zh-CN/products.ts b/src/i18n/locales/zh-CN/products.ts index 9798ae8..cbfc78c 100644 --- a/src/i18n/locales/zh-CN/products.ts +++ b/src/i18n/locales/zh-CN/products.ts @@ -367,4 +367,7 @@ export const products: MessageDict = { 'units.toast.opFail': '操作失败', 'form.processingBomCreateMaterial': '新建原材料商品', 'form.processingBomCreateMaterialNamed': '新建商品「{name}」', + 'form.processingBomTitle': '仓内加工原材料(BOM)', + 'form.processingBomHint': '成品配置原材料后,下单选择仓内加工会自动生成原料采购。', + 'form.processingBomMaterialPh': '原材料 SKU,例如 SKU66117900891', }; diff --git a/src/pages/products/SkuManagement.tsx b/src/pages/products/SkuManagement.tsx index bf7c764..c61fde0 100644 --- a/src/pages/products/SkuManagement.tsx +++ b/src/pages/products/SkuManagement.tsx @@ -139,6 +139,7 @@ interface Sku { /** 库存预警:勾选后才参与看板/库存页的低库存预警 */ /** 库存预警安全线:可用量合计低于此值即预警;0 = 不参与预警 */ low_stock_alert_qty?: number; + processing_bom?: Array<{ method: string; material_sku: string; loss_rate: number }> | null; created_at: string; } @@ -409,6 +410,8 @@ export const SkuManagement: React.FC = () => { status: 1, low_stock_alert_qty: 0, storage_zone: '', + processing_bom_material_sku: '', + processing_bom_loss_percent: 0, }); // Show toast notification @@ -1297,6 +1300,14 @@ export const SkuManagement: React.FC = () => { const unit = formData.unit.trim() || '斤'; const pricingUnit = formData.pricing_unit.trim() || unit; const packFactors = packFactorRowsToObject(formData.pack_factor_rows); + const processingBomMaterial = String(formData.processing_bom_material_sku || '').trim(); + const processingBomLossRate = Math.max( + 0, + Math.min(0.95, (Number(formData.processing_bom_loss_percent) || 0) / 100) + ); + const processingBom = processingBomMaterial + ? [{ method: '', material_sku: processingBomMaterial, loss_rate: processingBomLossRate }] + : []; if (editingSku) { const imageChanged = @@ -1315,6 +1326,7 @@ export const SkuManagement: React.FC = () => { default_loss_threshold: useLossThreshold ? formData.default_loss_threshold : null, stock_mode: null, low_stock_alert_qty: normalizeLowStockAlertQty(formData.low_stock_alert_qty), + processing_bom: processingBom, tax_code: formData.tax_code.trim() || undefined, tax_rate: Number(formData.tax_rate) || 0, status: formData.status, @@ -1353,6 +1365,7 @@ export const SkuManagement: React.FC = () => { default_loss_threshold: useLossThreshold ? formData.default_loss_threshold : undefined, stock_mode: null, low_stock_alert_qty: normalizeLowStockAlertQty(formData.low_stock_alert_qty), + processing_bom: processingBom, tax_code: formData.tax_code.trim() || undefined, tax_rate: Number(formData.tax_rate) || 0, status: formData.status, @@ -1812,6 +1825,8 @@ export const SkuManagement: React.FC = () => { tax_rate: Number(sku.tax_rate) || 0, status: sku.status, low_stock_alert_qty: Number(sku.low_stock_alert_qty) || 0, + processing_bom_material_sku: String(sku.processing_bom?.[0]?.material_sku || ''), + processing_bom_loss_percent: Math.round(Number(sku.processing_bom?.[0]?.loss_rate || 0) * 10000) / 100, }); setTaxRatePercentInput(taxRateToPercentInput(sku.tax_rate)); setHasManualImage(Boolean(sku.image_url?.trim() && !isGeneratedFallbackImage(sku.image_url))); @@ -1934,6 +1949,8 @@ export const SkuManagement: React.FC = () => { tax_rate: 0, status: 1, low_stock_alert_qty: 0, + processing_bom_material_sku: '', + processing_bom_loss_percent: 0, }); setTaxRatePercentInput('0'); setHasManualImage(false); @@ -2942,6 +2959,42 @@ export const SkuManagement: React.FC = () => { className="app-input w-full px-3 py-2 border border-slate-300 rounded-lg text-slate-900 placeholder:text-slate-400 focus:ring-2 focus:ring-[var(--app-theme-accent)] dark:text-slate-100" /> +
+ +

+ {t('products.form.processingBomHint')} +

+
+ + setFormData({ ...formData, processing_bom_material_sku: e.target.value }) + } + placeholder={t('products.form.processingBomMaterialPh')} + className="app-input w-full px-3 py-2 border border-slate-300 rounded-lg text-slate-900" + /> +
+ + setFormData({ + ...formData, + processing_bom_loss_percent: Number(e.target.value) || 0, + }) + } + className="app-input w-full px-3 py-2 border border-slate-300 rounded-lg text-slate-900" + /> + % +
+
+
; }): Record { const branch = String(input.branchCode || readOperatingBranchCode() || '').trim(); const code = input.code.trim(); @@ -418,6 +419,7 @@ export function buildCatalogProductInsertData(input: { tax_code: input.tax_code?.trim() || null, tax_rate: input.tax_rate ?? null, status: input.status ?? 1, + ...(input.processing_bom !== undefined ? { processing_bom: input.processing_bom } : {}), }; } @@ -442,6 +444,7 @@ export async function insertCatalogProduct(input: { status?: number; /** 库存预警:勾选后才参与低库存预警 */ low_stock_alert_qty?: number; + processing_bom?: Array<{ method: string; material_sku: string; loss_rate: number }>; }): Promise { const { error } = await supabase.from('product_catalog').insert(buildCatalogProductInsertData(input)); if (error) throw error; @@ -502,6 +505,7 @@ export async function updateCatalogProduct( direct_delivery: boolean; /** 库存预警安全线:可用量合计低于此值即预警;0 = 不参与预警(范围 0~300) */ low_stock_alert_qty: number; + processing_bom: Array<{ method: string; material_sku: string; loss_rate: number }>; }> ): Promise { const { error } = await supabase.from('product_catalog').update(patch).eq('code', code).eq('item_type', 'product');