Bug #11773
openEnsure Unconditional Immediate Database Invoice Balance Sync on Quotation Update
0%
Description
In
syncInvoiceDepositFromQuotation
, database synchronization of invoice.remainingBalance is guarded by shouldSyncDeposit:
javascript
const shouldSyncDeposit =
Object.prototype.hasOwnProperty.call(updates, "actualTotal") ||
Object.prototype.hasOwnProperty.call(updates, "actualSubTotal");
If an update modifies financial totals (e.g. updating costBreakdowns or discountAmount) without passing top-level actualTotal, the Invoice document in MongoDB preserves its old remainingBalance until a user views the invoice (at which point getInvoiceDetailsByQuotationNumber calculates it dynamically at runtime).
If an automated script reads the raw Invoice model from MongoDB without calling getInvoiceDetailsByQuotationNumber, it reads the un-synchronized balance.
2. Acceptance Criteria
AC 5.1 (Direct Balance Recalculation): Given an active quotation with an existing linked invoice, When updateQuotation modifies any field affecting the final cost (costBreakdowns, discount, discountAmount, taxAmount, excludeTax), Then syncInvoiceDepositFromQuotation MUST re-evaluate newTotalAmount and immediately persist the updated remainingBalance to the MongoDB Invoice collection.
AC 5.2 (Paid Installment Preservation): The updated remainingBalance in the database MUST strictly equal Math.max(0, newTotalAmount - sumOfPaidInstallments).
AC 5.3 (Audit Trail): When remainingBalance changes in the invoice document due to a quote update, log an entry into the invoice's actionHistory indicating automatic sync from quote revision.
Subtasks
Related issues
No data to display