سامانه صدور فاکتور و حسابداری
test(stage3): require canonical monetary fields from actual new sale/purchase UI (RED first)
davoodmehraban89 committed
Oct 23, 2026 at 02:29 UTC
69dae3ec7165e30bf8cbdfcc7cebc9f0848c76ad
1 file changed
+52
scripts/accounting-document-workflow.spec.js
+52
@@ -670,3 +670,55 @@ test('F2 validates formal invoice then saves a draft without posting any financi
670
expect(remoteInvoices(server)).toHaveLength(1);
671
expect([...server.records.values()].filter(x=>x.collection==='journalVouchers')).toHaveLength(0);
672
});
673
+
674
+
675
+test('Stage3 new sale and purchase UI must persist complete SQL-v1 monetary contract without rewriting history',async({page})=>{
676
+ const server=fakeServer();
677
+ await installHarness(page,server);
678
+ await authenticatedMockBrowser(page);
679
+
680
+ await fillInvoice(page,'STAGE3-SALE-CONTRACT',2);
681
+ await page.evaluate(()=>{
682
+ const mode=document.getElementById('invoice-vat-mode');
683
+ mode.value='with_vat';mode.dispatchEvent(new Event('change',{bubbles:true}));
684
+ document.getElementById('invoice-vat-type').value='percent';
685
+ document.getElementById('invoice-vat-rate-input').value='10';
686
+ recomputeTotals();
687
+ commitSaveInvoice();
688
+ });
689
+ await expect.poll(()=>remoteInvoices(server).find(x=>x.number==='STAGE3-SALE-CONTRACT')?.grandTotal,{timeout:15000}).toBe(3300);
690
+ const sale=remoteInvoices(server).find(x=>x.number==='STAGE3-SALE-CONTRACT');
691
+ expect(sale).toMatchObject({
692
+ kind:'formal',vatMode:'with_vat',vatType:'percent',vatRate:10,
693
+ discountType:'fixed',discountInput:0,currencyCode:'IRR',
694
+ accountingVersion:1,subtotal:3000,discount:0,vat:300,grandTotal:3300
695
+ });
696
+
697
+ await page.evaluate(()=>{
698
+ switchView('view-purchases');
699
+ purCancelEdit();
700
+ document.getElementById('pur-number').value='STAGE3-PURCHASE-CONTRACT';
701
+ document.getElementById('pur-supplier').value='QA_CONTACT';
702
+ document.getElementById('pur-payment-method').value='credit';
703
+ const tr=document.querySelector('#pur-items-body tr');
704
+ const product=tr.querySelector('.pur-prod');
705
+ product.value='QA_PROD';product.dispatchEvent(new Event('change',{bubbles:true}));
706
+ tr.querySelector('.pur-qty').value='2';
707
+ tr.querySelector('.pur-price').value='100';
708
+ document.getElementById('pur-discount').value='10';
709
+ document.getElementById('pur-vat-mode').value='with_vat';
710
+ document.getElementById('pur-vat-rate').value='10';
711
+ purRecalc();
712
+ purSave();
713
+ });
714
+ await expect.poll(()=>remotePurchases(server).find(x=>x.number==='STAGE3-PURCHASE-CONTRACT')?.grandTotal,{timeout:15000}).toBe(209);
715
+ const purchase=remotePurchases(server).find(x=>x.number==='STAGE3-PURCHASE-CONTRACT');
716
+ expect(purchase).toMatchObject({
717
+ paymentMethod:'credit',vatMode:'with_vat',vatType:'percent',vatRate:10,
718
+ discountType:'fixed',discountInput:10,currencyCode:'IRR',
719
+ accountingVersion:1,subtotal:200,discount:10,vat:19,grandTotal:209
720
+ });
721
+ expect(purchase.items).toHaveLength(1);
722
+ expect(purchase.items[0]).toMatchObject({qty:2,price:100,lineTotal:200});
723
+ expect(remoteInvoices(server).filter(x=>x.number==='STAGE3-SALE-CONTRACT')).toHaveLength(1);
724
+});