打印状态移至备注后并在点击打印时自动记录

This commit is contained in:
summer committed 2026-12-04 03:20:49 +08:00
1 parent 846a30cded
commit c12f2157b4
6 files changed
+80 -40

No files matched your search

+4 -4
View File
@@ -10,7 +10,7 @@ function fixture(t){
return {l,actors,order,run,mark};
}
const snapshot=l=>JSON.stringify(['orders','payments','expenses','movements','journal','price_locks','material_purchases','recovery_material_batches'].filter(name=>l.one("SELECT name FROM sqlite_master WHERE type='table' AND name=?",name)).map(name=>[name,l.rows('SELECT * FROM '+name)]));
test('打开预览不是已打印;人工确认和撤销不改变订单账目、复核与库存',t=>{
test('打开预览不是已打印;记录打印和撤销不改变订单账目、复核与库存',t=>{
const f=fixture(t),{l,order,actors}=f;
l.audit(order,'打开打印页',actors.assistant,{notice:'不代表纸张已输出'});
assert.equal(Print.read(l,'order',order,actors.assistant).printed,false);
@@ -21,7 +21,7 @@ test('打开预览不是已打印;人工确认和撤销不改变订单账目
assert.equal(f.mark('order',order,false).printed,false);
assert.equal(snapshot(l),before);assert.deepEqual(l.orderBook({date:today()}).rows,financialRows);assert.equal(l.detail(order).revision,detail.revision);
assert.equal(l.detail(order).reviewed_revision,detail.reviewed_revision);
assert.equal(l.rows("SELECT * FROM audit WHERE entity=? AND action IN ('确认已打印','改为未打印')",order).length,2);
assert.equal(l.rows("SELECT * FROM audit WHERE entity=? AND action IN ('记录打印操作','改为未打印')",order).length,2);
assert.ok(!Object.hasOwn(l.publicOrder(order),'printStatus'),'客户单据数据不带内部打印登记');
});
test('回收、置换与关联销售单共用打印状态;店员不能操作别人的单',t=>{
@@ -49,14 +49,14 @@ test('旧状态和旧打印页不能覆盖新记录,重试幂等,失败事
assert.throws(()=>f.run({},()=>{Print.update(l,'order',order,{...Print.read(l,'order',order,actors.assistant),printed:false},actors.assistant);throw new Error('rollback');}));
assert.equal(Print.read(l,'order',order,actors.assistant).printed,true);
});
test('HTTP打印页含人工确认,接口鉴权、账号切换和重试正常',async t=>{
test('HTTP打印页自动登记且无人工确认入口,接口鉴权、账号切换和重试正常',async t=>{
const f=fixture(t),dir=fs.mkdtempSync(path.join(os.tmpdir(),'print-status-http-')),app=createApp({mode:'trial',ledger:f.l,dataDir:dir,networkAccess:{header:'',trustedProxies:[]},feishuConfig:{enabled:false}});
await new Promise(done=>app.server.listen(0,'127.0.0.1',done));t.after(async()=>{await new Promise(done=>app.server.close(done));fs.rmSync(dir,{recursive:true,force:true});});
const base='http://127.0.0.1:'+app.server.address().port;
const login=await fetch(base+'/api/login',{method:'POST',headers:{'Content-Type':'application/json','X-Requested-With':'maimai-ledger',Origin:base},body:JSON.stringify({name:f.actors.assistant.name,password:'synthetic-print-password'})});assert.equal(login.status,200);
const headers={Cookie:login.headers.get('set-cookie').split(';')[0],'X-Ledger-User':f.actors.assistant.id},url=base+'/api/print-status/order/'+f.order;
assert.equal((await fetch(url)).status,401);
const html=await (await fetch(base+'/print/'+f.order,{headers})).text();assert.match(html,/id="confirm-document-print"/);assert.match(html,/未打印(未登记)/);assert.match(html,/data-state=/);
const html=await (await fetch(base+'/print/'+f.order,{headers})).text();assert.doesNotMatch(html,/id="confirm-document-print"/);assert.match(html,/id="retry-document-print" type="button" hidden/);assert.match(html,/未打印/);assert.match(html,/data-state=/);
const current=await (await fetch(url,{headers})).json(),body=JSON.stringify({printed:true,revision:current.revision,sourceRevision:current.sourceRevision}),key=randomUUID(),options={method:'POST',headers:{...headers,'Content-Type':'application/json','X-Requested-With':'maimai-ledger',Origin:base,'Idempotency-Key':key},body};
assert.equal((await fetch(url,{...options,headers:{...options.headers,'X-Ledger-User':f.actors.owner.id}})).status,409);
assert.equal((await fetch(url,options)).status,200);assert.equal((await fetch(url,options)).status,200);