@@ -91,11 +91,11 @@ export async function scrapeAndImportTransactions({companyId, bank}: ScrapeTrans
9191
9292 const existingReconciliation = allAccountTxns . find ( txn => txn . imported_id === reconciliationImportedId ) ;
9393
94- log ( 'RECONCILIATION' , {
95- from : currentBalance ,
96- to : accountBalance ,
97- diff : balanceDiff ,
98- } ) ;
94+ // If balances are already in sync, no need to create/update reconciliation.
95+ if ( existingReconciliation && balanceDiff === 0 ) {
96+ log ( 'RECONCILIATION_NOT_NEEDED' ) ;
97+ return ;
98+ }
9999
100100 const reconciliationTxn = {
101101 account : bank . actualAccountId ,
@@ -112,21 +112,19 @@ export async function scrapeAndImportTransactions({companyId, bank}: ScrapeTrans
112112 await actual . updateTransaction ( existingReconciliation . id , reconciliationTxn ) ;
113113 stdout . unmute ( ) ;
114114
115- log ( 'RECONCILIATION_UPDATED' , { transactionId : existingReconciliation . id } ) ;
115+ log ( 'RECONCILIATION_UPDATED' , { from : currentBalance , to : accountBalance , diff : balanceDiff } ) ;
116116 return ;
117117 }
118118
119119 // Create the reconciliation transaction for the first time
120- const reconciliationResult = await actual . importTransactions (
121- bank . actualAccountId ,
122- [ reconciliationTxn ] ,
123- ) ;
120+ stdout . mute ( ) ;
121+ const reconciliationResult = await actual . importTransactions ( bank . actualAccountId , [ reconciliationTxn ] ) ;
124122 stdout . unmute ( ) ;
125123
126124 if ( ! reconciliationResult || _ . isEmpty ( reconciliationResult . added ) ) {
127125 console . error ( 'Reconciliation errors' , reconciliationResult ?. errors ) ;
128126 } else {
129- log ( 'RECONCILIATION_ADDED' , { transactions : reconciliationResult . added . length } ) ;
127+ log ( 'RECONCILIATION_ADDED' , { from : currentBalance , to : accountBalance , diff : balanceDiff } ) ;
130128 }
131129 } catch ( error ) {
132130 console . error ( 'Error' , companyId , error ) ;
0 commit comments