支持多商品锁价及待交付修改作废审批

This commit is contained in:
summer committed 2026-11-08 02:22:58 +08:00
1 parent 1cbcdc728c
commit 337b2a709f
28 files changed
+1187 -344

No files matched your search

+3 -2
View File
@@ -192,11 +192,12 @@ function reconcileInternal(l,date,actor,env,{skipJournalOrder=null,preservePrice
}
function recordReturns(l,order,date,input,actor,env){
if(!enabled(l)||date<config(l).cutover)return;assertDate(l,date,env);ensureDay(l,date,env);
if(LockPools.recordReturn(l,order,date,input,actor,env))return;
const lockedReturns=LockPools.recordReturn(l,order,date,input,actor,env);
for(const [index,line] of order.lines.entries()){
if(lockedReturns&&lockedReturns.includes(index))continue;
const destination=input.returnPockets?.[index]??line.pocket;if(!env.selfPockets?.includes(destination)||line.unit!=='g'||Calc.isSilver(line.name))continue;
const amount=line.costParts?.material;if(!Number.isSafeInteger(amount)||amount<0)env.fail('原商品金料成本尚未核实,不能将未知金额记为退货回料',409);
const usage=l.one('SELECT * FROM material_pool_usages WHERE order_id=? AND line_index=?',order.id,index),old=line.materialPool?.allocations;
const usage=l.one('SELECT * FROM material_pool_usages WHERE order_id=? AND line_index=?',order.id,index),old=line.materialPool?.allocations??(line.materialAllocations?PARTIES.map(payer=>({payer,amount:sum(line.materialAllocations.filter(part=>part.payer===payer),'amount')})).filter(part=>part.amount>0):null);
const allocations=old?.length?old:[{payer:line.costPayers?.material??line.payer,amount}];if(sum(allocations,'amount')!==amount)env.fail('退货回料金料成本归属不守恒');
const id=randomUUID();l.run('INSERT INTO material_rolling_returns VALUES (?,?,?,?,?,?,?,?,?,?,?)',id,order.id,index,date,line.quantity,amount,JSON.stringify(allocations),usage?.pool_id??'',usage?.pool_id===date?1:0,actor.name,env.now());registerSource(l,'return',id);Allocation.saveReturn(l,'order',id,line.materialPool?.materialSources);
}