سامانه صدور فاکتور و حسابداری
test(adr216): preserve reversed-source projection in historical posting inventory
davoodmehraban89 committed
Nov 22, 2026 at 09:47 UTC
858076f35a413ecc9ca9f3e3d8b235c30094fe7f
2 files changed
+10
-3
scripts/draft-conversion-inventory.test.mjs
+5
-1
@@ -80,9 +80,13 @@ test('source-derived inventory on isolated PostgreSQL preserves scope, exact amo
80
insert('journalVouchers','P_JV',{companyId:'C',sourceType:'purchase',sourceId:'P_DRAFT_BAD',status:'draft'});
81
insert('invoices','I_UNLINKED',{companyId:'C',kind:'formal',documentStatus:'draft',accountingStatus:'draft'});
82
insert('journalVouchers','J_UNLINKED',{companyId:'C',sourceType:'sale',sourceId:'I_UNLINKED',status:'draft'});
83
+ // Historical posted voucher remains posted after a legitimate compensating
84
+ // reversal; the linked source's two statuses may be reversed consistently.
85
+ insert('invoices','I_REVERSED',{companyId:'C',kind:'formal',journalVoucherId:'J_REVERSED',documentStatus:'reversed',accountingStatus:'reversed'});
86
+ insert('journalVouchers','J_REVERSED',{companyId:'C',sourceType:'sale',sourceId:'I_REVERSED',status:'posted'});
87
const signal=inventory().sourceIdentityAudit;
88
assert.deepEqual(signal,{
85
- sourcesConsidered:8, withoutGeneratedVoucher:4,
89
+ sourcesConsidered:9, withoutGeneratedVoucher:4,
90
unlinkedWithGeneratedVoucher:1, danglingSourceLinks:1,
91
wrongIdentitySourceLinks:1, linkedDraftSources:2,
92
linkedDraftProjectionMismatches:1, postedProjectionMismatches:1,
scripts/sql/draft-conversion-inventory.sql
+5
-2
@@ -120,8 +120,11 @@ with vouchers as (
120
linked_data->>'sourceType'=kind and linked_data->>'sourceId'=id
121
and linked_owner=owner_id and linked_data->>'companyId'=data->>'companyId'
122
and linked_data->>'status'='posted' and
123
- (data->>'documentStatus' is distinct from 'posted' or
124
- data->>'accountingStatus' is distinct from 'posted')) posted_projection_mismatches
123
+ -- A compensating reversal leaves its original voucher posted; the
124
+ -- business source may legitimately have BOTH projections reversed.
125
+ not ((data->>'documentStatus'='posted' and data->>'accountingStatus'='posted')
126
+ or (data->>'documentStatus'='reversed' and data->>'accountingStatus'='reversed'))
127
+ ) posted_projection_mismatches
128
from source_observations
129
), generated_health as (
130
select