2222 'transaction_type' : fields .String (required = True , description = 'Transaction Type' ),
2323 'external_id' : fields .String (description = 'External ID' ),
2424 'external_date' : fields .DateTime (description = 'External Date' ),
25+ 'merchant' : fields .String (description = 'Merchant Name' ),
26+ 'original_statement' : fields .String (description = 'Original Statement' ),
27+ 'notes' : fields .String (description = 'Notes' ),
28+ 'tags' : fields .String (description = 'Tags' ),
2529 'description' : fields .String (description = 'Description' )
2630})
2731
@@ -37,6 +41,10 @@ def post(self):
3741 transaction_type = data .get ('transaction_type' )
3842 external_id = data .get ('external_id' )
3943 external_date = data .get ('external_date' )
44+ merchant = data .get ('merchant' )
45+ original_statement = data .get ('original_statement' )
46+ notes = data .get ('notes' )
47+ tags = data .get ('tags' )
4048 description = data .get ('description' )
4149
4250 # Validate required fields
@@ -61,6 +69,10 @@ def post(self):
6169 transaction_type = transaction_type ,
6270 external_id = external_id ,
6371 external_date = external_date ,
72+ merchant = merchant ,
73+ original_statement = original_statement ,
74+ notes = notes ,
75+ tags = tags ,
6476 description = description
6577 )
6678 new_transaction .save ()
@@ -210,20 +222,11 @@ def post(self):
210222 error_count += 1
211223 continue
212224
213- # Build description from available fields
214- description_parts = []
215- if merchant :
216- description_parts .append (f"Merchant: { merchant } " )
217- if original_statement :
218- description_parts .append (f"Statement: { original_statement } " )
219- if notes :
220- description_parts .append (f"Notes: { notes } " )
221- if tags :
222- description_parts .append (f"Tags: { tags } " )
225+ # Store fields separately (no joining)
226+ # Description can be used for additional custom info if needed
227+ description = None # Keep empty unless specifically provided
223228
224- description = " | " .join (description_parts ) if description_parts else merchant
225-
226- # Create transaction
229+ # Create transaction with all fields separate
227230 self .create_transaction (
228231 user_id = user_id ,
229232 categories_id = category_id ,
@@ -232,6 +235,10 @@ def post(self):
232235 transaction_type = _transaction_type ,
233236 external_id = external_id ,
234237 external_date = formatted_timestamp ,
238+ merchant = merchant ,
239+ original_statement = original_statement ,
240+ notes = notes ,
241+ tags = tags ,
235242 description = description
236243 )
237244 created_count += 1
@@ -251,8 +258,24 @@ def post(self):
251258 'errors' : error_count
252259 }
253260
254- if errors and len (errors ) <= 10 : # Only include first 10 errors
255- response_data ['error_details' ] = errors [:10 ]
261+ if errors :
262+ # Show first 50 errors to understand patterns
263+ response_data ['error_details' ] = errors [:50 ]
264+ # Also include a summary of error types
265+ error_summary = {}
266+ for error in errors :
267+ # Extract error type
268+ if "Category" in error and "not found" in error :
269+ error_summary ['category_not_found' ] = error_summary .get ('category_not_found' , 0 ) + 1
270+ elif "Could not create account" in error :
271+ error_summary ['account_creation_failed' ] = error_summary .get ('account_creation_failed' , 0 ) + 1
272+ elif "Could not parse" in error :
273+ error_summary ['date_parse_error' ] = error_summary .get ('date_parse_error' , 0 ) + 1
274+ elif "Invalid amount" in error :
275+ error_summary ['invalid_amount' ] = error_summary .get ('invalid_amount' , 0 ) + 1
276+ else :
277+ error_summary ['other' ] = error_summary .get ('other' , 0 ) + 1
278+ response_data ['error_summary' ] = error_summary
256279
257280 return make_response (jsonify (response_data ), 201 if created_count > 0 else 200 )
258281
@@ -347,7 +370,7 @@ def ensure_account_exists_smart(self, account_name, merchant_name):
347370
348371 return account .id
349372
350- def create_transaction (self ,user_id , categories_id , account_id , amount , transaction_type , external_id , external_date , description ):
373+ def create_transaction (self ,user_id , categories_id , account_id , amount , transaction_type , external_id , external_date , merchant = None , original_statement = None , notes = None , tags = None , description = None ):
351374 print (f"Creating transaction { external_id } ..." )
352375 transaction = TransactionModel (
353376 user_id = user_id ,
@@ -357,6 +380,10 @@ def create_transaction(self,user_id, categories_id, account_id, amount, transact
357380 transaction_type = transaction_type ,
358381 external_id = external_id ,
359382 external_date = external_date ,
383+ merchant = merchant ,
384+ original_statement = original_statement ,
385+ notes = notes ,
386+ tags = tags ,
360387 description = description
361388 )
362389 db .session .add (transaction )
@@ -408,6 +435,14 @@ def put(self, id):
408435 }), 400 )
409436
410437 # Update fields if provided
438+ if 'merchant' in data :
439+ transaction .merchant = data ['merchant' ]
440+ if 'original_statement' in data :
441+ transaction .original_statement = data ['original_statement' ]
442+ if 'notes' in data :
443+ transaction .notes = data ['notes' ]
444+ if 'tags' in data :
445+ transaction .tags = data ['tags' ]
411446 if 'description' in data :
412447 transaction .description = data ['description' ]
413448 if 'amount' in data :
0 commit comments