置换默认一份旧料换多件新货,统一结算差重与寄存
This commit is contained in:
1 parent
b070da1e3d
commit
9186480118
5 files changed
+35
-14
No files matched your search
@@ -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);
|
||||
});
|
||||
@@ -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);
|
||||
});
|
||||
@@ -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');
|
||||
});
|
||||
Reference in new issue
Block a user