置换余料支持寄存暂不结算及修改取消联动

This commit is contained in:
summer committed 2026-11-26 01:15:41 +08:00
1 parent 1f1e6dd402
commit b070da1e3d
9 files changed
+110 -36

No files matched your search

@@ -53,3 +53,28 @@ test('寄存HTTP接口需要登录,三人共享余额,重复提交同一操
const first=await(await post()).json(),again=await(await post()).json();assert.equal(first.id,again.id);assert.equal(first.remainingMg,1500);
for(const name of ['合成老板','合成助理甲','合成助理乙']){const response=await fetch(base+'/api/customer-materials',{headers:{Cookie:await login(name)}}),data=await response.json();assert.equal(response.status,200);assert.equal(data.rows.length,1);assert.equal(data.remainingMg,1500);assert.equal(data.rows[0].actor,'合成助理甲');}
});
test('置换余料1.439克暂存:只收入换货费用、不购料、不把客户余料加入自有库存,幂等不重复',t=>{
const f=fixture(t);f.stock();const input=exchange({old_lines:old('10'),surplus_mode:'deposit',surplus_memo:'袋B',buy_rate:'',buy_total:'1100.40'},{quantity:'8.561'}),key=randomUUID();
const r=f.run(input,()=>f.l.createRecovery(input,f.actors.assistant),'assistant',key),again=f.run(input,()=>f.l.createRecovery(input,f.actors.assistant),'assistant',key);
assert.equal(r.id,again.id);assert.equal(r.depositMg,1439);assert.equal(r.purchaseMg,0);assert.equal(r.purchaseAmount,0);assert.equal(r.purchase_id,null);assert.equal(r.netSettlement,r.receivable);assert.equal(f.l.inventory().find(p=>p.pocket==='回收旧料').mg,8561);
const d=f.l.customerMaterials({},f.actors.owner).rows[0];assert.equal(d.remainingMg,1439);assert.equal(d.sourceRecoveryId,r.id);assert.match(d.memo,/袋B/);assert.equal(f.l.rows('SELECT * FROM customer_material_origins').length,1);assert.equal(f.info(r.id).inputs.surplus_mode,'deposit');
const print=require('../recovery-printing').exchangeCustomerPrintDocument(f.l.publicRecovery(r.id,f.actors.owner));assert.match(print,/1\.439 克,暂不结算/);assert.doesNotMatch(print,/袋B/);
});
test('余料寄存修改与撤回:同一寄存号调整,不重复;已用部分不可撤销,回退用料后允许取消',t=>{
const f=fixture(t);f.stock();const r=f.create(exchange({old_lines:old('3'),surplus_mode:'deposit'},{quantity:'1'}));let d=f.l.customerMaterials({},f.actors.owner).rows[0];assert.equal(balance(f,d.id),2000);
f.update(r.id,{old_lines:old('2.5')});assert.equal(balance(f,d.id),1500);assert.equal(f.l.customerMaterials({},f.actors.owner).rows.length,1);
const use=f.create(fromDeposit(d.id,'1','1'));assert.equal(balance(f,d.id),500);const before=contents(f.l);assert.throws(()=>f.cancel(r.id),/寄存余料已被置换使用/);assert.equal(contents(f.l),before);assert.throws(()=>f.update(r.id,{old_lines:old('1.5')}),/寄存余料已被置换使用/);
f.update(r.id,{old_lines:old('2.2')});assert.equal(balance(f,d.id),200);assert.equal(f.l.customerMaterials({},f.actors.owner).rows[0].usedMg,1000);
f.cancel(use.id);assert.equal(balance(f,d.id),1200);f.cancel(r.id);d=f.l.customerMaterials({},f.actors.owner).rows[0];assert.equal(d.remainingMg,0);assert.equal(d.usedMg,0);assert.equal(d.mg,0);assert.equal(d.voided,true);assert.equal(f.l.inventory().find(p=>p.pocket==='回收旧料').mg,0);
});
test('多商品可分别回收和寄存,修改回填隔离,寄存改回收后不遗留余额',t=>{
const f=fixture(t);f.stock();const a=exchange({old_lines:old('3'),surplus_mode:'deposit'},{quantity:'1'}),b=exchange({old_lines:old('4'),buy_rate:'850'},{quantity:'2'});
const r=f.create({...a,exchange:{items:[a,b],rounding_mode:'cent',discount:'0'}});assert.equal(r.depositMg,2000);assert.equal(r.purchaseMg,2000);assert.equal(r.purchaseAmount,170000);assert.equal(r.surplusMg,4000);assert.equal(f.l.inventory().find(p=>p.pocket==='回收旧料').mg,5000);
const input=f.info(r.id).inputs;assert.equal(input.exchange.items[0].surplus_mode,'deposit');assert.equal(input.exchange.items[1].surplus_mode,undefined);const d=f.l.customerMaterials({},f.actors.owner).rows[0];
input.exchange.items[0].surplus_mode='buy';input.exchange.items[0].buy_rate='850';delete input.exchange.items[0].buy_total;f.update(r.id,input);assert.equal(balance(f,d.id),0);assert.equal(f.l.recovery(r.id,f.actors.owner).purchaseMg,4000);
});
test('过去置换的余料寄存修改须审批,审批前余额不变,同意后同步调整',t=>{
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);
});
+8
View File
@@ -155,3 +155,11 @@ test('寄存料按使用克重生成置换旧料,独立商品可混合本次
assert.equal(input.old_source,undefined);assert.equal(input.exchange.items[0].deposit_weight,'1');assert.equal(input.exchange.items[0].old_lines[0].melted_weight,'1');assert.equal(input.exchange.items[1].old_source,undefined);assert.equal(h.calculate(input).oldMg,1500);h.context.__input=input;assert.doesNotThrow(()=>h.run('validateRecoveryInput(__input)'));
h.context.__draft=h.draft({...swap,independent_products:true});const html=h.run('recoveryFormHTML(__draft)');assert.match(html,/寄存,暂不结算/);assert.match(html,/name="old_source"/);assert.match(html,/name="deposit_id"/);assert.match(html,/name="deposit_weight"/);
});
test('余料处理可选寄存,取消隐藏旧回收款;每件独立选择,不继承第一件寄存',()=>{
const h=harness(),draft={...swap,incoming_weight:'10',melted_weight:'10',new_quantity:'8.561',surplus_mode:'deposit',surplus_memo:'袋B',buy_rate:'',buy_total:'1100.40',buy_total_manual:true};
const input=h.input(draft),q=h.calculate(input);assert.equal(q.depositMg,1439);assert.equal(q.purchaseMg,0);assert.equal(q.purchaseAmount,0);assert.equal(q.netSettlement,q.receivable);assert.equal(input.surplus_memo,'袋B');h.context.__q=q;h.context.__input=input;assert.match(h.run('recoverySettlementHTML(__q,__input)'),/余料寄存:1.439g/);
h.context.__draft=h.draft({...draft,independent_products:true,extra_products:[h.draft({...swap,incoming_weight:'3',melted_weight:'3',new_quantity:'2',buy_rate:'850'})]});
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/);
});