diff --git a/processors/data_mapper.py b/processors/data_mapper.py index 3ebbf49..1ef46b1 100644 --- a/processors/data_mapper.py +++ b/processors/data_mapper.py @@ -61,6 +61,54 @@ class DataMapper: logger.error(f"Error calculating TXNIND for amount '{amount_str}': {e}") return 'CR' # Default to credit + @staticmethod + def process_status(status: str) -> str: + """ + Process status field. + If status contains 'processed' (case-insensitive), return 'Processed'. + Otherwise return the original status. + + Args: + status: Original status text + + Returns: + 'Processed' if status contains 'processed', else original status + """ + try: + if not status: + return '' + + # Check if 'processed' is in status (case-insensitive) + if 'processed' in status.lower(): + return 'Processed' + + # Otherwise return original status + return status + except Exception as e: + logger.error(f"Error processing status: {e}") + return status + + @staticmethod + def pad_account_number(account_number: str) -> str: + """ + Pad account number with leading zeroes to make it 17 digits. + + Args: + account_number: Account number string + + Returns: + Account number padded to 17 digits with leading zeroes + """ + try: + if not account_number: + return '0' * 17 + # Remove any existing spaces and pad to 17 digits + clean_account = account_number.strip() + return clean_account.zfill(17) + except Exception as e: + logger.error(f"Error padding account number '{account_number}': {e}") + return '0' * 17 + @staticmethod def convert_amount(amount_str: str) -> Decimal: """ @@ -103,13 +151,19 @@ class DataMapper: txnind = cls.calculate_txnind(amount_str) tran_date = cls.convert_date(parsed_transaction.get('date', '')) + # Pad account number to 17 digits + padded_account = cls.pad_account_number(parsed_transaction.get('cust_acct', '')) + + # Process status (check for 'processed' keyword) + status = cls.process_status(parsed_transaction.get('sys', '')) + record = TransactionRecord( - narration=parsed_transaction.get('remarks', '')[:500], # Limit to 500 chars - status=parsed_transaction.get('sys', ''), + narration=parsed_transaction.get('remarks', '')[:500], # Keep original remarks + status=status, # 'Processed' if status contains 'processed', else original bankcode=bankcode, jrnl_id=parsed_transaction.get('jrnl_no', ''), tran_date=tran_date, - cbs_acct=parsed_transaction.get('cust_acct', ''), + cbs_acct=padded_account, # Padded to 17 digits tran_amt=amount, txnind=txnind, )