سامانه صدور فاکتور و حسابداری
test: cover purchase finalization through accounting RPC
davoodmehraban89 committed
Nov 17, 2026 at 21:46 UTC
d1554a4f82b703eae37def7f7783db0c0fabe88d
1 file changed
+6
-4
scripts/accounting-document-workflow.spec.js
+6
-4
@@ -71,7 +71,8 @@ async function installHarness(page,server){
71
documentPostedBy:'FINORA_F0_FIXTURE_ONLY',documentVersion:Number(sourceRow.data.documentVersion||1),updatedAt:now};
72
server.records.set(sourceKey,{collection:args.p_source_collection,id:args.p_source_id,data:updatedSource,version:(Number(sourceRow.version)||1)+1});
73
server.records.set('journalVouchers|'+voucherId,{collection:'journalVouchers',id:voucherId,data:voucher,version:1});
74
- const debitAccount=kind==='sale'?'A_AR':'A_BUY',creditAccount=kind==='sale'?'A_REV':'A_AP';
74
+ const debitAccount=kind==='sale'?(sourceRow.data.paymentMethod==='credit'?'A_AR':'A_CASH'):'A_BUY';
75
+ const creditAccount=kind==='sale'?'A_REV':(sourceRow.data.paymentMethod==='credit'?'A_AP':'A_CASH');
76
const lines=[
77
{id:voucherId+'_L1',data:{voucherId,companyId:args.p_header.companyId,fiscalYearId:args.p_header.fiscalYearId,accountId:debitAccount,debit:amount,credit:0}},
78
{id:voucherId+'_L2',data:{voucherId,companyId:args.p_header.companyId,fiscalYearId:args.p_header.fiscalYearId,accountId:creditAccount,debit:0,credit:amount}}
@@ -375,9 +376,9 @@ test('pilot cancellation preserves posted invoice record while only unposted dra
376
377
function remotePurchases(server){return [...server.records.values()].filter(x=>x.collection==='purchases').map(x=>copy(x.data));}
378
async function createPostedPurchase(page,server,number='PILOT-PUR-001',qty=2){
378
- const id=await page.evaluate(({number,qty})=>{
379
- const p={id:'PUR-QA-'+number,ownerUserId:'FINORA_F0_FIXTURE_ONLY',companyId:'QA_CO',number,date:'1405/07/19',supplierId:'QA_CONTACT',supplierName:'خریدار آزمایشی',paymentMethod:'cash',warehouseId:'',projectId:'',items:[{prodId:'QA_PROD',prodName:'بلوک سیمانی',qty,unit:'عدد',price:100,lineTotal:qty*100}],grandTotal:qty*100,vat:0,accountingVersion:1};
380
- datastore.purchases.push(p);jePostSourceRecord('purchase',p);return p.id;
379
+ const id=await page.evaluate(async({number,qty})=>{
380
+ const p={id:'PUR-QA-'+number,ownerUserId:'FINORA_F0_FIXTURE_ONLY',companyId:'QA_CO',number,date:'1405/07/19',supplierId:'QA_CONTACT',supplierName:'خریدار آزمایشی',paymentMethod:'cash',warehouseId:'',projectId:'',items:[{prodId:'QA_PROD',prodName:'بلوک سیمانی',qty,unit:'عدد',price:100,lineTotal:qty*100}],subtotal:qty*100,discount:0,discountType:'fixed',discountInput:0,vat:0,vatMode:'none',vatType:'percent',vatRate:0,grandTotal:qty*100,accountingVersion:1,documentVersion:1,accountingStatus:'draft',documentStatus:'draft'};
381
+ datastore.purchases.push(p);await finalizePurchasePilotDraft(p.id);return p.id;
382
},{number,qty});
383
await expect.poll(()=>remotePurchases(server).find(x=>x.id===id)?.journalVoucherId,{timeout:13000}).toBeTruthy();
384
return id;
@@ -385,6 +386,7 @@ async function createPostedPurchase(page,server,number='PILOT-PUR-001',qty=2){
386
test('pilot purchase: posted to corrective draft to edited balanced repost via document manager',async({page})=>{
387
const server=fakeServer();await installHarness(page,server);await authenticatedMockBrowser(page);
388
const originalId=await createPostedPurchase(page,server);
389
+ expect(server.autoPostCount).toBe(1);
390
const first=remotePurchases(server).find(x=>x.id===originalId);
391
expect(first.accountingStatus).toBe('posted');
392
const voucher=first.journalVoucherId;