فینورا پرو - سامانه جامع حسابداری و صدور فاکتور
test(A01): block over-credit on inflated or cumulative returns without partial writes
davoodmehraban89 committed
Oct 15, 2026 at 20:50 UTC
3a64fa6ad941fd5aa47187b1afede988a6ff34dd
1 file changed
+30
tests/retail-phase2.test.mjs
+30
@@ -454,3 +454,33 @@ test('A01: customer returns reject non-posted legacy origin without partial writ
454
assert.equal((await db.getAll('journal_entries')).length, countBefore);
455
assert.equal((await db.getAll('document_corrections')).length, 0);
456
});
457
+
458
+test('A01: inflated return price cannot credit more than the original sale total', async () => {
459
+ await setup();
460
+ await purchase10();
461
+ const original = await sale3({ paidAmount: 200 });
462
+ const before = {
463
+ stock: await db.getAll('stock_movements'),
464
+ journals: await db.getAll('journal_entries'),
465
+ settlements: await db.getAll('settlements'),
466
+ invoices: await db.getAll('invoices')
467
+ };
468
+ const inflated = invoice('sale_return', 1, 650, { originalInvoiceId: original.id });
469
+ await assert.rejects(retail.issueInvoice(inflated), /مجموع مبلغ مرجوعی/);
470
+ assert.deepEqual(await db.getAll('stock_movements'), before.stock);
471
+ assert.deepEqual(await db.getAll('journal_entries'), before.journals);
472
+ assert.deepEqual(await db.getAll('settlements'), before.settlements);
473
+ assert.deepEqual(await db.getAll('invoices'), before.invoices);
474
+});
475
+
476
+test('A01: successive returns cannot exceed original gross even if total quantities fit', async () => {
477
+ await setup();
478
+ await purchase10();
479
+ const original = await sale3();
480
+ await retail.issueInvoice(invoice('sale_return', 1, 400, {
481
+ originalInvoiceId: original.id
482
+ }));
483
+ const excessive = invoice('sale_return', 1, 300, { originalInvoiceId: original.id });
484
+ await assert.rejects(retail.issueInvoice(excessive), /مجموع مبلغ مرجوعی/);
485
+ assert.equal((await db.getAll('document_corrections')).length, 1);
486
+});