[IMP] event : Add Stat button on contact form to count attended events
Count childs_ids too
This commit is contained in:
committed by
Yannick Tivisse
parent
88a5873d5a
commit
a866d1819c
@@ -29,6 +29,7 @@ Key Features
|
||||
'data/event_data.xml',
|
||||
'views/event_config_settings_views.xml',
|
||||
'views/event_templates.xml',
|
||||
'views/res_partner_views.xml',
|
||||
'data/email_template_data.xml',
|
||||
],
|
||||
'demo': [
|
||||
|
||||
@@ -4,3 +4,4 @@
|
||||
import event
|
||||
import event_mail
|
||||
import event_config_settings
|
||||
import res_partner
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
||||
|
||||
from odoo import api, fields, models
|
||||
|
||||
class ResPartner(models.Model):
|
||||
_inherit = 'res.partner'
|
||||
|
||||
event_count = fields.Integer("Events", compute='_compute_event_count', help="Number of events the partner has participated.")
|
||||
|
||||
def _compute_event_count(self):
|
||||
for partner in self:
|
||||
partner.event_count = self.env['event.event'].search_count([('registration_ids.partner_id', 'child_of', partner.ids)])
|
||||
|
||||
@api.multi
|
||||
def action_event_view(self):
|
||||
action = self.env.ref('event.action_event_view').read()[0]
|
||||
action['context'] = {}
|
||||
action['domain'] = [('registration_ids.partner_id', 'child_of', self.ids)]
|
||||
return action
|
||||
@@ -0,0 +1,20 @@
|
||||
<?xml version="1.0"?>
|
||||
<odoo>
|
||||
<data>
|
||||
<record id="res_partner_view_tree" model="ir.ui.view">
|
||||
<field name="name">view.res.partner.form.event.inherited</field>
|
||||
<field name="model">res.partner</field>
|
||||
<field name="inherit_id" ref="base.view_partner_form"/>
|
||||
<field name="arch" type="xml">
|
||||
<div name="button_box" position="inside">
|
||||
<button class="oe_stat_button"
|
||||
type="object"
|
||||
icon="fa-ticket"
|
||||
name="action_event_view" attrs="{'invisible': [('event_count','=', 0)]}">
|
||||
<field string="Events" name="event_count" widget="statinfo"/>
|
||||
</button>
|
||||
</div>
|
||||
</field>
|
||||
</record>
|
||||
</data>
|
||||
</odoo>
|
||||
Reference in New Issue
Block a user