Description

This function converts an OFX file to a QBO format by making specific adjustments to the file content. It removes unnecessary elements, modifies transaction types, and ensures the output is suitable for QuickBooks imports.

⚠️ Note: This function is still under testing and may require adjustments for specific use cases.


Main Features

  1. Reads an OFX file and processes its content.
  2. Removes [0:UTC] from all lines.
  3. Converts <TRNTYPE>PAYMENT to <TRNTYPE>DEBIT.
  4. Skips lines containing <CORRECTFITID> or <CORRECTACTION>.
  5. Outputs a QBO file with the modified content.

Requirements


Code for the Function

python
Copy code
def converter_ofx_para_qbo(ofx_file, qbo_file):
    """
    Converts an OFX file to QBO format by modifying the content as per QuickBooks requirements.

    Args:
        ofx_file (str): Path to the input OFX file.
        qbo_file (str): Path to the output QBO file.
    """
    # Open the OFX file for reading
    with open(ofx_file, 'r') as ofx_input:
        # Read all lines from the OFX file
        ofx_lines = ofx_input.readlines()

    # Create a list to store modified OFX lines
    modified_ofx_lines = []

    # Process each line in the OFX file
    for line in ofx_lines:
        # Remove [0:UTC]
        line = line.replace('[0:UTC]', '')

        # Replace <TRNTYPE>PAYMENT with <TRNTYPE>DEBIT
        line = line.replace('<TRNTYPE>PAYMENT', '<TRNTYPE>DEBIT')

        # Skip lines containing <CORRECTFITID> or <CORRECTACTION>
        if '<CORRECTFITID>' in line or '<CORRECTACTION>' in line:
            continue

        # Add the modified line to the list
        modified_ofx_lines.append(line)

    # Write the modified lines to the QBO file
    with open(qbo_file, 'w') as qbo_output:
        qbo_output.writelines(modified_ofx_lines)

# Example usage:
converter_ofx_para_qbo('example.ofx', 'output.qbo')