فینورا پرو - سامانه جامع حسابداری و صدور فاکتور
fix(finance): reject excessive global invoice discounts
Factor EasyPro QA committed
Nov 1, 2026 at 21:23 UTC
8b24d535902625c9e5097ad9b480dffeea0c2408
2 files changed
+17
-1
src/controllers/InvoiceController.js
+2
-1
@@ -88,7 +88,8 @@ class InvoiceControllerImpl {
88
} else {
89
totalDiscount = amount(discInput,'تخفیف ثابت کل');
90
}
91
- totalDiscount = Math.max(0, Math.min(totalDiscount, subtotal));
91
+ if (totalDiscount > subtotal)
92
+ throw Error('تخفیف کل نمیتواند بیشتر از مبلغ فاکتور باشد');
93
94
const afterDiscount = Math.max(0, subtotal - totalDiscount);
95
tests/invoice-discount-input-integrity.test.mjs
+15
@@ -107,3 +107,18 @@ test('malformed VAT, global discount or payment inputs are rejected before invoi
107
assert.deepEqual(await StorageService.getByCompany('invoices','discount-test-company'),[]);
108
}
109
});
110
+
111
+test('global fixed discount above subtotal is rejected without a preinvoice write', async () => {
112
+ await setup();
113
+ const payload = { ...base(10), discountType: 'fixed', discountInput: 2701 };
114
+ await assert.rejects(InvoiceController.save(payload), /تخفیف کل/);
115
+ assert.deepEqual(await StorageService.getByCompany('invoices', 'discount-test-company'), []);
116
+});
117
+
118
+test('global fixed discount equal to subtotal is valid and produces zero total', async () => {
119
+ await setup();
120
+ const invoice = await InvoiceController.save({ ...base(10), discountInput: 2700 });
121
+ assert.equal(invoice.totalDiscount, 2700);
122
+ assert.equal(invoice.grandTotal, 0);
123
+ assert.equal(invoice.remaining, 0);
124
+});
\ No newline at end of file