hi am working on odoo 11 accounting and am trying to devlop consolidate trial balance in multi company this is my sql code that show my trial balance with all account
query_inject_account = """
INSERT INTO
l10n_ro_report_trial_balance_account
(
report_id,
create_uid,
create_date,
account_id,
code,
name,
debit_opening,
credit_opening,
debit_initial,
credit_initial,
debit,
credit,
debit_total,
credit_total,
debit_balance,
credit_balance)
SELECT
%s AS report_id,
%s AS create_uid,
NOW() AS create_date,
accounts.*,
CASE WHEN accounts.debit_total > accounts.credit_total
THEN accounts.debit_total - accounts.credit_total
ELSE 0
END AS debit_balance,
CASE WHEN accounts.credit_total > accounts.debit_total
THEN accounts.credit_total - accounts.debit_total
ELSE 0
END AS credit_balance,
SUM(accounts.debit_total) as total1,
SUM(accounts.credit_total) as total2
FROM
(
SELECT
acc.id, acc.code, acc.name,
coalesce(sum(open.debit),0) AS debit_opening,
coalesce(sum(open.credit),0) AS credit_opening,
coalesce(sum(init.debit),0) AS debit_initial,
coalesce(sum(init.credit),0) AS credit_initial,
coalesce(sum(current.debit),0) AS debit,
coalesce(sum(current.credit),0) AS credit,
coalesce(sum(open.debit),0) + coalesce(sum(init.debit),0) +
coalesce(sum(current.debit),0) AS debit_total,
coalesce(sum(open.credit),0) + coalesce(sum(init.credit),0) +
coalesce(sum(current.credit),0) AS credit_total
FROM
account_account acc
LEFT OUTER JOIN account_move_line AS open
ON open.account_id = acc.id AND open.date < %s
LEFT OUTER JOIN account_move_line AS init
ON init.account_id = acc.id AND init.date >= %s AND init.date < %s
LEFT OUTER JOIN account_move_line AS current
ON current.account_id = acc.id AND current.date >= %s
AND current.date <= %s
LEFT JOIN account_move AS move
ON open.move_id = move.id AND move.state in (%s)
LEFT JOIN account_move AS init_move
ON init.move_id = init_move.id AND init_move.state in (%s)
LEFT JOIN account_move AS current_move
ON current.move_id = current_move.id AND current_move.state in (%s)
WHERE acc.id in %s
GROUP BY acc.id,acc.code,accounts.*
ORDER BY acc.id) as accounts"""
this code make me to sum debit, credit of account and i want to sum the total of each result
and i got this error can anyone help me, please