سامانه صدور فاکتور و حسابداری

test(ux): verify same sale/purchase number, deferred reversal, cancel, save, print and reload

davoodmehraban89 committed Oct 14, 2026 at 09:47 UTC e4832c962c3758791610fb653cb41a8a2bd99a26
1 file changed +77
scripts/accounting-document-workflow.spec.js
+77
@@ -332,6 +332,83 @@ test('pilot purchase denies paid/consumed source; cancels unallocated posting wi
332 expect(await page.evaluate(()=>productMovement('QA_PROD').available)).toBe(0);
333 expect(await page.evaluate(id=>{try{deletePurchasePilotDraft(id);return 'unsafe'}catch(e){return String(e.message)}},purchaseId)).not.toBe('unsafe');
334 });
335 +test('seamless sale correction: opening and cancelling leaves ledger unchanged; saving retains visible identity, printing and audit',async({page})=>{
336 + const server=fakeServer();await installHarness(page,server);await authenticatedMockBrowser(page);
337 + await fillInvoice(page,'SAME-SALE-001',2);await page.evaluate(()=>commitSaveInvoice());
338 + await expect.poll(()=>remoteInvoices(server).length,{timeout:13000}).toBe(1);
339 + const id=remoteInvoices(server)[0].id;await page.evaluate(x=>finalizeInvoiceDocument(x),id);
340 + await expect.poll(()=>remoteInvoices(server)[0]?.accountingStatus,{timeout:13000}).toBe('posted');
341 + const original=copy(remoteInvoices(server)[0]),initialLines=[...server.records.values()].filter(x=>x.collection==='journalLines').map(copy);
342 + await page.evaluate(()=>navigateShell('accounting','view-journal','documents'));
343 + await expect(page.locator('#finora-document-management-body tr')).toHaveCount(1);
344 + await page.locator('#finora-document-management-body [data-doc-action="reopen"]').click();
345 + await expect(page.locator('#edit-invoice-id')).toHaveValue(id);
346 + await expect(page.locator('#invoice-number')).toHaveValue('SAME-SALE-001');
347 + expect([...server.records.values()].filter(x=>x.collection==='journalVouchers')).toHaveLength(1);
348 + await page.evaluate(()=>cancelInvoiceEdit());
349 + expect([...server.records.values()].filter(x=>x.collection==='journalVouchers')).toHaveLength(1);
350 + expect(remoteInvoices(server)).toHaveLength(1);
351 + await page.evaluate(x=>beginInvoiceAmendment(x),id);
352 + await page.locator('#invoice-items-table-body .row-quantity').first().fill('3');
353 + await page.locator('#invoice-items-table-body .row-quantity').first().dispatchEvent('input');
354 + await page.evaluate(()=>commitSaveInvoice());
355 + await expect.poll(()=>remoteInvoices(server).filter(x=>x.correctsInvoiceId===id&&x.accountingStatus==='posted').length,{timeout:20000}).toBe(1);
356 + expect(remoteInvoices(server)).toHaveLength(2);expect(remoteInvoices(server).find(x=>x.id===id)).toEqual(original);
357 + const current=remoteInvoices(server).find(x=>x.correctsInvoiceId===id);
358 + expect(current.grandTotal).toBe(4500);
359 + expect(current.number).not.toBe(original.number);
360 + const visible=await page.evaluate(()=>invoiceVisibleRecords().map(x=>({id:x.id,number:invoiceVisibleNumber(x)})));
361 + expect(visible).toEqual([{id:current.id,number:'SAME-SALE-001'}]);
362 + await page.evaluate(()=>navigateShell('accounting','view-journal','documents'));
363 + await expect(page.locator('#finora-document-management-body tr')).toHaveCount(1);
364 + await expect(page.locator('#finora-document-management-body')).toContainText('SAME-SALE-001');
365 + await expect(page.locator('#finora-document-management-body')).not.toContainText('-اصلاح');
366 + await page.evaluate(x=>renderAndPrintDirect(x),id);
367 + await expect(page.locator('#printable-invoice')).toContainText('SAME-SALE-۰۰۱');
368 + await expect(page.locator('#printable-invoice')).toContainText('۴٬۵۰۰');
369 + await expect(page.locator('#printable-invoice')).not.toContainText('-اصلاح');
370 + expect(initialLines).toEqual([...server.records.values()].filter(x=>x.collection==='journalLines'&&x.data.voucherId===original.journalVoucherId).map(copy));
371 + const vouchers=[...server.records.values()].filter(x=>x.collection==='journalVouchers');
372 + expect(vouchers).toHaveLength(3);expect(vouchers.find(v=>v.id===original.journalVoucherId).data.status).toBe('reversed');
373 + await page.reload({waitUntil:'domcontentloaded'});await authenticatedMockBrowser(page);
374 + await page.evaluate(()=>navigateShell('accounting','view-journal','documents'));
375 + await expect(page.locator('#finora-document-management-body tr')).toHaveCount(1);
376 + await expect(page.locator('#finora-document-management-body')).toContainText('SAME-SALE-001');
377 +});
378 +
379 +test('seamless purchase correction: same visible number, no write on opening, save and print corrected purchase',async({page})=>{
380 + const server=fakeServer();await installHarness(page,server);await authenticatedMockBrowser(page);
381 + const id=await createPostedPurchase(page,server,'SAME-PURCHASE-001',2);
382 + const initial=copy(remotePurchases(server).find(x=>x.id===id));const before=[...server.records.values()].filter(x=>x.collection==='journalVouchers');
383 + await page.evaluate(()=>navigateShell('accounting','view-journal','documents'));
384 + await expect(page.locator('#finora-purchase-document-management-body tr')).toHaveCount(1);
385 + await page.locator('#finora-purchase-document-management-body [data-doc-action="reopen"]').click();
386 + await expect(page.locator('#pur-edit-id')).toHaveValue(id);
387 + await expect(page.locator('#pur-number')).toHaveValue('SAME-PURCHASE-001');
388 + expect([...server.records.values()].filter(x=>x.collection==='journalVouchers')).toHaveLength(before.length);
389 + await page.evaluate(()=>purCancelEdit());
390 + expect(remotePurchases(server)).toHaveLength(1);
391 + await page.evaluate(x=>beginPurchaseAmendment(x),id);
392 + await page.locator('#pur-items-body .pur-qty').first().fill('3');
393 + await page.locator('#pur-items-body .pur-qty').first().dispatchEvent('input');
394 + await page.locator('#pur-save-btn').click();
395 + await expect.poll(()=>remotePurchases(server).filter(x=>x.correctsPurchaseId===id&&x.accountingStatus==='posted').length,{timeout:20000}).toBe(1);
396 + expect(remotePurchases(server).find(x=>x.id===id)).toEqual(initial);
397 + const current=remotePurchases(server).find(x=>x.correctsPurchaseId===id);
398 + expect(current.grandTotal).toBe(300);expect(current.number).not.toBe(initial.number);
399 + const visible=await page.evaluate(()=>purchaseVisibleRecords().map(x=>({id:x.id,number:purchaseVisibleNumber(x)})));
400 + expect(visible).toEqual([{id:current.id,number:'SAME-PURCHASE-001'}]);
401 + await page.evaluate(()=>navigateShell('accounting','view-journal','documents'));
402 + await expect(page.locator('#finora-purchase-document-management-body tr')).toHaveCount(1);
403 + await expect(page.locator('#finora-purchase-document-management-body')).toContainText('SAME-PURCHASE-001');
404 + await expect(page.locator('#finora-purchase-document-management-body')).not.toContainText('-اصلاح');
405 + await page.evaluate(x=>purPrint(x),id);
406 + await expect(page.locator('#finora-purchase-document-management-body')).toContainText('SAME-PURCHASE-001');
407 + expect(await page.evaluate(()=>productMovement('QA_PROD').available)).toBe(3);
408 + await page.reload({waitUntil:'domcontentloaded'});await authenticatedMockBrowser(page);
409 + await page.evaluate(()=>navigateShell('accounting','view-journal','documents'));
410 + await expect(page.locator('#finora-purchase-document-management-body tr')).toHaveCount(1);
411 +});
412 test('cannot finalize draft if fiscal posting chart has no required account; draft remains intact',async({page})=>{
413 const server=fakeServer();server.records.delete('accounts|A_REV');await installHarness(page,server);await authenticatedMockBrowser(page);
414 await fillInvoice(page,'FIN-NO-REVENUE-ACCOUNT',2);await page.evaluate(()=>commitSaveInvoice());