From 55f87195854f04b943fb52a659f9ca7d54d30d20 Mon Sep 17 00:00:00 2001 From: Ivan Yelizariev Date: Mon, 2 Jan 2017 13:04:49 +0500 Subject: [PATCH] [PORT] res_partner_company_messages ported to 9.0 --- res_partner_company_messages/README.rst | 2 +- res_partner_company_messages/models.py | 23 ++++++++++++----------- 2 files changed, 13 insertions(+), 12 deletions(-) diff --git a/res_partner_company_messages/README.rst b/res_partner_company_messages/README.rst index b287290..f9f424d 100644 --- a/res_partner_company_messages/README.rst +++ b/res_partner_company_messages/README.rst @@ -3,4 +3,4 @@ Aggregate messages from company's contacts By default, odoo displays under partner form only its own messages. The module shows under company form both their own messages and the messages of any contacts attached to that company. -Tested on Odoo 8.0 ea60fed97af1c139e4647890bf8f68224ea1665b +Tested on Odoo 9.0 c8cd67c5d98b410cabe0a6efb3347a8a4de731d8 diff --git a/res_partner_company_messages/models.py b/res_partner_company_messages/models.py index 7d4f92d..f1d906a 100644 --- a/res_partner_company_messages/models.py +++ b/res_partner_company_messages/models.py @@ -3,16 +3,17 @@ from openerp import api from openerp import models -class MailMessage(models.Model): - _inherit = 'mail.message' +class Partner(models.Model): + _inherit = 'res.partner' - @api.cr_uid_context - def message_read(self, cr, uid, ids=None, domain=None, message_unload_ids=None, - thread_level=0, context=None, parent_id=False, limit=None): - if context and context.get('default_model') == 'res.partner': - partner = self.pool['res.partner'].browse(cr, uid, context.get('default_res_id')) - domain_by_id = domain and len(domain) == 1 and domain[0][0] == 'id' and domain[0][1] == '=' - if partner.is_company and not domain_by_id: - ids = None + @api.multi + def read(self, fields=None, load='_classic_read'): + res = super(Partner, self).read(fields=fields, load=load) + if fields and 'message_ids' in fields: + for vals in res: + partner = self.browse(vals['id']) + if not partner.is_company: + continue domain = [('model', '=', 'res.partner'), ('res_id', 'in', [partner.id] + partner.child_ids.ids)] - return super(MailMessage, self).message_read(cr, uid, ids, domain, message_unload_ids, thread_level, context, parent_id, limit) + vals['message_ids'] = self.env['mail.message'].search(domain).ids + return res