diff --git a/res_partner_mails_count/__init__.py b/res_partner_mails_count/__init__.py new file mode 100644 index 0000000..c7a6ca6 --- /dev/null +++ b/res_partner_mails_count/__init__.py @@ -0,0 +1,3 @@ +# -*- coding: utf-8 -*- +import controllers +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..250b763 --- /dev/null +++ b/res_partner_mails_count/__openerp__.py @@ -0,0 +1,34 @@ +# -*- coding: utf-8 -*- +{ + 'name': "res_partner_mails_count", + + 'summary': """ + Short (1 phrase/line) summary of the module's purpose, used as + subtitle on modules listing or apps.openerp.com""", + + 'description': """ + Long description of module's purpose + """, + + 'author': "Your Company", + 'website': "http://www.yourcompany.com", + + # 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': '0.1', + + # any module necessary for this one to work correctly + 'depends': ['base'], + + # always loaded + 'data': [ + # 'security/ir.model.access.csv', + 'templates.xml', + ], + # only loaded in demonstration mode + 'demo': [ + 'demo.xml', + ], +} \ No newline at end of file diff --git a/res_partner_mails_count/controllers.py b/res_partner_mails_count/controllers.py new file mode 100644 index 0000000..a1262c1 --- /dev/null +++ b/res_partner_mails_count/controllers.py @@ -0,0 +1,20 @@ +# -*- coding: utf-8 -*- +from openerp import http + +# class ResPartnerMailsCount(http.Controller): +# @http.route('/res_partner_mails_count/res_partner_mails_count/', auth='public') +# def index(self, **kw): +# return "Hello, world" + +# @http.route('/res_partner_mails_count/res_partner_mails_count/objects/', auth='public') +# def list(self, **kw): +# return http.request.render('res_partner_mails_count.listing', { +# 'root': '/res_partner_mails_count/res_partner_mails_count', +# 'objects': http.request.env['res_partner_mails_count.res_partner_mails_count'].search([]), +# }) + +# @http.route('/res_partner_mails_count/res_partner_mails_count/objects//', auth='public') +# def object(self, obj, **kw): +# return http.request.render('res_partner_mails_count.object', { +# 'object': obj +# }) \ No newline at end of file diff --git a/res_partner_mails_count/demo.xml b/res_partner_mails_count/demo.xml new file mode 100644 index 0000000..94953d2 --- /dev/null +++ b/res_partner_mails_count/demo.xml @@ -0,0 +1,25 @@ + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/res_partner_mails_count/models.py b/res_partner_mails_count/models.py new file mode 100644 index 0000000..1d667c0 --- /dev/null +++ b/res_partner_mails_count/models.py @@ -0,0 +1,50 @@ +# -*- coding: utf-8 -*- + +from openerp import models, fields, api + +import logging + + +def getlogger(name): + filename = 'test.log' + logger = logging.getLogger(name) + handler = logging.FileHandler(filename) + formatter = logging.Formatter('%(asctime)s - %(levelname)s - %(name)s: %(message)s') + + handler.setFormatter(formatter) + logger.addHandler(handler) + logger.setLevel(logging.DEBUG) + + return logger + +logger = getlogger(__name__) + + +class res_partner(models.Model): + _inherit = 'res.partner' + income = fields.Integer(compute="_income") + sent = fields.Integer(compute="_sent") + + def _search_partner(self): + return self.env['res.partner'].search([('user_ids', '=', self._uid)]) + + def _search_letters(self, partner, param): + letters = self.env['mail.message'].search([(param, '=', partner.id)]) + # logger.debug('partner.id: %s' % partner.id) + # logger.debug('Income letters: %s' % letters) + return letters + + @api.multi + def _income(self): + partner = self._search_partner() + if partner: + letters = self._search_letters(partner, 'partner_ids') + partner.income = len(letters) + + @api.multi + def _sent(self): + partner = self._search_partner() + if partner: + letters = self._search_letters(partner, 'author_id') + partner.sent = len(letters) + diff --git a/res_partner_mails_count/security/ir.model.access.csv b/res_partner_mails_count/security/ir.model.access.csv new file mode 100644 index 0000000..99d8f27 --- /dev/null +++ b/res_partner_mails_count/security/ir.model.access.csv @@ -0,0 +1,2 @@ +id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink +access_res_partner_mails_count_res_partner_mails_count,res_partner_mails_count.res_partner_mails_count,model_res_partner_mails_count_res_partner_mails_count,,1,0,0,0 \ No newline at end of file diff --git a/res_partner_mails_count/templates.xml b/res_partner_mails_count/templates.xml new file mode 100644 index 0000000..abf0199 --- /dev/null +++ b/res_partner_mails_count/templates.xml @@ -0,0 +1,87 @@ + + + + + res.partner.mails.count.income + res.partner + + + + + + + + + + + res.partner.mails.count.sent + res.partner + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file