Browse Source

Corrected wrong calculated mails count on the smart buttons

pull/3/head
x620 9 years ago
parent
commit
b07f52f9e3
  1. 3
      res_partner_mails_count/__openerp__.py
  2. 40
      res_partner_mails_count/models.py
  3. 28
      res_partner_mails_count/templates.xml

3
res_partner_mails_count/__openerp__.py

@ -20,11 +20,12 @@
'version': '0.1', 'version': '0.1',
# any module necessary for this one to work correctly # any module necessary for this one to work correctly
'depends': ['base'],
'depends': ['base', 'mail_sent'],
# always loaded # always loaded
'data': [ 'data': [
# 'security/ir.model.access.csv', # 'security/ir.model.access.csv',
'views/res_partner_mails_count.xml',
'templates.xml', 'templates.xml',
], ],
# only loaded in demonstration mode # only loaded in demonstration mode

40
res_partner_mails_count/models.py

@ -22,29 +22,17 @@ logger = getlogger(__name__)
class res_partner(models.Model): class res_partner(models.Model):
_inherit = 'res.partner' _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)
mails_from = fields.Integer(compute="_mails_from")
mails_to = fields.Integer(compute="_mails_to")
@api.one
def _mails_from(self):
for r in self:
letters = self.env['mail.message'].search([('partner_ids', 'in', r.id)])
self.mails_from = len(letters)
@api.one
def _mails_to(self):
for r in self:
letters = self.env['mail.message'].search([('author_id', '=', r.id)])
self.mails_to = len(letters)

28
res_partner_mails_count/templates.xml

@ -2,39 +2,29 @@
<openerp> <openerp>
<data> <data>
<record id="view_task_partner_info_form1" model="ir.ui.view"> <record id="view_task_partner_info_form1" model="ir.ui.view">
<field name="name">res.partner.mails.count.income</field>
<field name="name">res.partner.mails.count</field>
<field name="model">res.partner</field> <field name="model">res.partner</field>
<field name="inherit_id" ref="base.view_partner_form"/> <field name="inherit_id" ref="base.view_partner_form"/>
<field name="priority" eval="50"/> <field name="priority" eval="50"/>
<field name="groups_id" eval="[(4, ref('project.group_project_user'))]"/> <field name="groups_id" eval="[(4, ref('project.group_project_user'))]"/>
<field name="arch" type="xml"> <field name="arch" type="xml">
<xpath expr="//div[@name='buttons']" position="inside"> <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}"
<button class="oe_inline oe_stat_button" type="action"
name="%(action_mails_from)d"
context="{'search_default_partner_ids': [active_id]}"
icon="fa-envelope"> icon="fa-envelope">
<field string="Income" name="income" widget="statinfo"/>
<field string="Mails from" name="mails_from" widget="statinfo"/>
</button> </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}"
<button class="oe_inline oe_stat_button" type="action"
name="%(action_mails_to)d"
context="{'search_default_partner_ids': [active_id]}"
icon="fa-envelope-o"> icon="fa-envelope-o">
<field string="Sent" name="sent" widget="statinfo"/>
<field string="Mails to" name="mails_to" widget="statinfo"/>
</button> </button>
</xpath> </xpath>
</field> </field>
</record> </record>
<!--<record id="res_partner_mails_count" model="ir.actions.client">--> <!--<record id="res_partner_mails_count" model="ir.actions.client">-->
<!--<field name="name">Income</field>--> <!--<field name="name">Income</field>-->
<!--<field name="tag">mail.wall</field>--> <!--<field name="tag">mail.wall</field>-->

Loading…
Cancel
Save