فینورا پرو - سامانه جامع حسابداری و صدور فاکتور

fix(finance UX): leave invalid numeric paste visible and reject it before native invoice writes

davoodmehraban89 committed Oct 31, 2026 at 20:31 UTC fd55e9bbb7bc55c860af034622bc70aa97e08c20
4 files changed +36 -2
src/utils/NumberInput.js
+6
@@ -79,6 +79,12 @@ export const NumberInput = {
79 const oldValue = el.value;
80 const cursor = el.selectionStart ?? oldValue.length;
81 const digits = this._fractionDigits(el);
82 + // Do not silently turn malformed pasted text (2x5, 1,23) into a
83 + // different amount. Leave it visible so strict save validation rejects it.
84 + const normalized = latinDigits(oldValue).replace(/[٬،]/g, ',');
85 + if (!/^-?[\d,]*(?:\.[\d]*)?$/.test(normalized)) return;
86 + const whole = normalized.split('.')[0].replace(/^-/, '');
87 + if (whole.includes(',') && !/^\d{1,3}(?:,\d{3})+$/.test(whole)) return;
88 const formatted = this._formatText(oldValue, digits);
89 if (formatted === oldValue) return;
90
src/views/InvoiceFormView.js
+10 -2
@@ -416,9 +416,17 @@ class InvoiceFormViewImpl {
416 if (field === 'discount') {
417 // The textbox contains raw percent/rial input, not the computed rial
418 // discount. _recalc() sets item.discount only after using this value.
419 - ctx.data.items[idx].discountInput = NumberInput.parse(value);
419 + try {
420 + ctx.data.items[idx].discountInput = NumberInput.parseStrict(value, {
421 + decimals: ctx.data.items[idx].discountType === 'percent' ? 2 : 0, optional: true
422 + });
423 + } catch (_) { ctx.data.items[idx].discountInput = NaN; }
424 } else if (field === 'qty' || field === 'price') {
421 - ctx.data.items[idx][field] = NumberInput.parse(value);
425 + try {
426 + ctx.data.items[idx][field] = NumberInput.parseStrict(value, {
427 + decimals: field === 'qty' ? 3 : 0, optional: field !== 'qty'
428 + });
429 + } catch (_) { ctx.data.items[idx][field] = NaN; }
430 } else {
431 ctx.data.items[idx][field] = value;
432 }
tests/number-input-fractions.test.mjs
+13
@@ -133,3 +133,16 @@ test('invoice write path validates displayed row and VAT inputs strictly',()=>{
133 assert.match(src,/vatRate = NumberInput\.parseStrict/);
134 assert.match(src,/data-decimals="\\?\$\{item\.discountType === 'percent' \? 2 : 0\}"/);
135 });
136 +
137 +
138 +test('live input never sanitizes malformed currency or quantity into another number',()=>{
139 + for(const malformed of ['2x5','1,23','1 000','12..5','1e3']) {
140 + const el=field(malformed,{decimals:3});
141 + NumberInput._formatLive(el);
142 + assert.equal(el.value,malformed);
143 + assert.throws(()=>NumberInput.parseStrict(el,{decimals:3}),/نامعتبر/);
144 + }
145 + const valid=field('۱۲۳۴٫۵',{decimals:3});
146 + NumberInput._formatLive(valid);
147 + assert.equal(valid.value,'1,234.5');
148 +});
tests/windows-vm-native-functional-matrix.cjs
+7
@@ -176,6 +176,13 @@ async function purchaseInvoice() {
176 quantityField.dispatchEvent(new Event('input', { bubbles: true }));
177 check(quantityField.value === '2.5',
178 'Native input silently changed 2.5 to an incorrect financial quantity');
179 + // Malformed paste must never silently become a new financial quantity.
180 + quantityField.value = '2x5';
181 + quantityField.dispatchEvent(new Event('input', { bubbles: true }));
182 + check(quantityField.value === '2x5', 'Native formatter silently rewrote an invalid invoice amount');
183 + await window.InvoiceFormView._save(false);
184 + check(!(await FINORA.Storage.getAll('invoices')).some(x => x.contactId === c.id && x.kind === 'purchase'),
185 + 'Malformed native invoice quantity committed financial data');
186 // Restore the original synthetic invoice fixture before financial posting.
187 document.querySelector('.row-qty').value = '10';
188 window.InvoiceFormView._onFieldChange(0, 'qty', '10');