'Compute the sum of ending balances for all accounts that are of a type that does not bring forward the balance in new fiscal years.
This is needed because we have to display only one line for the initial balance of all expense/revenue accounts in the FEC.'

def do_query_unaffected_earnings(self):

    sql_query = "\n                                SELECT\n                                                'OUV'    AS    JournalCode,\n                                                'Balance    initiale'    AS    JournalLib,\n                                                'Balance    initiale    PL'    AS    EcritureNum,\n                                                %s    AS    EcritureDate,\n                                                '120/129'    AS    CompteNum,\n                                                'Benefice    (perte)    reporte(e)'    AS    CompteLib,\n                                                ''    AS    CompAuxNum,\n                                                ''    AS    CompAuxLib,\n                                                '-'    AS    PieceRef,\n                                                %s    AS    PieceDate,\n                                                '/'    AS    EcritureLib,\n                                                replace(CASE    WHEN    COALESCE(sum(aml.balance),    0)    <=    0    THEN    '0,00'    ELSE    to_char(SUM(aml.balance),    '999999999999999D99')    END,    '.',    ',')    AS    Debit,\n                                                replace(CASE    WHEN    COALESCE(sum(aml.balance),    0)    >=    0    THEN    '0,00'    ELSE    to_char(-SUM(aml.balance),    '999999999999999D99')    END,    '.',    ',')    AS    Credit,\n                                                ''    AS    EcritureLet,\n                                                ''    AS    DateLet,\n                                                %s    AS    ValidDate,\n                                                ''    AS    Montantdevise,\n                                                ''    AS    Idevise\n                                FROM\n                                                account_move_line    aml\n                                                LEFT    JOIN    account_move    am    ON    am.id=aml.move_id\n                                                JOIN    account_account    aa    ON    aa.id    =    aml.account_id\n                                                LEFT    JOIN    account_account_type    aat    ON    aa.user_type_id    =    aat.id\n                                WHERE\n                                                am.date    <    %s\n                                                AND    am.company_id    =    %s\n                                                AND    aat.include_initial_balance    =    'f'\n                                                AND    (aml.debit    !=    0    OR    aml.credit    !=    0)\n                                "
    if (self.export_type == 'official'):
        sql_query += "\n                                                AND    am.state    =    'posted'\n                                                "
    company = self.env.user.company_id
    formatted_date_from = self.date_from.replace('-', '')
    self._cr.execute(sql_query, (formatted_date_from, formatted_date_from, formatted_date_from, self.date_from, company.id))
    listrow = []
    row = self._cr.fetchone()
    listrow = list(row)
    return listrow
