完善订单成本编辑与多商品置换,修正锁价跨天作废回池

This commit is contained in:
summer committed 2026-11-24 21:11:32 +08:00
1 parent a3262a455d
commit 2e4e7dad55
25 files changed
+430 -109

No files matched your search

+18
View File
@@ -20,6 +20,14 @@ function harness(member='owner'){
const base={customer:'合成客户',incoming_weight:'20',melted_weight:'20',purity:'100',buy_rate:'900',verified:true};
const swap={...base,mode:'exchange',new_quantity:'30',gold_price:'1000',labor_rate:'20',material_source:'manual',material_rate:'900',cost_labor_value:'5'};
test('旧料入库选择保存草稿与payload,找金不受self限制,计对入库和新货出库各填各的',()=>{
const h=harness();h.run(`state.pockets.push('合成对数盘');state.pocketCatalog=[{key:'找金',name:'找金<img src=x>',active:true,self:false},{key:'合成对数盘',name:'合成对数盘',active:true,self:true,countUnit:'pair',countSince:'${D}'}];`);
assert.equal(h.draft().old_pocket,'回收旧料');const input=h.input({...swap,old_pocket:'找金',old_stock_count:'99'});assert.equal(input.old_pocket,'找金');assert.equal(input.old_stock_count,undefined);assert.equal(input.exchange.pocket,'现货');h.context.__input=input;assert.doesNotThrow(()=>h.run('validateRecoveryInput(__input)'));
const counted=h.input({...swap,old_pocket:'合成对数盘',old_stock_count:'3',pocket:'合成对数盘',stockCount:'2'});assert.equal(counted.old_stock_count,'3');assert.equal(counted.exchange.stockCount,'2');h.context.__input=counted;assert.doesNotThrow(()=>h.run('validateRecoveryInput(__input)'));counted.old_stock_count=null;assert.throws(()=>h.run('validateRecoveryInput(__input)'),/旧料入库数量/);
h.context.__draft=h.draft({...base,old_pocket:'找金'});const html=h.run('recoveryFormHTML(__draft)');assert.match(html,/旧料入库货盘/);assert.match(html,/name="old_pocket"/);assert.match(html,/name="old_stock_count"/);assert.match(html,/找金&lt;img src=x&gt;/);assert.doesNotMatch(html,/找金<img/);
h.context.__form=h.form({...base,old_pocket:'找金'});h.run('rememberRecoveryDraft(__form)');assert.equal(JSON.parse(h.saved.get('mm-recovery-draft-'+h.user.id)).old_pocket,'找金');
});
test('回收入口有两种业务且无最低5克,老板可代录归属,助理固定本人',()=>{
const h=harness();h.context.__draft=h.draft();const html=h.run('recoveryFormHTML(__draft)');
for(const text of ['直接回收','置换','客户称呼/代号','来料重量','熔后重量','成色(%)','折后重量','内部成本','保存后自动编号'])assert.ok(html.includes(text));
@@ -120,3 +128,13 @@ test('回收提交丢失响应仍保留原幂等操作号,重试不换金额
h.context.__pending=pending;h.run('api=async function(url,data,key){__posts.push({url,data,key});return {id:"saved"};};');await h.run('mutate(__pending.url,__pending.data,__pending)');assert.equal(h.posts[0].key,h.posts[1].key);assert.equal(h.saved.has('mm-pending-'+h.user.id),false);
const source=fs.readFileSync(path.join(__dirname,'../public/app.js'),'utf8');assert.match(source,/p.url==='\/api\/recoveries'.*finishRecoverySave/);
});
test('多商品新货合计参与补金与余料,外配空值保留,工费按每件独立计算',()=>{
const h=harness(),extra={new_name:'足金外配镯',new_quantity:'18',pocket:'',stockCount:'',labor_mode:'gram',labor_rate:'30',cost_labor_mode:'total',cost_labor_value:'90',labor_payer:'assistant2'};
const draft={...swap,new_quantity:'12',extra_products:[extra],verified:true};
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 进货工费/);
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);
});