Files
odoo_source/addons/crm/models/res_partner.py
T
Nicolas Lempereur 31a18fa6ea [FIX] crm,hr_recruitment: highlight and show others
When clicking on stat button "Meetings" on a partner, just highlight the
partner meetings as is done for similar stat button instead of having
a domain that hides other event (so when creating meeting, we can take
into account other existing meetings).

A similar change with same reasoning has been done for "Meetings" stat
button of hr.applicant records.

opw-2131494
closes #40812

closes odoo/odoo#40900

X-original-commit: 957e7eb77ed18e4a1c14ef4ef55bd54503c56f44
Signed-off-by: Nicolas Lempereur (nle) <nle@odoo.com>
2019-11-25 16:59:46 +00:00

56 lines
2.3 KiB
Python

# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.
from odoo import api, fields, models
class Partner(models.Model):
_name = 'res.partner'
_inherit = 'res.partner'
team_id = fields.Many2one('crm.team', string='Sales Team')
opportunity_ids = fields.One2many('crm.lead', 'partner_id', string='Opportunities', domain=[('type', '=', 'opportunity')])
meeting_ids = fields.Many2many('calendar.event', 'calendar_event_res_partner_rel', 'res_partner_id', 'calendar_event_id', string='Meetings', copy=False)
opportunity_count = fields.Integer("Opportunity", compute='_compute_opportunity_count')
meeting_count = fields.Integer("# Meetings", compute='_compute_meeting_count')
@api.model
def default_get(self, fields):
rec = super(Partner, self).default_get(fields)
active_model = self.env.context.get('active_model')
if active_model == 'crm.lead':
lead = self.env[active_model].browse(self.env.context.get('active_id')).exists()
if lead:
rec.update(
phone=lead.phone,
mobile=lead.mobile,
function=lead.function,
title=lead.title.id,
website=lead.website,
street=lead.street,
street2=lead.street2,
city=lead.city,
state_id=lead.state_id.id,
country_id=lead.country_id.id,
zip=lead.zip,
)
return rec
def _compute_opportunity_count(self):
for partner in self:
operator = 'child_of' if partner.is_company else '=' # the opportunity count should counts the opportunities of this company and all its contacts
partner.opportunity_count = self.env['crm.lead'].search_count([('partner_id', operator, partner.id), ('type', '=', 'opportunity')])
def _compute_meeting_count(self):
for partner in self:
partner.meeting_count = len(partner.meeting_ids)
def schedule_meeting(self):
partner_ids = self.ids
partner_ids.append(self.env.user.partner_id.id)
action = self.env.ref('calendar.action_calendar_event').read()[0]
action['context'] = {
'default_partner_ids': partner_ids,
}
return action