From 8e1bbf526e631eb067a783da17f4f219e6573a2f Mon Sep 17 00:00:00 2001 From: Pierre-Yves Dufays Date: Fri, 15 Sep 2023 13:16:50 +0200 Subject: [PATCH] [FIX] mail: fix activity view pager This solves the following problem: - Add 150 records with 2 activities each (ex. A call and a to do) - Go to the activity view (ex.: event through the systray) and clear filter - Only 50 of the 150 records are displayed (instead of 100) - Going to the next page, only 2 are displayed (instead of ~50) (will depends on the data already present) Technical notes: Not all activities were displayed because the search limit was applied on the activity search instead of searching all activity related to the records. The method fetchActivityData was doing half of the job because it was not assigning the activity data fetch on the server to the instance variable activityData, which was causing strange behavior when clicking on next page. To simplify and correct the code, that logic has been moved to that method instead of relying on the caller to do that assignation. Task-3508744 closes odoo/odoo#135651 Signed-off-by: Thibault Delavallee (tde) --- addons/mail/models/mail_activity.py | 6 +++--- .../static/src/views/web/activity/activity_controller.js | 3 +-- .../mail/static/src/views/web/activity/activity_model.js | 9 +++------ 3 files changed, 7 insertions(+), 11 deletions(-) diff --git a/addons/mail/models/mail_activity.py b/addons/mail/models/mail_activity.py index 00d275f645c..352c35a8cc9 100644 --- a/addons/mail/models/mail_activity.py +++ b/addons/mail/models/mail_activity.py @@ -581,13 +581,13 @@ class MailActivity(models.Model): @api.model def get_activity_data(self, res_model, domain, limit=None, offset=0): activity_domain = [('res_model', '=', res_model)] - if domain: - res = self.env[res_model].search(domain) + if domain or limit or offset: + res = self.env[res_model].search(domain or [], limit=limit, offset=offset) activity_domain.append(('res_id', 'in', res.ids)) grouped_activities = self.env['mail.activity']._read_group( activity_domain, ['res_id', 'activity_type_id'], - ['id:array_agg', 'date_deadline:min', '__count'], limit=limit, offset=offset) + ['id:array_agg', 'date_deadline:min', '__count']) # filter out unreadable records if not domain: res_ids = tuple(res_id for res_id, *_ in grouped_activities) diff --git a/addons/mail/static/src/views/web/activity/activity_controller.js b/addons/mail/static/src/views/web/activity/activity_controller.js index b3516bb9b9d..129f214e7d6 100644 --- a/addons/mail/static/src/views/web/activity/activity_controller.js +++ b/addons/mail/static/src/views/web/activity/activity_controller.js @@ -47,8 +47,7 @@ export class ActivityController extends Component { limit: limit, total: count, onUpdate: async (params) => { - await this.model.root.load(params); - this.model.fetchActivityData(params); + await Promise.all([this.model.root.load(params), this.model.fetchActivityData(params)]); }, updateTotal: hasLimitedCount ? () => this.model.root.fetchCount() : undefined, }; diff --git a/addons/mail/static/src/views/web/activity/activity_model.js b/addons/mail/static/src/views/web/activity/activity_model.js index bf4268fd7dd..306d411ae25 100644 --- a/addons/mail/static/src/views/web/activity/activity_model.js +++ b/addons/mail/static/src/views/web/activity/activity_model.js @@ -11,14 +11,11 @@ export class ActivityModel extends RelationalModel { if (params && "groupBy" in params) { params.groupBy = []; } - const prom = this.fetchActivityData(params).then((data) => { - this.activityData = data; - }); - await Promise.all([prom, super.load(params)]); + await Promise.all([this.fetchActivityData(params), super.load(params)]); } - fetchActivityData(params) { - return this.orm.call("mail.activity", "get_activity_data", [], { + async fetchActivityData(params) { + this.activityData = await this.orm.call("mail.activity", "get_activity_data", [], { res_model: this.config.resModel, domain: params.domain || this.env.searchModel._domain, limit: params.limit || this.initialLimit,