Browse Source

Merge pull request #23 from x620/mail-addons-8.0-res_partner_mails_count

WIP res_partner_mails_count (incomplete)
pull/3/head
Ivan Yelizariev 9 years ago
parent
commit
a51535add2
  1. 3
      res_partner_mails_count/__init__.py
  2. 35
      res_partner_mails_count/__openerp__.py
  3. 20
      res_partner_mails_count/controllers.py
  4. 25
      res_partner_mails_count/demo.xml
  5. 19
      res_partner_mails_count/models.py
  6. 2
      res_partner_mails_count/security/ir.model.access.csv
  7. 8
      res_partner_mails_count/static/src/js/main.js
  8. 35
      res_partner_mails_count/templates.xml
  9. 3
      res_partner_mails_count/tests/__init__.py
  10. 35
      res_partner_mails_count/tests/test_mail.py
  11. 18
      res_partner_mails_count/views/res_partner_mails_count.xml

3
res_partner_mails_count/__init__.py

@ -0,0 +1,3 @@
# -*- coding: utf-8 -*-
import controllers
import models

35
res_partner_mails_count/__openerp__.py

@ -0,0 +1,35 @@
# -*- 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', 'mail'],
# always loaded
'data': [
# 'security/ir.model.access.csv',
'views/res_partner_mails_count.xml',
'templates.xml',
],
# only loaded in demonstration mode
'demo': [
'demo.xml',
],
}

20
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/<model("res_partner_mails_count.res_partner_mails_count"):obj>/', auth='public')
# def object(self, obj, **kw):
# return http.request.render('res_partner_mails_count.object', {
# 'object': obj
# })

25
res_partner_mails_count/demo.xml

@ -0,0 +1,25 @@
<openerp>
<data>
<!-- -->
<!-- <record id="object0" model="res_partner_mails_count.res_partner_mails_count"> -->
<!-- <field name="name">Object 0</field> -->
<!-- </record> -->
<!-- -->
<!-- <record id="object1" model="res_partner_mails_count.res_partner_mails_count"> -->
<!-- <field name="name">Object 1</field> -->
<!-- </record> -->
<!-- -->
<!-- <record id="object2" model="res_partner_mails_count.res_partner_mails_count"> -->
<!-- <field name="name">Object 2</field> -->
<!-- </record> -->
<!-- -->
<!-- <record id="object3" model="res_partner_mails_count.res_partner_mails_count"> -->
<!-- <field name="name">Object 3</field> -->
<!-- </record> -->
<!-- -->
<!-- <record id="object4" model="res_partner_mails_count.res_partner_mails_count"> -->
<!-- <field name="name">Object 4</field> -->
<!-- </record> -->
<!-- -->
</data>
</openerp>

19
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([('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)])

2
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

8
res_partner_mails_count/static/src/js/main.js

@ -0,0 +1,8 @@
openerp.res_partner_mails_count = function(instance){
instance.mail.Wall.include({
init: function(){
this._super.apply(this, arguments);
delete this.defaults.model;
}
});
};

35
res_partner_mails_count/templates.xml

@ -0,0 +1,35 @@
<?xml version="1.0"?>
<openerp>
<data>
<template id="res_partner_mails_count_assets_backend"
name="res_partner_mails_count_assets_backend"
inherit_id="web.assets_backend">
<xpath expr="." position="inside">
<script src="/res_partner_mails_count/static/src/js/main.js"
type="text/javascript"></script>
</xpath>
</template>
<record id="view_res_partner_mails_count_info_form" model="ir.ui.view">
<field name="name">res.partner.mails.count</field>
<field name="model">res.partner</field>
<field name="inherit_id" ref="base.view_partner_form"/>
<field name="priority" eval="50"/>
<field name="arch" type="xml">
<xpath expr="//div[@name='buttons']" position="inside">
<button class="oe_inline oe_stat_button" type="action"
name="%(action_mails)d"
context="{'search_default_partner_ids': [active_id]}"
icon="fa-envelope">
<field string="Mails to" name="mails_to" widget="statinfo"/>
</button>
<button class="oe_inline oe_stat_button" type="action"
name="%(action_mails)d"
context="{'search_default_author_id': active_id}"
icon="fa-envelope-o">
<field string="Mails from" name="mails_from" widget="statinfo"/>
</button>
</xpath>
</field>
</record>
</data>
</openerp>

3
res_partner_mails_count/tests/__init__.py

@ -0,0 +1,3 @@
# -*- coding: utf-8 -*-
from . import test_mail

35
res_partner_mails_count/tests/test_mail.py

@ -0,0 +1,35 @@
# -*- 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',
'default_model': 'res.partner',
'default_res_id': new_partner1.id,
}).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)

18
res_partner_mails_count/views/res_partner_mails_count.xml

@ -0,0 +1,18 @@
<?xml version="1.0" encoding="UTF-8"?>
<openerp>
<data>
<record id="action_mails" model="ir.actions.client">
<field name="name">Mails</field>
<field name="tag">mail.wall</field>
<field name="res_model">mail.message</field>
<field name="context">{
'ignore_search_model': True,
}</field>
<field name="help" type="html">
<p>
Mails not found. Probably, they exist, but you don't have access.
</p>
</field>
</record>
</data>
</openerp>
Loading…
Cancel
Save