支持回收单修改取消、按归属人优先用料及锁价交付改单
This commit is contained in:
1 parent
0e146739bc
commit
19b1b0263c
41 files changed
+1814
-203
No files matched your search
@@ -82,11 +82,11 @@ function formHarness(current,rows,orderId=''){
|
||||
const fields={unit:{value:input.unit||'g'},nameType:{value:input.name||'足金999'},quantity:{value:input.quantity},'cost-materialSource':{value:input.source||'pool'},'cost-materialPoolId':{value:input.poolId||D}};
|
||||
return {controls,fields,querySelector(selector){if(selector==='.material-source-controls')return input.legacy?null:controls;return fields[selector.match(/\[name="([^"]+)"\]/)?.[1]]||null;}};
|
||||
};
|
||||
const elements=rows.map(makeRow),form={querySelectorAll:()=>elements,querySelector(selector){return selector==='[name="date"]'?{value:SALE}:selector==='[name="orderId"]'?{value:orderId}:null;}};
|
||||
const context=vm.createContext({LedgerCalc:Calc,document:{addEventListener(){}},state:{user:{id:'preview-user'}},$:selector=>selector==='#order-form'?form:null,__pools:current,__rows:elements,__pool:current[0]});
|
||||
const elements=rows.map(makeRow),member={value:'assistant'},form={querySelectorAll:()=>elements,querySelector(selector){return selector==='[name="date"]'?{value:SALE}:selector==='[name="orderId"]'?{value:orderId}:selector==='[name="member"]'?member:null;}};
|
||||
const context=vm.createContext({LedgerCalc:Calc,setTimeout(){},clearTimeout(){},document:{addEventListener(){}},state:{user:{id:'preview-user',role:'owner',member:'owner'}},currentMember:()=> 'owner',$:selector=>selector==='#order-form'?form:null,__pools:current,__rows:elements,__pool:current[0],__updated:0,updateTotal(){context.__updated++;}});
|
||||
vm.runInContext(fs.readFileSync(require.resolve('../public/material-pools-ui.js'),'utf8'),context);
|
||||
vm.runInContext("materialPoolsCache={rows:__pools};materialPoolsCacheUser=state.user.id;",context);
|
||||
return {rows:elements,preview:index=>vm.runInContext('materialPoolFormPreview(__pool,__rows['+index+'])',context),choices:()=>vm.runInContext('materialPoolAvailableRows("'+SALE+'","'+OTHER+'")',context)};
|
||||
return {context,form,member,run:code=>vm.runInContext(code,context),rows:elements,preview:index=>vm.runInContext('materialPoolFormPreview(__pool,__rows['+index+'])',context),choices:()=>vm.runInContext('materialPoolAvailableRows("'+SALE+'","'+OTHER+'")',context)};
|
||||
}
|
||||
test('前端从整张表单现值计算,改前行或切手填会立即改变后行尾差',()=>{
|
||||
const h=formHarness([pool()],[{quantity:'1'},{quantity:'1'}]);
|
||||
@@ -107,3 +107,10 @@ test('编辑本单满池时仍可选回原料池,新单和不占用该池的
|
||||
assert.ok(!formHarness([current],[{quantity:'1',poolId:OTHER}]).choices().some(value=>value.id===D));
|
||||
assert.ok(!formHarness([current],[{quantity:'1',poolId:OTHER}],'another-order').choices().some(value=>value.id===D));
|
||||
});
|
||||
function personalQuote(){const own={kind:'personal_recovery',member:'assistant',quantity:1000,amount:85000,allocations:[{payer:'owner',amount:85000}],averageRate:85000},common={kind:'public',member:null,quantity:500,amount:50000,allocations:[{payer:'assistant2',amount:50000}],averageRate:100000};return {date:SALE,member:'assistant',entries:[{lineIndex:0,poolId:D,mg:1500,amount:135000,status:'allocated',allocations:[...own.allocations,...common.allocations],materialSources:[own,common]}],pools:[{poolId:D,revision:'personal-v1',personalRemainingMg:0,personalRemainingAmount:0,publicRemainingMg:1500,publicRemainingAmount:150000,eligibleRemainingMg:1500,before:{personalRemainingMg:1000,personalRemainingAmount:85000,publicRemainingMg:2000,publicRemainingAmount:200000,eligibleRemainingMg:3000}}]};}
|
||||
test('个人回收料普通单与改单按归属走只读quote,两段成本相加而非公共均价乘整重',async()=>{
|
||||
for(const id of ['', 'editing']){const h=formHarness([pool({totalMg:2000,totalAmount:200000,averageRate:100000,remainingMg:2000,personalPools:{assistant:{remainingMg:1000}}})],[{quantity:'1.5'}],id),calls=[];h.context.__quote=personalQuote();h.context.api=async(url,input)=>{calls.push({url,input});return h.context.__quote;};assert.equal(h.preview(0).amount,null);await h.run('loadMaterialQuote()');const preview=h.preview(0);assert.equal(preview.amount,135000);assert.deepEqual(JSON.parse(JSON.stringify(preview.materialSources.map(source=>[source.kind,source.quantity,source.amount]))),[['personal_recovery',1000,85000],['public',500,50000]]);assert.equal(calls[0].url,'/api/material-pools/quote');assert.equal(calls[0].input.member,'assistant');assert.equal(calls[0].input.orderId,id||undefined);assert.equal(preview.balance.personalRemainingMg,0);assert.equal(preview.balance.publicRemainingMg,1500);assert.equal(h.choices().find(value=>value.id===D).availableMg,3000);assert.equal(h.context.__updated,1);}
|
||||
});
|
||||
test('个人池读数按当前成员隔离,换归属或离开后迟到quote不覆盖当前预览',async()=>{
|
||||
const h=formHarness([pool({personalPools:{assistant:{remainingMg:1000}}})],[{quantity:'1.5'}]);let resolve;h.context.api=()=>new Promise(yes=>{resolve=yes;});h.preview(0);const read=h.run('loadMaterialQuote()');h.member.value='assistant2';assert.equal(h.preview(0).amount,null);resolve(personalQuote());await read;assert.equal(h.context.__updated,0);assert.equal(h.preview(0).quote.result,null);h.context.__bad=personalQuote();h.context.__bad.entries[0].materialSources[0].member='assistant2';h.member.value='assistant';h.context.__input={date:SALE,member:'assistant',entries:[{lineIndex:0,poolId:D,mg:1500}]};assert.throws(()=>h.run('validateMaterialQuote(__bad,__input)'),/个人回收料/);
|
||||
});
|
||||
Reference in new issue
Block a user