Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[12.0][FIX] account_financial_report: Support Postgres v14+ #1056

Merged
merged 1 commit into from
Aug 24, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading