Browse Source
1. Create two Smart buttons (Income and Sent)
1. Create two Smart buttons (Income and Sent)
2. Calculate income and sent messages and output values on Smart buttons TODO: Create actions when click Smart buttonspull/3/head
x620
9 years ago
7 changed files with 221 additions and 0 deletions
-
3res_partner_mails_count/__init__.py
-
34res_partner_mails_count/__openerp__.py
-
20res_partner_mails_count/controllers.py
-
25res_partner_mails_count/demo.xml
-
50res_partner_mails_count/models.py
-
2res_partner_mails_count/security/ir.model.access.csv
-
87res_partner_mails_count/templates.xml
@ -0,0 +1,3 @@ |
|||
# -*- coding: utf-8 -*- |
|||
import controllers |
|||
import models |
@ -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', |
|||
], |
|||
} |
@ -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 |
|||
# }) |
@ -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> |
@ -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) |
|||
|
@ -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 |
@ -0,0 +1,87 @@ |
|||
<?xml version="1.0"?> |
|||
<openerp> |
|||
<data> |
|||
<record id="view_task_partner_info_form1" model="ir.ui.view"> |
|||
<field name="name">res.partner.mails.count.income</field> |
|||
<field name="model">res.partner</field> |
|||
<field name="inherit_id" ref="base.view_partner_form"/> |
|||
<field name="priority" eval="50"/> |
|||
<field name="groups_id" eval="[(4, ref('project.group_project_user'))]"/> |
|||
<field name="arch" type="xml"> |
|||
<xpath expr="//div[@name='buttons']" position="inside"> |
|||
<button class="oe_inline oe_stat_button" type="action" name="test" |
|||
context="{'search_default_partner_id': active_id, 'default_partner_id': active_id}" |
|||
icon="fa-envelope"> |
|||
<field string="Income" name="income" widget="statinfo"/> |
|||
</button> |
|||
</xpath> |
|||
</field> |
|||
</record> |
|||
<record id="view_task_partner_info_form2" model="ir.ui.view"> |
|||
<field name="name">res.partner.mails.count.sent</field> |
|||
<field name="model">res.partner</field> |
|||
<field name="inherit_id" ref="base.view_partner_form"/> |
|||
<field name="priority" eval="50"/> |
|||
<field name="groups_id" eval="[(4, ref('project.group_project_user'))]"/> |
|||
<field name="arch" type="xml"> |
|||
<xpath expr="//div[@name='buttons']" position="inside"> |
|||
<button class="oe_inline oe_stat_button" type="action" name="test" |
|||
context="{'search_default_partner_id': active_id, 'default_partner_id': active_id}" |
|||
icon="fa-envelope-o"> |
|||
<field string="Sent" name="sent" widget="statinfo"/> |
|||
</button> |
|||
</xpath> |
|||
</field> |
|||
</record> |
|||
|
|||
|
|||
<!--<record id="res_partner_mails_count" model="ir.actions.client">--> |
|||
<!--<field name="name">Income</field>--> |
|||
<!--<field name="tag">mail.wall</field>--> |
|||
<!--<field name="context">{--> |
|||
<!--'default_model': 'res.users',--> |
|||
<!--'default_res_id': uid,--> |
|||
<!--'thread_model': 'res.partner',--> |
|||
<!--'needaction_menu_ref': ['mail.mail_tomefeeds', 'mail.mail_starfeeds', 'mail.mail_inboxfeeds']--> |
|||
<!--}</field>--> |
|||
<!--<field name="params" eval=""{--> |
|||
<!--'domain': [--> |
|||
<!--'|',--> |
|||
<!--('notification_ids.partner_id.user_ids', 'in', [uid]),--> |
|||
<!--('author_id.user_ids', 'in', [uid]),--> |
|||
<!--],--> |
|||
<!--'view_mailbox': True,--> |
|||
<!--'show_compose_message': False--> |
|||
<!--}""/>--> |
|||
<!--<field name="help" type="html">--> |
|||
<!--<p>--> |
|||
<!--No message found and no message sent yet.--> |
|||
<!--</p>--> |
|||
<!--<p>--> |
|||
<!--Click on the top-right icon to compose a message. This--> |
|||
<!--message will be sent by email if it's an internal contact.--> |
|||
<!--</p>--> |
|||
<!--</field>--> |
|||
<!--</record>--> |
|||
|
|||
|
|||
<!-- <template id="listing"> --> |
|||
<!-- <ul> --> |
|||
<!-- <li t-foreach="objects" t-as="object"> --> |
|||
<!-- <a t-attf-href="#{ root }/objects/#{ object.id }"> --> |
|||
<!-- <t t-esc="object.display_name"/> --> |
|||
<!-- </a> --> |
|||
<!-- </li> --> |
|||
<!-- </ul> --> |
|||
<!-- </template> --> |
|||
<!-- <template id="object"> --> |
|||
<!-- <h1><t t-esc="object.display_name"/></h1> --> |
|||
<!-- <dl> --> |
|||
<!-- <t t-foreach="object._fields" t-as="field"> --> |
|||
<!-- <dt><t t-esc="field"/></dt> --> |
|||
<!-- <dd><t t-esc="object[field]"/></dd> --> |
|||
<!-- </t> --> |
|||
<!-- </dl> --> |
|||
<!-- </template> --> |
|||
</data> |
|||
</openerp> |
Write
Preview
Loading…
Cancel
Save
Reference in new issue