From bac088a50a8bf2b32f5589220e039cb5012dbad2 Mon Sep 17 00:00:00 2001 From: x620 Date: Mon, 28 Mar 2016 11:05:16 +0500 Subject: [PATCH] Init commit: worked 8.0 version, which will be changed to 9.0. Changed __openerp__.py and README.rst only. --- res_partner_mails_count/README.rst | 16 +++++++ res_partner_mails_count/__init__.py | 2 + res_partner_mails_count/__openerp__.py | 33 +++++++++++++ res_partner_mails_count/models.py | 19 ++++++++ res_partner_mails_count/static/src/js/main.js | 10 ++++ res_partner_mails_count/templates.xml | 48 +++++++++++++++++++ res_partner_mails_count/tests/__init__.py | 3 ++ res_partner_mails_count/tests/test_mail.py | 33 +++++++++++++ .../views/res_partner_mails_count.xml | 18 +++++++ 9 files changed, 182 insertions(+) create mode 100644 res_partner_mails_count/README.rst create mode 100644 res_partner_mails_count/__init__.py create mode 100644 res_partner_mails_count/__openerp__.py create mode 100644 res_partner_mails_count/models.py create mode 100644 res_partner_mails_count/static/src/js/main.js create mode 100644 res_partner_mails_count/templates.xml create mode 100644 res_partner_mails_count/tests/__init__.py create mode 100644 res_partner_mails_count/tests/test_mail.py create mode 100644 res_partner_mails_count/views/res_partner_mails_count.xml diff --git a/res_partner_mails_count/README.rst b/res_partner_mails_count/README.rst new file mode 100644 index 0000000..8a14292 --- /dev/null +++ b/res_partner_mails_count/README.rst @@ -0,0 +1,16 @@ +Smart buttons for mails count +============================= + +This module adds Smart buttons with "Mails from" and "Mails to" count of mails in the partner form. + +Usage +----- + +You can see Smart buttons "Mails from" and "Mails to" in the contact form in the Messaging/Contacts menu. If you click on these buttons, you can see list of corresponded mails. Click on the "Send a message" link to send mail to the partner. + +Further information +------------------- + +HTML Description: https://apps.odoo.com/apps/modules/9.0/res_partner_mails_count/ + +Tested on Odoo 9.0 \ No newline at end of file diff --git a/res_partner_mails_count/__init__.py b/res_partner_mails_count/__init__.py new file mode 100644 index 0000000..0f7cb6b --- /dev/null +++ b/res_partner_mails_count/__init__.py @@ -0,0 +1,2 @@ +# -*- coding: utf-8 -*- +import models \ No newline at end of file diff --git a/res_partner_mails_count/__openerp__.py b/res_partner_mails_count/__openerp__.py new file mode 100644 index 0000000..9110da5 --- /dev/null +++ b/res_partner_mails_count/__openerp__.py @@ -0,0 +1,33 @@ +# -*- coding: utf-8 -*- +{ + "name": "Smart buttons for mails count", + + "summary": """ + This module adds Smart buttons with "Mails from" and "Mails to" count of mails in the partner form. + """, + + "description": """ + You can see Smart buttons "Mails from" and "Mails to" in the contact + form in the Messaging/Contacts menu. If you click on these buttons, + you can see list of corresponded mails. Click on the "Send a message" + link to send mail to the partner. + """, + + "author": "IT-Projects LLC, Pavel Romanchenko", + "website": "http://www.it-projects.info", + + # Categories can be used to filter modules in modules listing + # Check https://github.com/odoo/odoo/blob/master/openerp/addons/base/module/module_data.xml + # for the full list + "category": "Uncategorized", + "version": "1.0.0", + + # any module necessary for this one to work correctly + "depends": ["base", "mail"], + + # always loaded + "data": [ + "views/res_partner_mails_count.xml", + "templates.xml", + ], +} diff --git a/res_partner_mails_count/models.py b/res_partner_mails_count/models.py new file mode 100644 index 0000000..0ca91e6 --- /dev/null +++ b/res_partner_mails_count/models.py @@ -0,0 +1,19 @@ +# -*- coding: utf-8 -*- + +from openerp import models, fields, api + + +class res_partner(models.Model): + _inherit = 'res.partner' + mails_to = fields.Integer(compute="_mails_to") + mails_from = fields.Integer(compute="_mails_from") + + @api.one + def _mails_to(self): + for r in self: + r.mails_to = self.env['mail.message'].sudo().search_count([('notified_partner_ids', 'in', r.id)]) + + @api.one + def _mails_from(self): + for r in self: + r.mails_from = self.env['mail.message'].sudo().search_count([('author_id', '=', r.id)]) diff --git a/res_partner_mails_count/static/src/js/main.js b/res_partner_mails_count/static/src/js/main.js new file mode 100644 index 0000000..16c9d56 --- /dev/null +++ b/res_partner_mails_count/static/src/js/main.js @@ -0,0 +1,10 @@ +openerp.res_partner_mails_count = function(instance){ + instance.mail.Wall.include({ + init: function(){ + this._super.apply(this, arguments); + if(this.context.ignore_search_model){ + delete this.defaults.model; + } + } + }); +}; diff --git a/res_partner_mails_count/templates.xml b/res_partner_mails_count/templates.xml new file mode 100644 index 0000000..936ba1c --- /dev/null +++ b/res_partner_mails_count/templates.xml @@ -0,0 +1,48 @@ + + + + + + + mail.message.search.notified_partner + mail.message + 50 + + + + + + + + + + res.partner.mails.count + res.partner + + + + + + + + + + + diff --git a/res_partner_mails_count/tests/__init__.py b/res_partner_mails_count/tests/__init__.py new file mode 100644 index 0000000..300df16 --- /dev/null +++ b/res_partner_mails_count/tests/__init__.py @@ -0,0 +1,3 @@ +# -*- coding: utf-8 -*- + +from . import test_mail diff --git a/res_partner_mails_count/tests/test_mail.py b/res_partner_mails_count/tests/test_mail.py new file mode 100644 index 0000000..f606964 --- /dev/null +++ b/res_partner_mails_count/tests/test_mail.py @@ -0,0 +1,33 @@ +# -*- coding: utf-8 -*- + +from openerp.tests.common import TransactionCase + + +class test_message_count(TransactionCase): + post_install = True + def test_count(self): + new_partner1 = self.env['res.partner'].sudo().create({'name': 'rpmc Test Partner one', 'email': 'tt@tt', 'notify_email': 'always'}) + new_partner2 = self.env['res.partner'].sudo().create({'name': 'rpmc Test Partner two', 'email': 'rr@rr', 'notify_email': 'always'}) + self.assertEqual(new_partner1.mails_to, 0, 'rpmc: new partner have mails_to != 0') + mail_compose = self.env['mail.compose.message'] + compose = mail_compose.with_context( + { + 'default_composition_mode': 'comment', + }).create( + { + 'subject': 'test subj', + 'body': 'test body', + 'partner_ids': [(4, new_partner2.id)], + 'email_from': 'tt@tt', + 'author_id': new_partner1.id + }) + compose.send_mail() + self.assertEqual(new_partner1.mails_to, 0) + self.assertEqual(new_partner1.mails_from, 1, 'rpmc: one message but mails_from != 1') + self.assertEqual(new_partner2.mails_to, 1, 'rpmc: one message but mails_to != 1') + self.assertEqual(new_partner2.mails_from, 0) + compose.send_mail() + self.assertEqual(new_partner1.mails_to, 0) + self.assertEqual(new_partner1.mails_from, 2, 'rpmc: one message but mails_from != 2') + self.assertEqual(new_partner2.mails_to, 2, 'rpmc: one message but mails_to != 2') + self.assertEqual(new_partner2.mails_from, 0) \ No newline at end of file diff --git a/res_partner_mails_count/views/res_partner_mails_count.xml b/res_partner_mails_count/views/res_partner_mails_count.xml new file mode 100644 index 0000000..bd2d7d0 --- /dev/null +++ b/res_partner_mails_count/views/res_partner_mails_count.xml @@ -0,0 +1,18 @@ + + + + + Mails + mail.wall + mail.message + { + 'ignore_search_model': True, + } + +

+ Mails not found. Probably, they exist, but you don't have access. +

+
+
+
+