From eac4dca6dd33f6e0b2478455c06cd7249dc178dc Mon Sep 17 00:00:00 2001 From: mth-odoo Date: Mon, 13 Mar 2023 13:16:27 +0000 Subject: [PATCH] [FIX] account: updated the alias for an ambiguous column MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Before this commit ------------------ Before this commit, the db migration from the 15.0 to 16.0 test case is failing while this is migrating analytic_account, in computing methods trying to use a direct field without reference. Traceback (most recent call last): File "/tmp/tmpmjg7gno3/migrations/base/tests/test_mock_crawl.py", line 223, in crawl_menu self.mock_action(action_vals) File "/tmp/tmpmjg7gno3/migrations/base/tests/test_mock_crawl.py", line 377, in mock_action mock_method(model, view, fields_list, domain, group_by) File "/tmp/tmpmjg7gno3/migrations/base/tests/test_mock_crawl.py", line 405, in mock_view_form [data] = record.read(fields_list) File "/home/odoo/src/odoo/16.0/odoo/models.py", line 2977, in read return self._read_format(fnames=fields, load=load) File "/home/odoo/src/odoo/16.0/odoo/models.py", line 3126, in _read_format vals[name] = convert(record[name], record, use_name_get) File "/home/odoo/src/odoo/16.0/odoo/models.py", line 5847, in __getitem__ return self._fields[key].__get__(self, type(self)) File "/home/odoo/src/odoo/16.0/odoo/fields.py", line 1188, in __get__ self.compute_value(recs) File "/home/odoo/src/odoo/16.0/odoo/fields.py", line 1347, in compute_value records._compute_field_value(self) File "/home/odoo/src/odoo/16.0/addons/mail/models/mail_thread.py", line 403, in _compute_field_value return super()._compute_field_value(field) File "/home/odoo/src/odoo/16.0/odoo/models.py", line 4186, in _compute_field_value getattr(self, field.compute)() File "/home/odoo/src/odoo/16.0/addons/account/models/account_analytic_account.py", line 38, in _compute_invoice_count self._cr.execute(query_string, query_param) File "/home/odoo/src/odoo/16.0/odoo/sql_db.py", line 516, in execute return self._cursor.execute(*args, **kwargs) File "/home/odoo/src/odoo/16.0/odoo/sql_db.py", line 313, in execute res = self._obj.execute(query, params) psycopg2.errors.AmbiguousColumn: column reference "move_id" is ambiguous LINE 1: ...lytic_distribution) as account_id, COUNT(DISTINCT(move_id)) ... After this commit ----------------- In this commit added the reference to the move_id which is used without reference. closes odoo/odoo#115160 Taskid: 3141476 X-original-commit: 6ae96c7f707cdd2beac241280957bd3b3661b94d Signed-off-by: William André (wan) --- addons/account/models/account_analytic_account.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/addons/account/models/account_analytic_account.py b/addons/account/models/account_analytic_account.py index ce0ce56b8ec..07696765cca 100644 --- a/addons/account/models/account_analytic_account.py +++ b/addons/account/models/account_analytic_account.py @@ -30,7 +30,7 @@ class AccountAnalyticAccount(models.Model): query_string, query_param = query.select( 'jsonb_object_keys(account_move_line.analytic_distribution) as account_id', - 'COUNT(DISTINCT(move_id)) as move_count', + 'COUNT(DISTINCT(account_move_line.move_id)) as move_count', ) query_string = f"{query_string} GROUP BY jsonb_object_keys(account_move_line.analytic_distribution)" @@ -54,7 +54,7 @@ class AccountAnalyticAccount(models.Model): query_string, query_param = query.select( 'jsonb_object_keys(account_move_line.analytic_distribution) as account_id', - 'COUNT(DISTINCT(move_id)) as move_count', + 'COUNT(DISTINCT(account_move_line.move_id)) as move_count', ) query_string = f"{query_string} GROUP BY jsonb_object_keys(account_move_line.analytic_distribution)" @@ -67,7 +67,7 @@ class AccountAnalyticAccount(models.Model): self.ensure_one() query = self.env['account.move.line']._search([('move_id.move_type', 'in', self.env['account.move'].get_sale_types())]) query.add_where('analytic_distribution ? %s', [str(self.id)]) - query_string, query_param = query.select('DISTINCT move_id') + query_string, query_param = query.select('DISTINCT account_move_line.move_id') self._cr.execute(query_string, query_param) move_ids = [line.get('move_id') for line in self._cr.dictfetchall()] result = { @@ -84,7 +84,7 @@ class AccountAnalyticAccount(models.Model): self.ensure_one() query = self.env['account.move.line']._search([('move_id.move_type', 'in', self.env['account.move'].get_purchase_types())]) query.add_where('analytic_distribution ? %s', [str(self.id)]) - query_string, query_param = query.select('DISTINCT move_id') + query_string, query_param = query.select('DISTINCT account_move_line.move_id') self._cr.execute(query_string, query_param) move_ids = [line.get('move_id') for line in self._cr.dictfetchall()] result = {