@davoodmehraban89 / Factor-easy-2 Mirror · read-only / commits / 6c85dbb
Fork 0

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

Mirrored from https://github.com/davoodmehraban89/Factor-easy.git

Synced Dec 3, 20:45 UTC

fix(ui): classify linked source journal drafts accurately in sale and purchase

davoodmehraban89 committed Nov 22, 2026 at 16:40 UTC 6c85dbb6afd317b504795af9fe7a52ed6b026d04
3 files changed +38 -11
js/invoices.js
+7 -1
@@ -369,7 +369,13 @@ function invoiceDocumentStatus(inv){
369 const linked=inv.journalVoucherId&&typeof jeSourceVoucher==='function'?jeSourceVoucher(inv):null;
370 const linkedStatus=linked?(typeof jeRpcEffectiveStatus==='function'?jeRpcEffectiveStatus(linked):linked.status):'';
371 if(linkedStatus==='reversed'||inv.accountingStatus==='reversed'||inv.documentStatus==='reversed')return 'reversed';
372 - if(linkedStatus==='posted'||inv.journalVoucherId||inv.accountingStatus==='posted'||inv.documentStatus==='posted')return 'posted';
372 + // A linked draft is NOT posted merely because it has a journalVoucherId.
373 + // Contradictory source statuses require review instead of a false draft label.
374 + if(linkedStatus==='draft')
375 + return inv.accountingStatus==='posted'||inv.documentStatus==='posted'?'legacy_review':'draft';
376 + if(linkedStatus==='posted')return 'posted';
377 + if(inv.journalVoucherId)return 'legacy_review'; // unresolved/missing linked voucher
378 + if(inv.accountingStatus==='posted'||inv.documentStatus==='posted')return 'posted';
379 if(inv.documentStatus==='draft'||inv.accountingStatus==='draft')return 'draft';
380 if(invoiceCreatesAccountingEntry(inv.kind))return 'legacy_review';
381 return 'operational';
js/purchases.js
+4 -1
@@ -67,7 +67,10 @@
67 const linkedStatus=linked?(typeof jeRpcEffectiveStatus==='function'?jeRpcEffectiveStatus(linked):linked.status):'';
68 if(linkedStatus==='reversed'||p.accountingStatus==='reversed')return 'reversed';
69 if(linkedStatus==='posted')return 'posted';
70 - if(p.accountingStatus==='draft'&&!p.journalVoucherId)return 'draft';
70 + if(linkedStatus==='draft')
71 + return p.accountingStatus==='posted'||p.documentStatus==='posted'?'legacy_review':'draft';
72 + if(p.journalVoucherId)return 'legacy_review'; // missing or unresolved linked voucher
73 + if(p.accountingStatus==='draft')return 'draft';
74 return 'legacy_review';
75 }
76 window.purchaseDocumentStatus=purchaseDocumentStatus;
scripts/accounting-document-workflow.spec.js
+27 -9
@@ -941,9 +941,9 @@ test('contact operational balance reflects a saved unallocated supplier payment
941 });
942
943
944 -// Issue #229 / ADR0216: executable expected-RED acceptance contracts.
945 -// test.fail is a transparent temporary xfail, NOT a product PASS. Remove
946 -// annotations only after the linked-draft lifecycle works end-to-end.
944 +// Issue #229 / ADR0216: purchase Save remains expected-RED.
945 +// Linked-draft status is fixed in this independent UI-only candidate; its
946 +// regression below is now a normal PASS, not a false product-fix claim.
947 test('P0 #229 expected RED: purchase Save must not auto-post',async({page})=>{
948 const server=fakeServer();
949 await installHarness(page,server);
@@ -990,7 +990,7 @@ test('P0 #229 expected RED: purchase Save must not auto-post',async({page})=>{
990 });
991 });
992
993 -test('P0 #229 expected RED: linked journal draft stays draft for both sales and purchases',async({page})=>{
993 +test('P0 #229 linked journal draft stays draft for both sales and purchases',async({page})=>{
994 const server=fakeServer();
995 await installHarness(page,server);
996 await authenticatedMockBrowser(page);
@@ -1000,20 +1000,38 @@ test('P0 #229 expected RED: linked journal draft stays draft for both sales and
1000 journalVoucherId:'QA_SALE_JV_DRAFT',accountingStatus:'draft',documentStatus:'draft'};
1001 const purchase={id:'QA_PUR_LINK_DRAFT',ownerUserId,companyId,
1002 journalVoucherId:'QA_PUR_JV_DRAFT',accountingStatus:'draft',documentStatus:'draft'};
1003 - datastore.invoices.push(sale);
1004 - datastore.purchases.push(purchase);
1003 + const conflictingSale={...sale,id:'QA_SALE_LINK_CONFLICT',
1004 + journalVoucherId:'QA_SALE_JV_CONFLICT',accountingStatus:'posted'};
1005 + const conflictingPurchase={...purchase,id:'QA_PUR_LINK_CONFLICT',
1006 + journalVoucherId:'QA_PUR_JV_CONFLICT',documentStatus:'posted'};
1007 + const danglingSale={...sale,id:'QA_SALE_LINK_DANGLING',journalVoucherId:'QA_NOT_FOUND_SALE'};
1008 + const danglingPurchase={...purchase,id:'QA_PUR_LINK_DANGLING',journalVoucherId:'QA_NOT_FOUND_PUR'};
1009 + datastore.invoices.push(sale,conflictingSale,danglingSale);
1010 + datastore.purchases.push(purchase,conflictingPurchase,danglingPurchase);
1011 datastore.journalVouchers.push(
1012 {id:'QA_SALE_JV_DRAFT',ownerUserId,companyId,status:'draft',
1013 sourceType:'sale',sourceId:sale.id},
1014 {id:'QA_PUR_JV_DRAFT',ownerUserId,companyId,status:'draft',
1009 - sourceType:'purchase',sourceId:purchase.id}
1015 + sourceType:'purchase',sourceId:purchase.id},
1016 + {id:'QA_SALE_JV_CONFLICT',ownerUserId,companyId,status:'draft',
1017 + sourceType:'sale',sourceId:conflictingSale.id},
1018 + {id:'QA_PUR_JV_CONFLICT',ownerUserId,companyId,status:'draft',
1019 + sourceType:'purchase',sourceId:conflictingPurchase.id}
1020 );
1021 return {
1022 sale:invoiceDocumentStatus(sale),
1023 purchase:purchaseDocumentStatus(purchase),
1024 + conflictingSale:invoiceDocumentStatus(conflictingSale),
1025 + conflictingPurchase:purchaseDocumentStatus(conflictingPurchase),
1026 + danglingSale:invoiceDocumentStatus(danglingSale),
1027 + danglingPurchase:purchaseDocumentStatus(danglingPurchase),
1028 voucherStates:getMyJournalVouchers().filter(v=>v.id.endsWith('_JV_DRAFT')).map(v=>v.status)
1029 };
1030 });
1017 - test.fail(true,'#229: linked draft misclassified in sale and purchase status selectors');
1018 - expect(observed).toEqual({sale:'draft',purchase:'draft',voucherStates:['draft','draft']});
1031 + expect(observed).toEqual({
1032 + sale:'draft',purchase:'draft',
1033 + conflictingSale:'legacy_review',conflictingPurchase:'legacy_review',
1034 + danglingSale:'legacy_review',danglingPurchase:'legacy_review',
1035 + voucherStates:['draft','draft']
1036 + });
1037 });