feat(小程序独立加工): 创建改多行原料;独立加工完工改「申报成品」(成品多行/成本自动均分/损耗自动差额/继承开关);订单与需求单加工流程保持原样
This commit is contained in:
@@ -136,3 +136,19 @@
|
||||
| 原料成本来源 | `processing_task_materials.material_cost` 合计(真实扣减批次成本,不是估算) | — |
|
||||
|
||||
证据:契约测试 15 项(新增 3 项:损耗自动联动、成本自动均分且人工改过不覆盖、原料成本来自原料行);**删掉损耗自动赋值那一行后 1 条变红**,还原复绿;全量 1409 项 / 4 既有红灯无关。
|
||||
|
||||
## 10. 追加(同日第六次提交):小程序同步(Web 已通)
|
||||
|
||||
开发者:「请你修改小程序方面的代码 你要记住我们正常录单创建的加工单与独立加工单是两回事」。
|
||||
|
||||
**移动端路由**(`server/src/routes/mobile/mobilePurchaseRoutes.ts`,与 Web 共用同一服务,不分端):
|
||||
- `POST /mobile/processing/standalone/create` 扩展 `materials[]` + `client_request_no`(老版本小程序只传 `sku_code+qty` 仍可用)
|
||||
- 新增 `POST /mobile/processing/standalone/:taskId/complete`、`GET /mobile/processing/standalone/:taskId/lines`
|
||||
|
||||
**小程序面板**(`miniprogram/components/processing-panel/`):
|
||||
- **创建独立加工**:搜索商品 → **点一次加一行原料**(可多行、逐行数量、可删)→ 提交带 `client_request_no`;**需求单领料仍走原来的单选块**(`pickTaskId` 分支未改)
|
||||
- **完工分流**:`source_type === 'standalone'` ⇒ 打开「申报加工成品」弹窗(成品多行、搜索加入、**成本默认均分可改**、**损耗自动差额可改**、**两个继承开关**、确认后 `processing_in` 回仓);**订单/需求单仍是毛重/净重 + 加工单价**(`completeProcessingWork` 原样保留)
|
||||
- API 客户端:`completeStandaloneProcessingTask`、`listStandaloneLines`;成品搜索复用 `/mobile/inventory/sku-options`
|
||||
|
||||
**证据**:新增小程序契约测试 `miniprogram/components/processing-panel/standalone.contract.test.js`(5 条,node 直接跑)——**删掉独立加工完工分流后 1 条失败**,还原通过;后端 `tsc --noEmit` 0 error。
|
||||
小程序「新增商品」(建品)暂未做,Web 已有,待真机验证后再补。
|
||||
|
||||
@@ -5,6 +5,9 @@ const {
|
||||
pickDemandSheetMaterial,
|
||||
startProcessingTask,
|
||||
completeProcessingWork,
|
||||
completeStandaloneProcessingTask,
|
||||
listStandaloneLines,
|
||||
fetchStockInboundSkuOptions,
|
||||
uploadProcessingInspectPhoto,
|
||||
submitProcessingInspection,
|
||||
} = require('../../utils/request');
|
||||
@@ -192,6 +195,20 @@ Component({
|
||||
},
|
||||
|
||||
data: {
|
||||
/** 独立加工:多行原料(与录单/Web 同口径) */
|
||||
createMaterials: [],
|
||||
/** 独立加工:成品申报(多行成品 + 损耗 + 报告继承) */
|
||||
showOutputModal: false,
|
||||
outputTaskId: '',
|
||||
outputTaskCode: '',
|
||||
outputUnit: '',
|
||||
outputMaterialQty: 0,
|
||||
outputMaterialCost: 0,
|
||||
outputRows: [],
|
||||
outputLoss: '',
|
||||
outputLossManual: false,
|
||||
outputAutoLoss: 0,
|
||||
outputAutoUnitCost: 0,
|
||||
activeTab: 'work',
|
||||
viewMode: 'today',
|
||||
dateField: 'created_at',
|
||||
@@ -458,6 +475,11 @@ Component({
|
||||
const { id } = e.currentTarget.dataset;
|
||||
const row = this.data.rows.find((item) => item.id === id);
|
||||
if (!row) return;
|
||||
/** 独立加工 ≠ 订单/需求单加工:独立加工完工是**申报成品**,其它仍是毛重/净重(保持原样) */
|
||||
if (String(row.source_type || '') === 'standalone') {
|
||||
this.openOutputForm(row);
|
||||
return;
|
||||
}
|
||||
|
||||
const unitPrice = displayUnitPrice(row);
|
||||
const workForm = {
|
||||
@@ -489,6 +511,7 @@ Component({
|
||||
pickDemandInboundText: '',
|
||||
pickDemandUnit: '',
|
||||
createSkuOptions: [],
|
||||
createMaterials: [],
|
||||
createForm: {
|
||||
skuSearch: '',
|
||||
selectedSku: null,
|
||||
@@ -570,14 +593,101 @@ Component({
|
||||
const skuCode = e.currentTarget.dataset.sku;
|
||||
const selected = this.data.createSkuOptions.find((opt) => opt.sku_code === skuCode);
|
||||
if (!selected) return;
|
||||
/** 独立加工:点一次就**加一行原料**(多行);需求单领料:仍按单选(保持原流程) */
|
||||
if (!this.data.pickTaskId) {
|
||||
const exists = this.data.createMaterials.some((row) => row.sku_code === selected.sku_code);
|
||||
this.setData({
|
||||
createSkuOptions: [],
|
||||
createForm: { ...this.data.createForm, skuSearch: '' },
|
||||
createMaterials: exists
|
||||
? this.data.createMaterials
|
||||
: [
|
||||
...this.data.createMaterials,
|
||||
{
|
||||
sku_code: selected.sku_code,
|
||||
sku_name: selected.sku_name,
|
||||
unit: selected.unit || '',
|
||||
display_unit: displayUnit(selected.unit),
|
||||
available_qty: Number(selected.available_qty) || 0,
|
||||
qty: '',
|
||||
},
|
||||
],
|
||||
});
|
||||
return;
|
||||
}
|
||||
this.setData({
|
||||
createForm: { ...this.data.createForm, selectedSku: selected, skuSearch: selected.sku_name },
|
||||
createSkuOptions: [],
|
||||
});
|
||||
},
|
||||
|
||||
/** 多行原料:改数量 / 删除 */
|
||||
onCreateMaterialQty(e) {
|
||||
const skuCode = e.currentTarget.dataset.sku;
|
||||
const value = e.detail.value || '';
|
||||
this.setData({
|
||||
createMaterials: this.data.createMaterials.map((row) =>
|
||||
row.sku_code === skuCode ? { ...row, qty: value } : row
|
||||
),
|
||||
});
|
||||
},
|
||||
|
||||
removeCreateMaterial(e) {
|
||||
const skuCode = e.currentTarget.dataset.sku;
|
||||
this.setData({
|
||||
createMaterials: this.data.createMaterials.filter((row) => row.sku_code !== skuCode),
|
||||
});
|
||||
},
|
||||
|
||||
async submitCreate() {
|
||||
const { createForm } = this.data;
|
||||
/** 独立加工:多行原料校验(需求单领料仍走下面的单选校验,一行不改) */
|
||||
if (!this.data.pickTaskId) {
|
||||
const rows = this.data.createMaterials || [];
|
||||
if (!rows.length) {
|
||||
wx.showToast({ title: '请选择原料商品', icon: 'none' });
|
||||
return;
|
||||
}
|
||||
for (let i = 0; i < rows.length; i += 1) {
|
||||
const qty = Number(rows[i].qty);
|
||||
if (!Number.isFinite(qty) || qty <= 0) {
|
||||
wx.showToast({ title: `第 ${i + 1} 行数量须大于 0`, icon: 'none' });
|
||||
return;
|
||||
}
|
||||
if (qty > rows[i].available_qty + 1e-9) {
|
||||
wx.showToast({ title: `第 ${i + 1} 行库存不足:可用 ${rows[i].available_qty}`, icon: 'none' });
|
||||
return;
|
||||
}
|
||||
}
|
||||
const method = String(createForm.processingMethod || '').trim();
|
||||
if (!method) {
|
||||
wx.showToast({ title: '请填写加工方式', icon: 'none' });
|
||||
return;
|
||||
}
|
||||
const price = createForm.processUnitPrice === '' ? null : Number(createForm.processUnitPrice);
|
||||
if (price != null && (!Number.isFinite(price) || price < 0)) {
|
||||
wx.showToast({ title: '加工单价不能为负数', icon: 'none' });
|
||||
return;
|
||||
}
|
||||
this.setData({ saving: true });
|
||||
try {
|
||||
await createStandaloneProcessingTask({
|
||||
materials: rows.map((row) => ({ sku_code: row.sku_code, qty: Number(row.qty) })),
|
||||
processing_method: method,
|
||||
process_unit_price: price,
|
||||
remark: String(createForm.remark || '').trim() || undefined,
|
||||
client_request_no: `spg-${Date.now()}-${Math.random().toString(36).slice(2, 10)}`,
|
||||
});
|
||||
wx.showToast({ title: '创建成功', icon: 'success' });
|
||||
this.closeCreateForm();
|
||||
this.applyTab('work');
|
||||
} catch (err) {
|
||||
wx.showToast({ title: err.message || '创建失败', icon: 'none' });
|
||||
} finally {
|
||||
this.setData({ saving: false });
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (!createForm.selectedSku) {
|
||||
wx.showToast({ title: '请选择商品', icon: 'none' });
|
||||
return;
|
||||
@@ -631,6 +741,215 @@ Component({
|
||||
}
|
||||
},
|
||||
|
||||
/** 独立加工完工:申报成品(多行)——默认带出原料行,操作员填产出数量 */
|
||||
async openOutputForm(row) {
|
||||
const unit = displayUnit(row.unit);
|
||||
let materialQty = Number(row.source_qty) || 0;
|
||||
let materialCost = Number(row.material_cost) || 0;
|
||||
let outputs = [];
|
||||
try {
|
||||
const res = await listStandaloneLines(row.id);
|
||||
const materials = (res && res.data && res.data.materials) || [];
|
||||
if (materials.length) {
|
||||
materialQty = materials.reduce((sum, m) => sum + (Number(m.qty) || 0), 0);
|
||||
materialCost = materials.reduce((sum, m) => sum + (Number(m.material_cost) || 0), 0);
|
||||
outputs = materials.map((m) => ({
|
||||
sku_code: m.sku_code,
|
||||
sku_name: m.sku_name || m.sku_code,
|
||||
qty: '',
|
||||
unit_cost: '',
|
||||
unit_cost_manual: false,
|
||||
inherit_batch_report: false,
|
||||
inherit_inspection_report: false,
|
||||
}));
|
||||
}
|
||||
} catch (err) {
|
||||
// 读不到行时退回单据头
|
||||
}
|
||||
if (!outputs.length) {
|
||||
outputs = [
|
||||
{
|
||||
sku_code: row.sku_code,
|
||||
sku_name: row.item_name || row.sku_name || row.sku_code,
|
||||
qty: '',
|
||||
unit_cost: '',
|
||||
unit_cost_manual: false,
|
||||
inherit_batch_report: false,
|
||||
inherit_inspection_report: false,
|
||||
},
|
||||
];
|
||||
}
|
||||
this.setData({
|
||||
showOutputModal: true,
|
||||
outputTaskId: row.id,
|
||||
outputTaskCode: String(row.task_code || ''),
|
||||
outputUnit: unit,
|
||||
outputMaterialQty: materialQty,
|
||||
outputMaterialCost: materialCost,
|
||||
outputRows: outputs,
|
||||
outputLoss: '',
|
||||
outputLossManual: false,
|
||||
outputSkuSearch: '',
|
||||
outputSkuOptions: [],
|
||||
});
|
||||
this.recalcOutput();
|
||||
},
|
||||
|
||||
recalcOutput() {
|
||||
const rows = this.data.outputRows || [];
|
||||
const totalQty = rows.reduce((sum, r) => sum + (Number(r.qty) || 0), 0);
|
||||
const autoLoss = Math.max(0, Math.round((this.data.outputMaterialQty - totalQty) * 1000) / 1000);
|
||||
const autoUnit =
|
||||
totalQty > 0 && this.data.outputMaterialCost > 0
|
||||
? Math.round((this.data.outputMaterialCost / totalQty) * 10000) / 10000
|
||||
: 0;
|
||||
const nextRows = rows.map((r) => {
|
||||
if (r.unit_cost_manual || !(Number(r.qty) > 0) || autoUnit <= 0) return r;
|
||||
return { ...r, unit_cost: autoUnit.toFixed(2) };
|
||||
});
|
||||
this.setData({
|
||||
outputRows: nextRows,
|
||||
outputAutoLoss: autoLoss,
|
||||
outputAutoUnitCost: autoUnit,
|
||||
outputLoss: this.data.outputLossManual ? this.data.outputLoss : String(autoLoss),
|
||||
});
|
||||
},
|
||||
|
||||
onOutputQtyInput(e) {
|
||||
const skuCode = e.currentTarget.dataset.sku;
|
||||
const value = e.detail.value || '';
|
||||
this.setData(
|
||||
{ outputRows: this.data.outputRows.map((r) => (r.sku_code === skuCode ? { ...r, qty: value } : r)) },
|
||||
() => this.recalcOutput()
|
||||
);
|
||||
},
|
||||
|
||||
onOutputCostInput(e) {
|
||||
const skuCode = e.currentTarget.dataset.sku;
|
||||
const value = e.detail.value || '';
|
||||
this.setData({
|
||||
outputRows: this.data.outputRows.map((r) =>
|
||||
r.sku_code === skuCode ? { ...r, unit_cost: value, unit_cost_manual: true } : r
|
||||
),
|
||||
});
|
||||
},
|
||||
|
||||
onOutputLossInput(e) {
|
||||
this.setData({ outputLossManual: true, outputLoss: e.detail.value || '' });
|
||||
},
|
||||
|
||||
resetOutputLossAuto() {
|
||||
this.setData({ outputLossManual: false }, () => this.recalcOutput());
|
||||
},
|
||||
|
||||
toggleOutputInherit(e) {
|
||||
const skuCode = e.currentTarget.dataset.sku;
|
||||
const field = e.currentTarget.dataset.field;
|
||||
this.setData({
|
||||
outputRows: this.data.outputRows.map((r) =>
|
||||
r.sku_code === skuCode ? { ...r, [field]: !r[field] } : r
|
||||
),
|
||||
});
|
||||
},
|
||||
|
||||
removeOutputRow(e) {
|
||||
const skuCode = e.currentTarget.dataset.sku;
|
||||
this.setData({ outputRows: this.data.outputRows.filter((r) => r.sku_code !== skuCode) }, () =>
|
||||
this.recalcOutput()
|
||||
);
|
||||
},
|
||||
|
||||
async searchOutputSkus(e) {
|
||||
const search = e.detail.value || '';
|
||||
this.setData({ outputSkuSearch: search });
|
||||
if (!search.trim()) {
|
||||
this.setData({ outputSkuOptions: [] });
|
||||
return;
|
||||
}
|
||||
try {
|
||||
const res = await fetchStockInboundSkuOptions({ search: search.trim(), limit: 20 });
|
||||
this.setData({ outputSkuOptions: res.data || [] });
|
||||
} catch (err) {
|
||||
this.setData({ outputSkuOptions: [] });
|
||||
}
|
||||
},
|
||||
|
||||
addOutputSku(e) {
|
||||
const skuCode = e.currentTarget.dataset.sku;
|
||||
const opt = (this.data.outputSkuOptions || []).find((o) => o.sku_code === skuCode);
|
||||
if (!opt) return;
|
||||
if (this.data.outputRows.some((r) => r.sku_code === skuCode)) {
|
||||
this.setData({ outputSkuOptions: [], outputSkuSearch: '' });
|
||||
return;
|
||||
}
|
||||
this.setData(
|
||||
{
|
||||
outputSkuOptions: [],
|
||||
outputSkuSearch: '',
|
||||
outputRows: [
|
||||
...this.data.outputRows,
|
||||
{
|
||||
sku_code: opt.sku_code,
|
||||
sku_name: opt.sku_name,
|
||||
qty: '',
|
||||
unit_cost: '',
|
||||
unit_cost_manual: false,
|
||||
inherit_batch_report: false,
|
||||
inherit_inspection_report: false,
|
||||
},
|
||||
],
|
||||
},
|
||||
() => this.recalcOutput()
|
||||
);
|
||||
},
|
||||
|
||||
closeOutputForm() {
|
||||
this.setData({
|
||||
showOutputModal: false,
|
||||
outputTaskId: '',
|
||||
outputTaskCode: '',
|
||||
outputRows: [],
|
||||
outputLoss: '',
|
||||
outputLossManual: false,
|
||||
});
|
||||
},
|
||||
|
||||
async submitOutput() {
|
||||
const { outputTaskId, outputRows, outputMaterialQty } = this.data;
|
||||
if (!outputTaskId) return;
|
||||
const rows = (outputRows || []).filter((r) => Number(r.qty) > 0);
|
||||
if (!rows.length) {
|
||||
wx.showToast({ title: '请至少填写一行成品数量', icon: 'none' });
|
||||
return;
|
||||
}
|
||||
const totalOut = rows.reduce((sum, r) => sum + (Number(r.qty) || 0), 0);
|
||||
if (totalOut > outputMaterialQty + 1e-6) {
|
||||
wx.showToast({ title: `产出合计 ${totalOut} 不能大于原料投入 ${outputMaterialQty}`, icon: 'none' });
|
||||
return;
|
||||
}
|
||||
this.setData({ saving: true });
|
||||
try {
|
||||
await completeStandaloneProcessingTask(outputTaskId, {
|
||||
outputs: rows.map((r) => ({
|
||||
sku_code: r.sku_code,
|
||||
qty: Number(r.qty),
|
||||
unit_cost: r.unit_cost === '' ? null : Number(r.unit_cost),
|
||||
inherit_batch_report: r.inherit_batch_report === true,
|
||||
inherit_inspection_report: r.inherit_inspection_report === true,
|
||||
})),
|
||||
loss_qty: this.data.outputLoss === '' ? null : Number(this.data.outputLoss),
|
||||
});
|
||||
wx.showToast({ title: '成品已入库', icon: 'success' });
|
||||
this.closeOutputForm();
|
||||
this.applyTab('inspect');
|
||||
this.fetchData && this.fetchData();
|
||||
} catch (err) {
|
||||
wx.showToast({ title: err.message || '提交失败', icon: 'none' });
|
||||
} finally {
|
||||
this.setData({ saving: false });
|
||||
}
|
||||
},
|
||||
|
||||
onWorkInput(e) {
|
||||
const field = e.currentTarget.dataset.field;
|
||||
const nextForm = { ...this.data.workForm, [field]: e.detail.value };
|
||||
|
||||
@@ -155,8 +155,18 @@
|
||||
</view>
|
||||
</view>
|
||||
<view wx:if="{{createForm.selectedSku}}" class="selected-sku">已选 {{createForm.selectedSku.sku_name}}</view>
|
||||
<!-- 独立加工:多行原料(每行独立商品 + 数量,可删) -->
|
||||
<view wx:if="{{!pickTaskId}}" class="field">
|
||||
<text class="field-label">原料明细(可多行)</text>
|
||||
<view wx:if="{{!createMaterials.length}}" class="sheet-sub">请在上方搜索并选择原料商品</view>
|
||||
<view wx:for="{{createMaterials}}" wx:key="sku_code" class="selected-sku" style="display:flex;align-items:center;gap:8rpx;">
|
||||
<text style="flex:1;">{{index + 1}}. {{item.sku_name}}(可用 {{item.available_qty}}{{item.display_unit}})</text>
|
||||
<input class="field-input" style="width:140rpx;" type="digit" placeholder="数量" value="{{item.qty}}" data-sku="{{item.sku_code}}" bindinput="onCreateMaterialQty" />
|
||||
<text style="color:#e11d48;" data-sku="{{item.sku_code}}" catchtap="removeCreateMaterial">删除</text>
|
||||
</view>
|
||||
</view>
|
||||
<view class="field-grid">
|
||||
<view class="field">
|
||||
<view wx:if="{{pickTaskId}}" class="field">
|
||||
<text class="field-label">领料数量</text>
|
||||
<input class="field-input" type="digit" placeholder="0" value="{{createForm.qty}}" data-field="qty" bindinput="onCreateInput" />
|
||||
</view>
|
||||
@@ -183,6 +193,64 @@
|
||||
</root-portal>
|
||||
|
||||
<root-portal enable="{{true}}">
|
||||
<view wx:if="{{showOutputModal}}" class="sheet-mask" catchtouchmove="stopCreateTap" bindtap="closeOutputForm">
|
||||
<view class="sheet-card" catchtap="stopCreateTap">
|
||||
<view class="sheet-head">
|
||||
<view>
|
||||
<view class="sheet-title">申报加工成品</view>
|
||||
<view class="sheet-sub">{{outputTaskCode}} · 原料投入合计 {{outputMaterialQty}}{{outputUnit}}</view>
|
||||
</view>
|
||||
<view class="sheet-close" bindtap="closeOutputForm">×</view>
|
||||
</view>
|
||||
<view class="field">
|
||||
<text class="field-label">成品明细(可多行)</text>
|
||||
<input class="field-input" placeholder="搜索成品商品,点下方加入" value="{{outputSkuSearch}}" bindinput="searchOutputSkus" />
|
||||
<view wx:if="{{outputSkuOptions.length}}" class="sku-options">
|
||||
<view wx:for="{{outputSkuOptions}}" wx:key="sku_code" class="sku-option" catchtap="addOutputSku" data-sku="{{item.sku_code}}">
|
||||
<text class="sku-name">{{item.sku_name}}</text>
|
||||
<text class="sku-meta">{{item.sku_code}}</text>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
<view wx:for="{{outputRows}}" wx:key="sku_code" class="loss-box">
|
||||
<view class="loss-row">
|
||||
<text>{{index + 1}}. {{item.sku_name}}</text>
|
||||
<text style="color:#e11d48;" data-sku="{{item.sku_code}}" catchtap="removeOutputRow">删除</text>
|
||||
</view>
|
||||
<view class="field-grid">
|
||||
<view class="field">
|
||||
<text class="field-label">产出数量</text>
|
||||
<input class="field-input" type="digit" placeholder="0" value="{{item.qty}}" data-sku="{{item.sku_code}}" bindinput="onOutputQtyInput" />
|
||||
</view>
|
||||
<view class="field">
|
||||
<text class="field-label">入库成本价(默认均分)</text>
|
||||
<input class="field-input" type="digit" placeholder="自动" value="{{item.unit_cost}}" data-sku="{{item.sku_code}}" bindinput="onOutputCostInput" />
|
||||
</view>
|
||||
</view>
|
||||
<view class="loss-row">
|
||||
<text data-sku="{{item.sku_code}}" data-field="inherit_batch_report" catchtap="toggleOutputInherit">
|
||||
{{item.inherit_batch_report ? '☑' : '☐'}} 继承原料批次报告
|
||||
</text>
|
||||
<text data-sku="{{item.sku_code}}" data-field="inherit_inspection_report" catchtap="toggleOutputInherit">
|
||||
{{item.inherit_inspection_report ? '☑' : '☐'}} 继承原料检验报告
|
||||
</text>
|
||||
</view>
|
||||
</view>
|
||||
<view class="loss-box">
|
||||
<view class="loss-row">
|
||||
<text>损耗数量(不填=自动差额)</text>
|
||||
<text class="loss-value">{{outputLoss}}</text>
|
||||
</view>
|
||||
<view class="loss-hint">自动差额:{{outputAutoLoss}}{{outputUnit}}(可改,改后不再自动)</view>
|
||||
<input class="field-input" type="digit" placeholder="自动" value="{{outputLoss}}" bindinput="onOutputLossInput" />
|
||||
</view>
|
||||
<view class="sheet-actions">
|
||||
<button class="btn-ghost" bindtap="closeOutputForm">取消</button>
|
||||
<button class="btn-primary btn-block" loading="{{saving}}" bindtap="submitOutput">确认完工并回仓</button>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<view wx:if="{{showWorkModal}}" class="sheet-mask" catchtouchmove="stopCreateTap" bindtap="closeWorkForm">
|
||||
<view class="sheet-card" catchtap="stopCreateTap">
|
||||
<view class="sheet-head">
|
||||
|
||||
@@ -0,0 +1,68 @@
|
||||
/**
|
||||
* 小程序「独立加工 ≠ 正常录单加工」契约(2026-10-23 开发者:记住两者是两回事)。
|
||||
*
|
||||
* 只读校验:独立加工(source_type='standalone')在小程序里
|
||||
* ① 创建 = 多行原料(materials)+ 幂等请求号;
|
||||
* ② 完工 = 申报成品(成品多行 / 成本自动均分 / 损耗自动差额 / 两个继承开关);
|
||||
* ③ 订单加工与需求单的「毛重/净重 + 加工单价」流程**保持原样**。
|
||||
*/
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
const assert = require('assert');
|
||||
|
||||
const js = fs.readFileSync(path.join(__dirname, 'index.js'), 'utf8');
|
||||
const wxml = fs.readFileSync(path.join(__dirname, 'index.wxml'), 'utf8');
|
||||
const api = fs.readFileSync(path.join(__dirname, '../../utils/request.js'), 'utf8');
|
||||
|
||||
let failed = 0;
|
||||
function it(name, fn) {
|
||||
try {
|
||||
fn();
|
||||
console.log(' ✓', name);
|
||||
} catch (err) {
|
||||
failed += 1;
|
||||
console.log(' ✗', name, '→', err.message);
|
||||
}
|
||||
}
|
||||
|
||||
it('创建:独立加工走多行原料 + client_request_no', () => {
|
||||
assert.ok(js.includes('materials: rows.map((row) => ({ sku_code: row.sku_code, qty: Number(row.qty) }))'));
|
||||
assert.ok(js.includes('client_request_no:'));
|
||||
assert.ok(wxml.includes('原料明细(可多行)'));
|
||||
assert.ok(wxml.includes('onCreateMaterialQty'));
|
||||
assert.ok(wxml.includes('removeCreateMaterial'));
|
||||
});
|
||||
|
||||
it('完工:独立加工走成品申报(不再要求毛重/净重)', () => {
|
||||
assert.ok(js.includes("String(row.source_type || '') === 'standalone'"));
|
||||
assert.ok(js.includes('this.openOutputForm(row);'));
|
||||
assert.ok(js.includes('await completeStandaloneProcessingTask(outputTaskId'));
|
||||
assert.ok(wxml.includes('申报加工成品'));
|
||||
assert.ok(wxml.includes('确认完工并回仓'));
|
||||
});
|
||||
|
||||
it('成品:成本默认均分 + 损耗自动差额 + 两个继承开关', () => {
|
||||
assert.ok(js.includes('this.data.outputMaterialCost / totalQty'));
|
||||
assert.ok(js.includes('outputAutoLoss'));
|
||||
assert.ok(wxml.includes('inherit_batch_report'));
|
||||
assert.ok(wxml.includes('inherit_inspection_report'));
|
||||
});
|
||||
|
||||
it('订单/需求单加工:毛重净重流程保持原样(不许被改)', () => {
|
||||
assert.ok(js.includes('await completeProcessingWork({'));
|
||||
assert.ok(js.includes('gross_weight: grossWeight,'));
|
||||
assert.ok(js.includes('net_weight: netWeight,'));
|
||||
assert.ok(wxml.includes('加工损耗(毛重 − 净重)'));
|
||||
});
|
||||
|
||||
it('接口:新完工/行查询走移动端路由(与 Web 同一服务)', () => {
|
||||
assert.ok(api.includes("'/mobile/processing/standalone/'") || api.includes('/mobile/processing/standalone/${encodeURIComponent(taskId)}/complete'));
|
||||
assert.ok(api.includes('/complete`'));
|
||||
assert.ok(api.includes('/lines`'));
|
||||
});
|
||||
|
||||
if (failed) {
|
||||
console.error(`\n ${failed} 条失败`);
|
||||
process.exit(1);
|
||||
}
|
||||
console.log('\n 全部通过');
|
||||
@@ -1024,12 +1024,26 @@ function fetchStandaloneProcessingSkuOptions(search = '', limit = 20) {
|
||||
}
|
||||
|
||||
function createStandaloneProcessingTask(payload) {
|
||||
// payload 支持多行原料 `materials: [{sku_code, qty}]` 与幂等键 `client_request_no`(2026-10-23)
|
||||
return request('/mobile/processing/standalone/create', {
|
||||
method: 'POST',
|
||||
data: payload,
|
||||
});
|
||||
}
|
||||
|
||||
/** 独立加工完工:申报成品(多行)→ 成品回仓(与 Web 同一服务) */
|
||||
function completeStandaloneProcessingTask(taskId, payload) {
|
||||
return request(`/mobile/processing/standalone/${encodeURIComponent(taskId)}/complete`, {
|
||||
method: 'POST',
|
||||
data: payload,
|
||||
});
|
||||
}
|
||||
|
||||
/** 独立加工单的原料行 / 成品行 */
|
||||
function listStandaloneLines(taskId) {
|
||||
return request(`/mobile/processing/standalone/${encodeURIComponent(taskId)}/lines`);
|
||||
}
|
||||
|
||||
function pickDemandSheetMaterial(taskId, payload) {
|
||||
return request(`/mobile/processing/demand/${encodeURIComponent(taskId)}/pick`, {
|
||||
method: 'POST',
|
||||
@@ -1449,6 +1463,8 @@ module.exports = {
|
||||
fetchProcessingTasks,
|
||||
fetchStandaloneProcessingSkuOptions,
|
||||
createStandaloneProcessingTask,
|
||||
completeStandaloneProcessingTask,
|
||||
listStandaloneLines,
|
||||
pickDemandSheetMaterial,
|
||||
skipWarehouseDemandPurchase,
|
||||
startProcessingTask,
|
||||
|
||||
@@ -863,7 +863,16 @@ router.post('/processing/standalone/create', authMiddleware, async (req: AuthReq
|
||||
if (!ctx?.branchCode) {
|
||||
return res.status(403).json({ error: 'invalid_branch', error_description: '未绑定分公司' });
|
||||
}
|
||||
/** 多行原料(2026-10-23,与 Web 同一契约);老版本小程序只传 sku_code+qty 仍可用 */
|
||||
const rawMaterials = Array.isArray(req.body?.materials) ? (req.body.materials as unknown[]) : [];
|
||||
const materials = rawMaterials
|
||||
.map((row) => {
|
||||
const r = row as { sku_code?: unknown; qty?: unknown };
|
||||
return { skuCode: String(r?.sku_code ?? ''), qty: Number(r?.qty) };
|
||||
})
|
||||
.filter((row) => row.skuCode || Number.isFinite(row.qty));
|
||||
const data = await createStandaloneProcessingTask({
|
||||
...(materials.length ? { materials } : {}),
|
||||
skuCode: String(req.body?.sku_code || ''),
|
||||
qty: Number(req.body?.qty),
|
||||
processingMethod: String(req.body?.processing_method || ''),
|
||||
@@ -871,6 +880,7 @@ router.post('/processing/standalone/create', authMiddleware, async (req: AuthReq
|
||||
processUnitPrice: req.body?.process_unit_price === undefined ? null : Number(req.body.process_unit_price),
|
||||
operatorId: req.userId || null,
|
||||
remark: req.body?.remark ? String(req.body.remark) : null,
|
||||
clientRequestNo: req.body?.client_request_no ? String(req.body.client_request_no) : null,
|
||||
});
|
||||
return res.json({ success: true, data });
|
||||
} catch (error: any) {
|
||||
@@ -881,6 +891,62 @@ router.post('/processing/standalone/create', authMiddleware, async (req: AuthReq
|
||||
}
|
||||
});
|
||||
|
||||
/**
|
||||
* 独立加工**完工**:申报成品(多行)→ 成品新批次回仓 → 损耗留痕 → 可选继承原料报告。
|
||||
* 与 Web 共用同一服务(`completeStandaloneProcessingTask`),口径不分端。
|
||||
*/
|
||||
router.post('/processing/standalone/:taskId/complete', authMiddleware, async (req: AuthRequest, res: Response) => {
|
||||
try {
|
||||
requireMobileRoles(req, ['warehouse', 'inspector']);
|
||||
const ctx = await loadTenantContext(req.userId);
|
||||
if (!ctx?.branchCode) {
|
||||
return res.status(403).json({ error: 'invalid_branch', error_description: '未绑定分公司' });
|
||||
}
|
||||
const { completeStandaloneProcessingTask } = await import('../../services/processingStandaloneOutputService');
|
||||
const data = await completeStandaloneProcessingTask({
|
||||
taskId: String(req.params.taskId || ''),
|
||||
branchCode: ctx.branchCode,
|
||||
outputs: (Array.isArray(req.body?.outputs) ? req.body.outputs : []).map((row: unknown) => {
|
||||
const r = row as Record<string, unknown>;
|
||||
return {
|
||||
skuCode: String(r?.sku_code ?? ''),
|
||||
qty: Number(r?.qty),
|
||||
unitCost:
|
||||
r?.unit_cost === undefined || r?.unit_cost === '' || r?.unit_cost === null ? null : Number(r.unit_cost),
|
||||
inheritBatchReport: r?.inherit_batch_report === true,
|
||||
inheritInspectionReport: r?.inherit_inspection_report === true,
|
||||
};
|
||||
}),
|
||||
lossQty:
|
||||
req.body?.loss_qty === undefined || req.body?.loss_qty === '' || req.body?.loss_qty === null
|
||||
? null
|
||||
: Number(req.body.loss_qty),
|
||||
operatorId: req.userId || null,
|
||||
});
|
||||
return res.json({ success: true, data });
|
||||
} catch (error: any) {
|
||||
return res.status(error?.status || 500).json({
|
||||
error: error?.code || 'server_error',
|
||||
error_description: error?.message || '申报成品失败',
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
/** 独立加工单的原料行 / 成品行(小程序渲染成品申报与详情用) */
|
||||
router.get('/processing/standalone/:taskId/lines', authMiddleware, async (req: AuthRequest, res: Response) => {
|
||||
try {
|
||||
requireMobileRoles(req, ['warehouse', 'inspector']);
|
||||
const { listStandaloneMaterialsAndOutputs } = await import('../../services/processingStandaloneOutputService');
|
||||
const data = await listStandaloneMaterialsAndOutputs(String(req.params.taskId || ''));
|
||||
return res.json({ success: true, data });
|
||||
} catch (error: any) {
|
||||
return res.status(error?.status || 500).json({
|
||||
error: error?.code || 'server_error',
|
||||
error_description: error?.message || '读取加工单行失败',
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
router.post('/processing/demand/:taskId/pick', authMiddleware, async (req: AuthRequest, res: Response) => {
|
||||
try {
|
||||
requireMobileRoles(req, ['warehouse', 'inspector']);
|
||||
|
||||
Reference in New Issue
Block a user