取消已用回收单时将关联用料转入公共料池
This commit is contained in:
1 parent
19b1b0263c
commit
dec01a3dca
18 files changed
+380
-56
No files matched your search
@@ -60,9 +60,19 @@ function purchaseStatus(l,purchaseId){
|
||||
if(usedMg>purchase.mg)fail('回收批次耗用超过原克重,请先核对料池');
|
||||
return {purchaseId,recoveryId:source.recoveryId,member:source.materialOwner,mg:purchase.mg,usedMg,remainingMg:purchase.deleted_at?0:purchase.mg-usedMg,usages};
|
||||
}
|
||||
function cancelPurchase(l,purchaseId){
|
||||
if(!purchaseSource(l,purchaseId))return;
|
||||
const allocation=require('./material-pool-allocation');
|
||||
// 包含已退回的历史头尾段;重建原日及后续回料时,不能让已取消批次重新流入个人池。
|
||||
for(const row of l.rows('SELECT u.id,s.sources FROM material_usage_sources s JOIN material_pool_usages u ON u.id=s.usage_id WHERE instr(s.sources,?)>0 ORDER BY u.rowid',purchaseId))
|
||||
allocation.substitutePurchase(l,'order',row.id,purchaseId,sources(row.sources));
|
||||
for(const row of l.rows('SELECT id,snapshot FROM price_lock_pool_reservations WHERE instr(snapshot,?)>0 ORDER BY rowid',purchaseId))
|
||||
allocation.substitutePurchase(l,'priceLock',row.id,purchaseId,sources(JSON.parse(row.snapshot).materialSources));
|
||||
}
|
||||
function dependency(l){
|
||||
if(!exists(l,'recovery_material_batches')||!l.one('SELECT purchase_id FROM recovery_material_batches LIMIT 1'))return null;
|
||||
const names=['recovery_material_batches','material_usage_sources','material_return_sources'].filter(name=>exists(l,name));
|
||||
if(exists(l,'material_public_substitutions')&&l.one('SELECT source_id FROM material_public_substitutions LIMIT 1'))names.push('material_public_substitutions');
|
||||
return createHash('sha256').update(JSON.stringify(names.map(name=>[name,l.rows('SELECT * FROM '+name+' ORDER BY rowid')]))).digest('hex');
|
||||
}
|
||||
function ownershipReason(l,order,target=null,env){
|
||||
@@ -82,4 +92,4 @@ function ownershipReason(l,order,target=null,env){
|
||||
}
|
||||
return personal?'本单涉及个人回收料,不能直接转给其他归属人;请先更正用料并释放个人料占用,再调整归属。':'';
|
||||
}
|
||||
module.exports={initialize,registerSource,purchaseSource,blockedUsages,purchaseStatus,dependency,ownershipReason};
|
||||
module.exports={initialize,registerSource,purchaseSource,blockedUsages,purchaseStatus,cancelPurchase,dependency,ownershipReason};
|
||||
Reference in new issue
Block a user