Skip to content

Commit

Permalink
[FIX] account_financial_report: Support Postgres v14+
Browse files Browse the repository at this point in the history
Postgres 14+ expects the argument anycompatiblearray instead of anyarray
to array_cat. We detect the Postgres version and proceed with the
correct type.

Signed-off-by: Carmen Bianca BAKKER <[email protected]>
  • Loading branch information
carmenbianca committed Jul 31, 2023
1 parent 21fe559 commit 0b30aa7
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions account_financial_report/report/trial_balance.py
Original file line number Diff line number Diff line change
Expand Up @@ -482,11 +482,19 @@ def _update_account_group_child_values(self):

def _add_account_group_account_values(self):
"""Compute values for report_trial_balance_account group in child."""
# Since Postgres 14, the argument to array_cat must be
# anycompatiblearray instead of anyarray. See
# <https://www.postgresql.org/docs/14/release-14.html#id-1.11.6.13.4>.
# We detect the version and use the correct type as needed.
array_type = (
"anycompatiblearray" if self.env.cr.connection.server_version >= 140000
else "anyarray"
)
query_update_account_group = """
DROP AGGREGATE IF EXISTS array_concat_agg(anyarray);
CREATE AGGREGATE array_concat_agg(anyarray) (
DROP AGGREGATE IF EXISTS array_concat_agg({array_type});
CREATE AGGREGATE array_concat_agg({array_type}) (
SFUNC = array_cat,
STYPE = anyarray
STYPE = {array_type}
);
WITH aggr AS(WITH computed AS (WITH RECURSIVE cte AS (
SELECT account_group_id, account_group_id AS parent_id,
Expand Down Expand Up @@ -516,7 +524,7 @@ def _add_account_group_account_values(self):
FROM aggr
WHERE report_trial_balance_account.account_group_id = aggr.account_group_id
AND report_trial_balance_account.report_id = %s
"""
""".format(array_type=array_type)
query_update_account_params = (self.id, self.id, self.id,)
self.env.cr.execute(query_update_account_group,
query_update_account_params)
Expand Down

0 comments on commit 0b30aa7

Please sign in to comment.