成本配置改用紧凑列表增删查改,空目录不恢复固定项目

This commit is contained in:
summer committed 2026-12-04 01:24:14 +08:00
1 parent ba67ba790d
commit 13382e4d49
7 files changed
+88 -28

No files matched your search

@@ -4,6 +4,8 @@ const {Ledger,today}=require('../ledger'),{createUser}=require('../server'),Sett
function fixture(t){
const l=new Ledger(':memory:');t.after(()=>l.close());l.enableTeamMode();
const owner=require('../new-shop').initialize(l,{storeName:'合成独立店',ownerLabel:'老板甲',ownerLoginName:'test-owner',ownerPassword:'synthetic-test-password'},createUser);
// 兼容性案例显式装入旧店目录;新店空目录另外验收。
Settings.update(l,{revision:Settings.read(l).revision,costPresets:Fees.presetCatalog()},owner);
const add=(label='客服乙')=>Employees.create(l,{revision:Settings.read(l).revision,label,loginName:'login-'+randomUUID(),password:'synthetic-test-password'},owner).employee;
const patch=input=>Settings.update(l,{revision:Settings.read(l).revision,...input},owner);
const run=(input,fn)=>l.scope(owner,()=>l.transact(randomUUID(),owner,input,fn));
@@ -81,3 +83,22 @@ test('勾选成本配置拒绝坏键、重复名字和非法启用类型,旧
for(const costPresets of [{__bad:{name:'x',amount:'1',payer:'owner'}},{[kind]:{name:'京东快递',amount:'1',payer:'owner'}},{box:{enabled:'false'}},{box:{byQuantity:1}},{box:{name:''}},{[kind]:{name:'新项'}}])assert.throws(()=>f.patch({costPresets}));
assert.deepEqual(Settings.read(f.l),before);assert.equal(Fees.presetCatalog().box.byQuantity,true);assert.equal(Fees.presetCatalog().jd.enabled,true);
});
test('成本目录真正删除默认及自定义项,空目录在其他配置和员工更新后不复活,历史账保留',t=>{
const f=fixture(t),kind='custom_'+randomUUID();f.patch({costPresets:{[kind]:{name:'可删除礼袋',amount:'5',payer:'owner',enabled:true,byQuantity:false}}});
const fees=[Fees.presetFee('jd','1','owner',Settings.read(f.l).costPresets),Fees.presetFee(kind,'1','owner',Settings.read(f.l).costPresets)];
const input={date:today(),customer:'合成删除检查',internal_note:'合成测试',salesperson:'开单名称',member:'owner',payment_account:'麦麦微信',rounding_mode:'cent',discount:'0',fee_cost_mode:'checkboxes',lines:[{name:'银饰',unit:'件',quantity:'1',pocket:'',payer:'owner',cost:'20',sale:'100'}],fee_items:fees};
const result=f.run(input,()=>f.l.issueOrder(input,f.owner)),before=financial(f.l),original=f.l.detail(result.id);
const revision=Settings.read(f.l).revision;f.patch({costPresets:{jd:null,[kind]:null}});
assert.ok(!Object.hasOwn(Settings.read(f.l).costPresets,'jd'));assert.ok(!Object.hasOwn(Settings.read(f.l).costPresets,kind));
assert.equal(financial(f.l),before);assert.equal(f.l.detail(result.id).profit,original.profit);assert.equal(Fees.presetKind(fees[0],{presets:Settings.read(f.l).costPresets}),'');
assert.throws(()=>Settings.update(f.l,{revision,costPresets:{jd:{amount:'9'}}},f.owner),/已有变动/);
f.patch({costPresets:Object.fromEntries(Object.keys(Settings.read(f.l).costPresets).map(key=>[key,null]))});assert.deepEqual(Settings.read(f.l).costPresets,{});
f.patch({storeName:'空目录的店'});f.add('新员工不复活成本');assert.deepEqual(Settings.read(f.l).costPresets,{});assert.deepEqual(Fees.presetCatalog({}),{});assert.equal(Fees.customPresets({}),true);
assert.equal(financial(f.l),before);
});
test('新店成本目录为空,可从零新增项目',t=>{
const l=new Ledger(':memory:');t.after(()=>l.close());const actor=require('../new-shop').initialize(l,{storeName:'新店',ownerLabel:'店主',ownerLoginName:'test-empty',ownerPassword:'synthetic-test-password'},createUser);
assert.deepEqual(Settings.read(l).costPresets,{});const key='custom_'+randomUUID();Settings.update(l,{revision:Settings.read(l).revision,costPresets:{[key]:{name:'自定项目',amount:'1.25',payer:'owner',enabled:true,byQuantity:true}}},actor);
assert.deepEqual(Object.keys(Settings.read(l).costPresets),[key]);assert.equal(Fees.presetFee(key,'4','owner',Settings.read(l).costPresets).amount,'5');
});