diff --git a/新账系统/public/recoveries-ui.js b/新账系统/public/recoveries-ui.js
index 892a3e8..4da01f0 100644
--- a/新账系统/public/recoveries-ui.js
+++ b/新账系统/public/recoveries-ui.js
@@ -35,11 +35,13 @@ function recoveryExtraProductHTML(row,index){
}
function recoveryDefaults(mode='direct'){
const member=currentMember();
- return {surplus_mode:'buy',surplus_memo:'',old_source:'incoming',deposit_id:'',deposit_weight:'',mode,date:state.today,customer:'',salesperson:defaultSalesperson(),member,old_name:'Au旧料',incoming_weight:'',melted_weight:'',purity:'100',old_pocket:'回收旧料',old_stock_count:'',buy_rate:'',buy_total:'',new_name:'足金999',new_quantity:'',pocket:'现货',stockCount:'',gold_price:'',labor_mode:'gram',labor_rate:'',depreciation_weight:'',depreciation_rate:'10',charge_name:'其他收费',charge_amount:'0',discount:'0',rounding_mode:'yuan',material_source:'pool',material_pool_id:state.today,material_rate:'',material_payer:member,cost_labor_mode:'gram',cost_labor_value:'',labor_payer:member,fee_note:'其他费用',fee_amount:'0',fee_payer:member,payment_method:'微信',payment_recipient:recoveryPrefix(member),payout_method:'微信',payer:member,note:'',buy_total_manual:false,depreciation_manual:false,melted_manual:false};
+ return {independent_products:false,surplus_mode:'buy',surplus_memo:'',old_source:'incoming',deposit_id:'',deposit_weight:'',mode,date:state.today,customer:'',salesperson:defaultSalesperson(),member,old_name:'Au旧料',incoming_weight:'',melted_weight:'',purity:'100',old_pocket:'回收旧料',old_stock_count:'',buy_rate:'',buy_total:'',new_name:'足金999',new_quantity:'',pocket:'现货',stockCount:'',gold_price:'',labor_mode:'gram',labor_rate:'',depreciation_weight:'',depreciation_rate:'10',charge_name:'其他收费',charge_amount:'0',discount:'0',rounding_mode:'yuan',material_source:'pool',material_pool_id:state.today,material_rate:'',material_payer:member,cost_labor_mode:'gram',cost_labor_value:'',labor_payer:member,fee_note:'其他费用',fee_amount:'0',fee_payer:member,payment_method:'微信',payment_recipient:recoveryPrefix(member),payout_method:'微信',payer:member,note:'',buy_total_manual:false,depreciation_manual:false,melted_manual:false};
}
function recoveryStoredDraft(){
let value;try{value=JSON.parse(localStorage.getItem(recoveryDraftKey())||'null');}catch{}
- const draft={...recoveryDefaults(),...(value&&typeof value==='object'?value:{independent_products:true})};
+ const draft={...recoveryDefaults(),...(value&&typeof value==='object'?value:{})};
+ // 旧版单件草稿可以直接使用共享旧料;多件旧草稿保留原录入,避免丢失各件旧料。
+ if(draft.independent_products&&!draft.extra_products?.length)draft.independent_products=false;
if(!Object.hasOwn(recoveryModeNames,draft.mode))draft.mode='direct';
if(state.user.role!=='owner')draft.member=currentMember();
return draft;
@@ -158,7 +160,7 @@ function recoveryFormHTML(draft){
if(draft.mode==='exchange'&&draft.independent_products)return recoveryItemsFormHTML(draft);
const exchange=draft.mode==='exchange',members=teamMemberOptions(),recipients=members.map(([member,name])=>[recoveryPrefix(member),name]);
const oldPocket=draft.old_pocket??'回收旧料',oldOriginal=typeof recoveryEditEntry!=='undefined'?recoveryEditEntry?.data?.inputs:null;
- return `
`;
+ return ``;
}
function recoverySettlementHTML(value,input){
if(value.exchangeItems){const items=input?.exchange?.items;return value.exchangeItems.map((p,i)=>'置换商品 '+(i+1)+':'+e(p.newProduct?.name||items?.[i]?.exchange?.name||'')+'
'+recoverySettlementHTML(p,items?{...items[i],mode:'exchange'}:recoveryDetailInput(p))).join('')+recoveryItemsSummaryHTML(value,input);}
@@ -198,6 +200,7 @@ function syncRecoveryForm(form=$('#recovery-form'),{quote=true}={}){
$('#recovery-folded-formula').textContent=draft.old_lines?.length>1?`${draft.old_lines.length} 项旧料折后总重 ${grams(old.oldMg)}g,逐项按熔后重量与成色核算。`:`折后重量 = ${draft.melted_weight}g × ${draft.purity}% = ${grams(old.oldMg)}g。`;
}catch{recoveryField(form,'folded_weight').value='';$('#recovery-folded-formula').textContent='折后重量 = 熔后重量 × 成色 ÷ 100。';}
try{if(exchange)newMg=recoveryNewWeight(draft);}catch{}
+ const newTotal=form.querySelector('#recovery-new-total');if(newTotal)newTotal.textContent=`新货共 ${1+(draft.extra_products?.length||0)} 件 · 合计 ${newMg===null?'待填写':grams(newMg)+'g'}${old?' · 共用折后旧料 '+grams(old.oldMg)+'g':''}`;
if(exchange&&old&&newMg!==null&&!draft.depreciation_manual){draft.depreciation_weight=grams(Math.min(old.oldMg,newMg));recoveryField(form,'depreciation_weight').value=draft.depreciation_weight;}
const hasPurchase=!exchange||!!(old&&newMg!==null&&old.oldMg>newMg),buyPanel=form.querySelector('.recovery-buy-panel');
if(buyPanel){buyPanel.hidden=!hasPurchase;for(const control of buyPanel.querySelectorAll('input,select,button'))control.disabled=!hasPurchase;}
@@ -234,7 +237,7 @@ function recoverySyncInternal(form,draft,calculation){
}else{let amount=null;try{amount=recoveryMul(mg,recoveryUnits(draft.material_rate,2,'差重进货料价'));}catch{}materialNote.textContent=`只计算补金差重 ${grams(mg)}g 的料费:${amount==null?'待填进货料价':grams(mg)+'g × '+draft.material_rate+'元/g = '+recoveryMoney(amount)}。等重部分不进出料池。`;}
let labor=null;try{const amount=recoveryUnits(draft.cost_labor_value,2,'进货工费');labor=draft.cost_labor_mode==='total'?amount:recoveryMul(recoveryUnits(draft.new_quantity,3,'新货克重'),amount);for(const row of draft.extra_products||[]){const rate=recoveryUnits(row.cost_labor_value,2,'进货工费');labor+=row.cost_labor_mode==='total'?rate:recoveryMul(recoveryUnits(row.new_quantity,3,'新货克重'),rate);}}catch{}
let extra=null;try{extra=Array.isArray(draft.fee_items)?draft.fee_items.reduce((total,row)=>total+recoveryUnits(row.amount,2,'其他实际成本'),0):recoveryUnits(draft.fee_amount||'0',2,'其他实际成本');}catch{}
- preview.textContent=`新货进货工费 ${recoveryMoney(labor)},${draft.extra_products?.length?'各件按所选付款人支付':teamMemberName(draft.labor_payer)+'支付'};其他实际成本 ${recoveryMoney(extra)}${extra?(draft.fee_items?.length>1?',按各项实际付款人核算':','+teamMemberName(draft.fee_payer)+'支付'):''}。${calculation.surplusMg?'实际余料 '+grams(calculation.surplusMg)+'g 与回收款将自动登记购料。':'本次没有额外余料购料。'}`;
+ preview.textContent=`新货进货工费 ${recoveryMoney(labor)},${draft.extra_products?.length?'各件按所选付款人支付':teamMemberName(draft.labor_payer)+'支付'};其他实际成本 ${recoveryMoney(extra)}${extra?(draft.fee_items?.length>1?',按各项实际付款人核算':','+teamMemberName(draft.fee_payer)+'支付'):''}。${calculation.depositMg?'实际余料 '+grams(calculation.depositMg)+'g 自动寄存,暂不结算,不登记购料。':calculation.surplusMg?'实际余料 '+grams(calculation.surplusMg)+'g 与回收款将自动登记购料。':'本次没有额外余料购料。'}`;
}
function applyRecoveryRestrictions(){
const form=$('#recovery-form');if(!form){if(typeof applyRecoveryChangeRestrictions==='function')applyRecoveryChangeRestrictions();return;}syncRecoveryForm(form,{quote:false});
@@ -372,13 +375,6 @@ document.addEventListener('change',event=>{
document.addEventListener('click',async event=>{
const node=event.target.closest?.('button'),action=node?.dataset.action;if(!action?.startsWith('recovery-')||node.disabled)return;
try{
- if(action==='recovery-upgrade-items'){
- const form=$('#recovery-form');if(busy||pending())return;const draft=recoveryFormDraft(form);
- if(draft.old_lines?.length>1)throw new Error('原单有多项旧料,请先按原表单核对;新建置换单可逐件填写。');
- draft.independent_products=true;draft.extra_products=(draft.extra_products||[]).map(row=>({...recoveryDefaults('exchange'),...row,gold_price:draft.gold_price,material_pool_id:draft.material_pool_id||draft.date,material_payer:draft.member}));
- if(form.dataset.recoveryEdit==='true'){recoveryEditEntry.draft=draft;form.outerHTML=recoveryEditingFormHTML(recoveryEditEntry);}else form.outerHTML=recoveryFormHTML(draft);
- recoveryPoolOptions($('#recovery-form'));syncRecoveryForm();toast('原旧料暂保留在第一件,请按实际情况分配到各件后再保存。');return;
- }
if(action==='recovery-item-reset-buy'||action==='recovery-item-reset-depreciation'){const form=$('#recovery-form'),row=form.querySelector('[data-recovery-item="'+node.dataset.index+'"]');row.dataset[action==='recovery-item-reset-buy'?'buy_total_manual':'depreciation_manual']='false';return syncRecoveryItems(form);}
if(action==='recovery-add-product'||action==='recovery-remove-product'){
const form=$('#recovery-form');if(busy||pending())return;rememberRecoveryDraft(form);const draft=recoveryFormDraft(form);draft.extra_products??=[];
@@ -398,7 +394,7 @@ document.addEventListener('click',async event=>{
if(action==='recovery-close')return closeRecoveryDetail();
if(action==='recovery-print'){window.open('/print/recoveries/'+encodeURIComponent(node.dataset.id),'_blank','noopener');return toast('客户打印页已打开;若未出现,请允许此网站打开新窗口');}
if(action==='recovery-open-order'){closeRecoveryDetail();return await openOrder(node.dataset.id);}
- if(action==='recovery-new'){customerMaterialPage=false;localStorage.setItem(recoveryDraftKey(),JSON.stringify({...recoveryDefaults(node.dataset.mode||'direct'),independent_products:true}));return await renderRecoveries();}
+ if(action==='recovery-new'){customerMaterialPage=false;localStorage.setItem(recoveryDraftKey(),JSON.stringify({...recoveryDefaults(node.dataset.mode||'direct'),independent_products:false}));return await renderRecoveries();}
}catch(err){toast(err.message,true);}
});
document.addEventListener('submit',async event=>{
diff --git a/新账系统/public/recovery-changes-ui.js b/新账系统/public/recovery-changes-ui.js
index 64a05dd..556ceca 100644
--- a/新账系统/public/recovery-changes-ui.js
+++ b/新账系统/public/recovery-changes-ui.js
@@ -24,7 +24,7 @@ function recoveryEditPanelHTML(data){
return `${data.status==='cancelled'?'本单已取消,原记录和更正历史保留。
':''}${data.permissions.reason?`${e(data.permissions.reason)}
`:''}${recoveryMaterialBatchHTML(data.record.materialBatch)}${recoveryBlockedHTML(data.blockedUsages)}${data.permissions.canCancel&&data.blockedUsages.length?recoveryCancellationMaterialHTML():''}${data.pending?`待麦麦复核
原记录仍生效,申请尚未记账。
${recoveryChangeComparisonHTML(data.pending)}${button(state.user.role==='owner'?'查看并复核':'查看申请','recovery-change-open','',`data-id="${e(data.pending.id)}"`)}`:''}${data.history.length?`更正与取消记录(${data.history.length})
${data.history.map(row=>`- ${e(recoveryChangeStatus(row))} · ${e(row.requesterName||'未提供')}${row.reviewerName?' · '+e(row.reviewerName)+'复核':''}${row.note?'
'+e(row.note)+'
':''}${button('查看前后内容','recovery-change-open','quiet',`data-id="${e(row.id)}"`)} `).join('')}
`:''}`;
}
function recoveryEditDraft(input){
- if(input.exchange?.items){const rows=input.exchange.items.map(row=>recoveryEditDraft({...input,...row,exchange:row.exchange})),first=rows[0],x=input.exchange;return {...first,independent_products:true,extra_products:rows.slice(1),charges:x.charges,charge_name:x.charges[0]?.name||'其他收费',charge_amount:x.charges[0]?.amount||'0',fee_items:x.fee_items,fee_note:x.fee_items[0]?.note||'其他费用',fee_amount:x.fee_items[0]?.amount||'0',fee_payer:x.fee_items[0]?.payer||input.member,discount:x.discount,rounding_mode:x.rounding_mode};}
+ if(input.exchange?.items){const rows=input.exchange.items.map(row=>recoveryEditDraft({...input,...row,exchange:row.exchange})),first=rows[0],x=input.exchange;return {...first,independent_products:rows.length>1,extra_products:rows.slice(1),charges:x.charges,charge_name:x.charges[0]?.name||'其他收费',charge_amount:x.charges[0]?.amount||'0',fee_items:x.fee_items,fee_note:x.fee_items[0]?.note||'其他费用',fee_amount:x.fee_items[0]?.amount||'0',fee_payer:x.fee_items[0]?.payer||input.member,discount:x.discount,rounding_mode:x.rounding_mode};}
const first=input.old_lines[0],x=input.exchange||{},charge=x.charges?.[0],fee=x.fee_items?.[0],account=input.payment_account||'',recipient=account.startsWith('麦麦')?'麦麦':account.startsWith('助理2')?'助理2':'助理',method=account.replace(/^(麦麦|助理2|助理1|助理)/,'');
return {...recoveryDefaults(input.mode),mode:input.mode,surplus_mode:input.surplus_mode||'buy',surplus_memo:input.surplus_memo||'',old_source:input.old_source||'incoming',deposit_id:input.deposit_id||'',deposit_weight:input.deposit_weight||'',date:input.date,customer:input.customer,salesperson:input.salesperson,member:input.member,note:input.note||'',old_pocket:input.old_pocket??'回收旧料',old_stock_count:input.old_stock_count??'',old_name:first.name,incoming_weight:first.incoming_weight,melted_weight:first.melted_weight,purity:first.purity,old_lines:JSON.parse(JSON.stringify(input.old_lines)),buy_rate:input.buy_rate,buy_total:input.buy_total??'',buy_total_manual:Object.hasOwn(input,'buy_total'),melted_manual:true,depreciation_manual:Object.hasOwn(x,'depreciation_weight'),payer:input.payer,payment_method:method,payment_recipient:recipient,payout_method:method==='信用卡'?'微信':method,new_name:x.name||'足金999',new_quantity:x.quantity||'',pocket:x.pocket??state.pockets[0]??'',stockCount:x.stockCount??'',gold_price:x.gold_price||'0',labor_mode:x.labor_mode||'gram',labor_rate:x.labor_rate||'0',depreciation_weight:x.depreciation_weight??'',depreciation_rate:x.depreciation_rate||'0',charge_name:charge?.name||'其他收费',charge_amount:charge?.amount||'0',charges:JSON.parse(JSON.stringify(x.charges||[])),discount:x.discount||'0',rounding_mode:x.rounding_mode||'cent',material_source:x.cost_material?.mode==='pool'?'pool':'manual',material_pool_id:x.cost_material?.poolId||input.date,material_rate:x.cost_material?.rate||'',material_payer:x.cost_material_payer||input.member,cost_labor_mode:x.cost_labor?.mode||'total',cost_labor_value:x.cost_labor?.mode==='gram'?x.cost_labor.rate:x.cost_labor?.amount??'',cost_payer:x.cost_payer||input.member,labor_payer:x.cost_labor_payer||x.cost_payer||input.member,fee_note:fee?.note||'其他费用',fee_amount:fee?.amount||'0',fee_payer:fee?.payer||input.member,fee_items:JSON.parse(JSON.stringify(x.fee_items||[])),...(x.products?{...recoveryProductDraft(x.products[0]),extra_products:x.products.slice(1).map(recoveryProductDraft)}:{}),verified:false};
}
diff --git a/新账系统/test/customer-materials.test.js b/新账系统/test/customer-materials.test.js
index 0d956a4..33f1402 100644
--- a/新账系统/test/customer-materials.test.js
+++ b/新账系统/test/customer-materials.test.js
@@ -78,3 +78,14 @@ test('过去置换的余料寄存修改须审批,审批前余额不变,同
const f=fixture(t);f.stock();const r=f.create(exchange({old_lines:old('3'),surplus_mode:'deposit'},{quantity:'1'})),d=f.l.customerMaterials({},f.actors.owner).rows[0];const request=f.update(r.id,{old_lines:old('2')},'assistant');assert.equal(request.pending,true);assert.equal(balance(f,d.id),2000);f.approve(request.request);assert.equal(balance(f,d.id),1000);
const cancel=f.cancel(r.id,{},'assistant');assert.equal(cancel.pending,true);assert.equal(balance(f,d.id),1000);f.approve(cancel.request);assert.equal(balance(f,d.id),0);
});
+
+test('一份20克旧料换15克及3克新货,余2克寄存;修改统一补差且取消完整恢复',t=>{
+ const f=fixture(t);f.stock();const product=(name,quantity,pocket,rate,cost,payer)=>({name,quantity,pocket,labor_mode:'gram',labor_rate:rate,cost_labor:{mode:'gram',rate:cost},cost_labor_payer:payer});
+ const input=exchange({old_lines:old('20'),surplus_mode:'deposit'},{products:[product('足金手镯','15','现货','25','5','owner'),product('足金戒指','3','','20','3','assistant')]}),r=f.create(input);
+ assert.equal(r.old_lines.length,1);assert.equal(r.oldMg,20000);assert.equal(r.newMg,18000);assert.equal(r.depositMg,2000);assert.equal(r.purchase_id,null);assert.equal(r.receivable,61500);assert.equal(r.laborCost,8400);assert.equal(r.profit,53100);
+ assert.equal(f.l.inventory().find(p=>p.pocket==='现货').mg,85000);assert.equal(f.l.inventory().find(p=>p.pocket==='回收旧料').mg,18000);const d=f.l.customerMaterials({},f.actors.owner).rows[0];assert.equal(balance(f,d.id),2000);
+ const saved=f.info(r.id).inputs;assert.equal(saved.exchange.products.length,2);assert.equal(saved.exchange.products[1].cost_labor_payer,'assistant');assert.equal(saved.old_lines.length,1);
+ const p={date:D,grams:'5',total:'4500',payer:'owner'};f.run(p,()=>f.l.createMaterialPurchase(p,f.actors.owner));saved.exchange.products[1].quantity='7';saved.exchange.cost_material={mode:'pool',poolId:D};
+ const edited=f.update(r.id,saved).recovery;assert.equal(edited.newMg,22000);assert.equal(edited.differenceMg,2000);assert.equal(edited.depositMg,0);assert.equal(edited.materialCost,180000);assert.equal(edited.goldAmount,200000);assert.equal(balance(f,d.id),0);assert.equal(f.l.materialPoolDetail(D).usedMg,2000);assert.equal(f.l.inventory().find(p=>p.pocket==='回收旧料').mg,20000);
+ f.cancel(r.id);assert.equal(f.l.materialPoolDetail(D).usedMg,0);assert.equal(f.l.inventory().find(p=>p.pocket==='现货').mg,100000);assert.equal(f.l.inventory().find(p=>p.pocket==='回收旧料').mg,0);assert.equal(balance(f,d.id),0);
+});
diff --git a/新账系统/test/recoveries-ui.test.js b/新账系统/test/recoveries-ui.test.js
index bac964a..55661f0 100644
--- a/新账系统/test/recoveries-ui.test.js
+++ b/新账系统/test/recoveries-ui.test.js
@@ -135,7 +135,7 @@ test('多商品新货合计参与补金与余料,外配空值保留,工费
const input=h.input(draft),calc=h.calculate(input);assert.equal(input.exchange.products.length,2);assert.equal(input.exchange.products[1].pocket,'');assert.equal(input.exchange.products[1].cost_labor.amount,'90');
assert.equal(calc.newMg,30000);assert.equal(calc.differenceMg,10000);assert.equal(calc.laborAmount,78000);assert.equal(calc.netSettlement,1098000);
h.context.__input=input;assert.doesNotThrow(()=>h.run('validateRecoveryInput(__input)'));
- h.context.__draft=h.draft(draft);const html=h.run('recoveryFormHTML(__draft)');assert.match(html,/recovery-add-product/);assert.match(html,/recovery-remove-product/);assert.match(html,/外配(不扣店内库存)/);assert.match(html,/name="extra_new_quantity" value="18"/);assert.match(html,/新货 1 进货工费/);
+ h.context.__draft=h.draft(draft);const html=h.run('recoveryFormHTML(__draft)');assert.match(html,/recovery-add-product/);assert.match(html,/recovery-remove-product/);assert.match(html,/外配(不扣店内库存)/);assert.match(html,/name="extra_new_quantity" value="18"/);assert.match(html,/本件内部成本/);assert.match(html,/name="cost_labor_value"/);assert.match(html,/name="extra_cost_labor_value"/);
const surplus=h.input({...draft,incoming_weight:'40',melted_weight:'40',buy_rate:'850'}),back=h.calculate(surplus);assert.equal(back.surplusMg,10000);assert.equal(back.purchaseAmount,850000);assert.equal(surplus.exchange.cost_material,undefined);
});
@@ -163,3 +163,11 @@ test('余料处理可选寄存,取消隐藏旧回收款;每件独立选择
const mixed=h.json('recoveryInput(__draft)'),total=h.calculate(mixed);assert.equal(mixed.exchange.items[1].surplus_mode,undefined);assert.equal(total.depositMg,1439);assert.equal(total.purchaseMg,1000);assert.equal(total.purchaseAmount,85000);
const html=h.run('recoveryFormHTML(__draft)');assert.match(html,/name="surplus_mode"/);assert.match(html,/name="extra_surplus_mode"/);assert.match(html,/添加到寄存料,暂不结算/);assert.match(html,/data-surplus-buy/);
});
+
+test('新建默认一份旧料换多件新货,旧料和寄存选择只出现一次,工费及货盘逐件完整',()=>{
+ const h=harness();assert.equal(h.json('recoveryStoredDraft()').independent_products,false);assert.equal(h.draft({mode:'exchange'}).independent_products,false);
+ const extra=h.draft({new_name:'足金戒指',new_quantity:'3',pocket:'',labor_rate:'20',cost_labor_value:'3',labor_payer:'assistant'}),draft=h.draft({...swap,new_quantity:'15',labor_rate:'25',surplus_mode:'deposit',surplus_memo:'共享旧料余2克',extra_products:[extra]});h.context.__draft=draft;
+ const input=h.json('recoveryInput(__draft)'),q=h.calculate(input);assert.equal(input.old_lines.length,1);assert.equal(input.exchange.items,undefined);assert.equal(input.exchange.products.length,2);assert.equal(q.oldMg,20000);assert.equal(q.newMg,18000);assert.equal(q.depositMg,2000);assert.equal(q.receivable,61500);
+ const html=h.run('recoveryFormHTML(__draft)');assert.equal((html.match(/name="incoming_weight"/g)||[]).length,1);assert.equal((html.match(/name="surplus_mode"/g)||[]).length,1);assert.equal((html.match(/name="cost_labor_value"/g)||[]).length,1);assert.match(html,/name="extra_cost_labor_value"/);assert.match(html,/name="extra_pocket"/);assert.doesNotMatch(html,/name="extra_incoming_weight"|recovery-upgrade-items/);assert.match(html,/上方旧料只录一次/);
+ h.saved.set('mm-recovery-draft-'+h.user.id,JSON.stringify({...draft,independent_products:true,extra_products:[]}));assert.equal(h.json('recoveryStoredDraft()').independent_products,false);
+});
diff --git a/新账系统/test/recovery-changes-ui.test.js b/新账系统/test/recovery-changes-ui.test.js
index baa5886..bfbce64 100644
--- a/新账系统/test/recovery-changes-ui.test.js
+++ b/新账系统/test/recovery-changes-ui.test.js
@@ -117,3 +117,9 @@ test('逐件完整置换修改回填保留每件旧料、折旧、补金及独
h.context.__individual={...original,exchange:{...x,items:[{old_lines:original.old_lines,old_pocket:'找金',buy_rate:'850',buy_total:'0',exchange:{...x,quantity:'15',gold_price:'1000',depreciation_weight:'10',depreciation_rate:'10',cost_material:{mode:'pool',poolId:D}}},{old_lines:[{name:'第二份旧料',incoming_weight:'20',melted_weight:'20',purity:'99'}],old_pocket:'回收旧料',buy_rate:'860',buy_total:'6708',exchange:{...x,name:'第二件',quantity:'12',pocket:'',gold_price:'1100',depreciation_weight:'12',depreciation_rate:'5',cost_material:{mode:'gram',rate:'800'},cost_material_payer:'assistant2'}}]}};
const draft=h.json('recoveryEditDraft(__individual)');assert.equal(draft.independent_products,true);assert.equal(draft.old_pocket,'找金');assert.equal(draft.material_source,'pool');assert.equal(draft.extra_products[0].incoming_weight,'20');assert.equal(draft.extra_products[0].depreciation_rate,'5');assert.equal(draft.extra_products[0].material_rate,'800');assert.equal(draft.extra_products[0].material_payer,'assistant2');assert.equal(draft.extra_products[0].pocket,'');
});
+
+test('历史单件逐件单编辑转为共用旧料,可添加多件新货且保留原费用和寄存选择',()=>{
+ const h=harness(),original=inputs(),item={old_lines:[{name:'Au旧料',incoming_weight:'10',melted_weight:'10',purity:'100'}],old_pocket:'回收旧料',surplus_mode:'deposit',surplus_memo:'原寄存备忘',buy_rate:'0',buy_total:'0',exchange:{...original.exchange,quantity:'8',depreciation_weight:'8'}};
+ h.context.__single={...original,exchange:{...original.exchange,items:[item]}};const draft=h.json('recoveryEditDraft(__single)');assert.equal(draft.independent_products,false);assert.equal(draft.incoming_weight,'10');assert.equal(draft.surplus_mode,'deposit');assert.equal(draft.surplus_memo,'原寄存备忘');assert.equal(draft.extra_products.length,0);assert.equal(draft.charges.length,2);assert.equal(draft.fee_items.length,2);
+ h.context.__draft={...draft,verified:true};const input=h.json('recoveryInput(__draft)');assert.equal(input.exchange.items,undefined);assert.equal(input.old_lines.length,1);assert.equal(input.exchange.quantity,'8');assert.equal(input.surplus_mode,'deposit');
+});