[REF] mail: update related_attachment_count field name to match mixin namespace.
Reason: The Attachment count of mail_thread is used by the new attachment button of the chatter, the compute field has been chosen over a search_count JS RPC to keep a synchronous chatter and prevent flickering. This commit refactors those changes to follow the naming conventions of mail_thread and to optimize the count method for eventual reuse follwing TDE's advices. - Changed the name of a mail_thread's related_attachment_count into message_attachment_count. - Changed the count method to a read_group. PR: 26989 Task: 1860031
This commit is contained in:
@@ -110,7 +110,7 @@ class MailThread(models.AbstractModel):
|
||||
message_has_error_counter = fields.Integer(
|
||||
'Number of error', compute='_compute_message_has_error',
|
||||
help="Number of messages with delivery error")
|
||||
related_attachment_count = fields.Integer('Attachment Count', compute='_compute_related_attachment_count')
|
||||
message_attachment_count = fields.Integer('Attachment Count', compute='_compute_message_attachment_count')
|
||||
message_main_attachment_id = fields.Many2one(string="Main Attachment", comodel_name='ir.attachment')
|
||||
|
||||
@api.one
|
||||
@@ -147,12 +147,6 @@ class MailThread(models.AbstractModel):
|
||||
# using read() below is much faster than followers.mapped('res_id')
|
||||
return [('id', 'in', [res['res_id'] for res in followers.read(['res_id'])])]
|
||||
|
||||
@api.multi
|
||||
def _compute_related_attachment_count(self):
|
||||
for record in self:
|
||||
domain = [('res_id', '=', record.id), ('res_model', '=', self._name)]
|
||||
record.related_attachment_count = self.env['ir.attachment'].search_count(domain)
|
||||
|
||||
@api.multi
|
||||
@api.depends('message_follower_ids')
|
||||
def _compute_is_follower(self):
|
||||
@@ -244,6 +238,16 @@ class MailThread(models.AbstractModel):
|
||||
def _search_message_has_error(self, operator, operand):
|
||||
return [('message_ids.has_error', operator, operand)]
|
||||
|
||||
@api.multi
|
||||
def _compute_message_attachment_count(self):
|
||||
read_group_var = self.env['ir.attachment'].read_group([('res_model', '=', self._name)],
|
||||
fields=['res_id'],
|
||||
groupby=['res_id'])
|
||||
|
||||
attachment_count_dict = dict((d['res_id'], d['res_id_count']) for d in read_group_var)
|
||||
for record in self:
|
||||
record.message_attachment_count = attachment_count_dict.get(record.id, 0)
|
||||
|
||||
# ------------------------------------------------------
|
||||
# CRUD overrides for automatic subscription and logging
|
||||
# ------------------------------------------------------
|
||||
|
||||
@@ -79,7 +79,7 @@ var Chatter = Widget.extend({
|
||||
start: function () {
|
||||
this._$topbar = this.$('.o_chatter_topbar');
|
||||
this.$('.o_topbar_right_area').append(QWeb.render('mail.chatter.Attachment.Button', {
|
||||
count: this.record.data.related_attachment_count || 0,
|
||||
count: this.record.data.message_attachment_count || 0,
|
||||
}));
|
||||
// render and append the buttons
|
||||
this._$topbar.prepend(QWeb.render('mail.chatter.Buttons', {
|
||||
@@ -270,7 +270,7 @@ var Chatter = Widget.extend({
|
||||
if (self._reloadAfterPost(messageData)) {
|
||||
self.trigger_up('reload');
|
||||
} else if (messageData.attachment_ids.length) {
|
||||
self.trigger_up('reload', {fieldNames: ['related_attachment_count']});
|
||||
self.trigger_up('reload', {fieldNames: ['message_attachment_count']});
|
||||
}
|
||||
});
|
||||
});
|
||||
@@ -364,7 +364,7 @@ var Chatter = Widget.extend({
|
||||
* @private
|
||||
*/
|
||||
_updateAttachmentCounter: function () {
|
||||
var count = this.record.data.related_attachment_count || 0;
|
||||
var count = this.record.data.message_attachment_count || 0;
|
||||
this.$('.o_chatter_attachment_button_count').html(' ('+ count +')');
|
||||
this.$('.o_chatter_button_attachment').toggleClass('o_hidden', !count);
|
||||
},
|
||||
|
||||
@@ -29,7 +29,7 @@ FormRenderer.include({
|
||||
*/
|
||||
confirmChange: function (state, id, fields) {
|
||||
if (this.chatter) {
|
||||
var chatterFields = ['related_attachment_count'].concat(_.values(this.mailFields));
|
||||
var chatterFields = ['message_attachment_count'].concat(_.values(this.mailFields));
|
||||
var updatedMailFields = _.intersection(fields, chatterFields);
|
||||
if (updatedMailFields.length) {
|
||||
this.chatter.update(state, updatedMailFields);
|
||||
|
||||
@@ -4,7 +4,7 @@ odoo.define('mail.FormView', function (require) {
|
||||
var FormView = require('web.FormView');
|
||||
|
||||
/**
|
||||
* This file is used to add "related_attachment_count" to fieldsInfo so we can fetch its value for the
|
||||
* This file is used to add "message_attachment_count" to fieldsInfo so we can fetch its value for the
|
||||
* chatter's attachment button without having it explicitly declared in the form view template.
|
||||
*
|
||||
*/
|
||||
@@ -17,7 +17,7 @@ FormView.include({
|
||||
this._super.apply(this, arguments);
|
||||
|
||||
if ('message_ids' in this.fieldsInfo[this.viewType]) {
|
||||
this.fieldsInfo[this.viewType].related_attachment_count = {};
|
||||
this.fieldsInfo[this.viewType].message_attachment_count = {};
|
||||
}
|
||||
},
|
||||
});
|
||||
|
||||
@@ -55,14 +55,14 @@ QUnit.module('Chatter', {
|
||||
type: 'selection',
|
||||
selection: [['overdue', 'Overdue'], ['today', 'Today'], ['planned', 'Planned']],
|
||||
},
|
||||
related_attachment_count: {
|
||||
message_attachment_count: {
|
||||
string: 'Attachment count',
|
||||
type: 'integer',
|
||||
},
|
||||
},
|
||||
records: [{
|
||||
id: 2,
|
||||
related_attachment_count: 3,
|
||||
message_attachment_count: 3,
|
||||
display_name: "first partner",
|
||||
foo: "HELLO",
|
||||
message_follower_ids: [],
|
||||
|
||||
Reference in New Issue
Block a user