feat(商品管理): 增加仓内加工原材料 BOM 配置
This commit is contained in:
@@ -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',
|
||||
};
|
||||
|
||||
@@ -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',
|
||||
};
|
||||
|
||||
@@ -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',
|
||||
};
|
||||
|
||||
@@ -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"
|
||||
/>
|
||||
</div>
|
||||
<div className="col-span-full rounded-lg border app-border p-3">
|
||||
<label className="block text-sm font-medium text-slate-700 dark:text-slate-200 mb-1">
|
||||
{t('products.form.processingBomTitle')}
|
||||
</label>
|
||||
<p className="text-xs app-foreground-muted mb-2">
|
||||
{t('products.form.processingBomHint')}
|
||||
</p>
|
||||
<div className="grid grid-cols-1 sm:grid-cols-[minmax(0,1fr)_8rem] gap-2">
|
||||
<input
|
||||
type="text"
|
||||
value={formData.processing_bom_material_sku}
|
||||
onChange={(e) =>
|
||||
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"
|
||||
/>
|
||||
<div className="flex items-center gap-1">
|
||||
<input
|
||||
type="number"
|
||||
min={0}
|
||||
max={95}
|
||||
step="0.01"
|
||||
value={formData.processing_bom_loss_percent}
|
||||
onChange={(e) =>
|
||||
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"
|
||||
/>
|
||||
<span className="text-xs app-foreground-muted">%</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div>
|
||||
<label className="block text-sm font-medium text-slate-700 dark:text-slate-200 mb-1">{t('products.form.brand')}</label>
|
||||
<input
|
||||
|
||||
@@ -393,6 +393,7 @@ export function buildCatalogProductInsertData(input: {
|
||||
tax_rate?: number;
|
||||
status?: number;
|
||||
low_stock_alert_qty?: number;
|
||||
processing_bom?: Array<{ method: string; material_sku: string; loss_rate: number }>;
|
||||
}): Record<string, unknown> {
|
||||
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<void> {
|
||||
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<void> {
|
||||
const { error } = await supabase.from('product_catalog').update(patch).eq('code', code).eq('item_type', 'product');
|
||||
|
||||
Reference in New Issue
Block a user