فینورا پرو - سامانه جامع حسابداری و صدور فاکتور
fix(finance): reject invoice company mismatch before posting
Davood Mehraban committed
Nov 23, 2026 at 09:19 UTC
bc50cb24340959dbdc1cac9aa01ca7dd570a61db
2 files changed
+22
src/core/RetailPostingService.js
+2
@@ -226,6 +226,8 @@ class RetailPostingServiceImpl {
226
invoice.idempotencyKey || ('factor-easypro-invoice-id:' + invoice.id));
227
invoice = { ...invoice, ...identity };
228
const company=await DataScope.companyId();
229
+ if(invoice.companyId!==company)
230
+ throw Error('شناسه شرکت فاکتور با شرکت فعال مطابقت ندارد');
231
if(!await this.isEnabled())throw Error('حسابداری یکپارچه برای این شرکت فعال نیست');
232
assertInvoiceTotals(invoice);
233
// A return is a new commercial/ledger document, not authorization for
tests/g316-company-boundary.test.mjs
+20
@@ -30,6 +30,26 @@ async function setup(){
30
contactId:'g316-foreign-contact',date});
31
await retail.activate();
32
}
33
+
34
+test('G316: invoice issuance rejects a foreign company identity without any financial writes',async()=>{
35
+ await setup();
36
+ const attempt={id:'g316-foreign-issue-attempt',companyId:'g316-scope-foreign',
37
+ number:'G316-FOREIGN-ISSUE',clientUuid:'g316-foreign-issue-attempt',kind:'sale',
38
+ date,contactId:'g316-local-contact',contactName:'G316 local supplier',
39
+ isPreInvoice:false,items:[{productId:null,productName:'Synthetic service',qty:1,
40
+ price:100,lineSubtotal:100,lineTotal:100,discount:0}],
41
+ subtotal:100,totalDiscount:0,vatAmount:0,grandTotal:100,paidAmount:0,
42
+ paymentMethod:'cash',status:'unpaid',remaining:100};
43
+ const before={invoices:(await db.getAll('invoices')).length,
44
+ journals:(await db.getAll('journal_entries')).length,
45
+ receipts:(await db.getAll('settings')).filter(x=>String(x.id).startsWith('issuance_receipt_')).length};
46
+ await assert.rejects(retail.issueInvoice(attempt),/company|شرکت|مجاز|دسترسی|تعلق/i);
47
+ assert.equal(await db.get('invoices',attempt.id),undefined);
48
+ assert.deepEqual({invoices:(await db.getAll('invoices')).length,
49
+ journals:(await db.getAll('journal_entries')).length,
50
+ receipts:(await db.getAll('settings')).filter(x=>String(x.id).startsWith('issuance_receipt_')).length},before);
51
+});
52
+
53
test('G316: treasury posting rejects foreign-company invoice, contact and bank account without writes',async()=>{
54
await setup();
55
const before={