[IMP] calendar: add generic res_id and res_model_id to link documents and events
Linking calendar.event to documents is a good idea to allow searching and filtering meetings. It also allow to have a link to the document from a meeting and ease navigation. There are currently some specific links (opportunity_id for crm.lead and applicant_id for hr.applicant) but this commit allows some generic document linking through a res_model_id / res_id fields pair.
This commit is contained in:
committed by
Thibault Delavallée
parent
fc4251fef9
commit
be23a75c0e
@@ -528,6 +528,27 @@ class Meeting(models.Model):
|
||||
_order = "id desc"
|
||||
_inherit = ["mail.thread"]
|
||||
|
||||
@api.model
|
||||
def default_get(self, fields):
|
||||
if self.env.context.get('default_res_model'): # super default_model='crm.lead' for easier use in adddons
|
||||
self = self.with_context(
|
||||
default_res_model_id=self.env['ir.model'].sudo().search([
|
||||
('model', '=', self.env.context['default_res_model'])
|
||||
], limit=1).id
|
||||
)
|
||||
|
||||
defaults = super(Meeting, self).default_get(fields)
|
||||
|
||||
# support active_model / active_id as replacement of default_* if not already given
|
||||
if 'res_model_id' not in defaults and 'res_model_id' in fields and \
|
||||
self.env.context.get('active_model') and self.env.context['active_model'] != 'calendar.event':
|
||||
defaults['res_model_id'] = self.env['ir.model'].sudo().search([('model', '=', self.env.context['active_model'])], limit=1).id
|
||||
if 'res_id' not in defaults and 'res_id' in fields and \
|
||||
defaults.get('res_model_id') and self.env.context.get('active_id'):
|
||||
defaults['res_id'] = self.env.context['active_id']
|
||||
|
||||
return defaults
|
||||
|
||||
@api.model
|
||||
def _default_partners(self):
|
||||
""" When active_model is res.partner, the current partners should be attendees """
|
||||
@@ -710,6 +731,11 @@ class Meeting(models.Model):
|
||||
location = fields.Char('Location', states={'done': [('readonly', True)]}, track_visibility='onchange', help="Location of Event")
|
||||
show_as = fields.Selection([('free', 'Free'), ('busy', 'Busy')], 'Show Time as', states={'done': [('readonly', True)]}, default='busy')
|
||||
|
||||
# linked document
|
||||
res_id = fields.Integer('Document ID')
|
||||
res_model_id = fields.Many2one('ir.model', 'Document Model', ondelete='cascade')
|
||||
res_model = fields.Char('Document Model Name', related='res_model_id.model', readonly=True, store=True)
|
||||
|
||||
# RECURRENCE FIELD
|
||||
rrule = fields.Char('Recurrent Rule', compute='_compute_rrule', inverse='_inverse_rrule', store=True)
|
||||
rrule_type = fields.Selection([
|
||||
@@ -1277,6 +1303,12 @@ class Meeting(models.Model):
|
||||
'flags': {'form': {'action_buttons': True, 'options': {'mode': 'edit'}}}
|
||||
}
|
||||
|
||||
@api.multi
|
||||
def action_open_calendar_event(self):
|
||||
if self.res_model and self.res_id:
|
||||
return self.env[self.res_model].browse(self.res_id).get_formview_action()
|
||||
return False
|
||||
|
||||
@api.multi
|
||||
def action_sendmail(self):
|
||||
email = self.env.user.email
|
||||
|
||||
@@ -88,6 +88,9 @@
|
||||
<field name="arch" type="xml">
|
||||
<form string="Meetings">
|
||||
<sheet>
|
||||
<button string="Document" class="oe_stat_button pull-right" icon="fa-bars" type="object" name="action_open_calendar_event" attrs="{'invisible': ['|', ('res_model', '=', False), ('res_id', '=', False)]}"/>
|
||||
<field name="res_model" invisible="1" />
|
||||
<field name="res_id" invisible="1" />
|
||||
<field name="state" invisible="1"/>
|
||||
<field name="is_attendee" invisible="1"/>
|
||||
<field name="attendee_status" invisible="1"/>
|
||||
@@ -233,6 +236,9 @@
|
||||
<field name="priority" eval="2"/>
|
||||
<field name="arch" type="xml">
|
||||
<form string="Meetings">
|
||||
<button string="Document" class="oe_stat_button pull-right" icon="fa-bars" type="object" name="action_open_calendar_event" attrs="{'invisible': ['|', ('res_model', '=', False), ('res_id', '=', False)]}"/>
|
||||
<field name="res_model" invisible="1" />
|
||||
<field name="res_id" invisible="1" />
|
||||
<field name="state" invisible="1"/>
|
||||
<field name="is_attendee" invisible="1"/>
|
||||
<field name="attendee_status" invisible="1"/>
|
||||
|
||||
@@ -8,6 +8,15 @@ class CalendarEvent(models.Model):
|
||||
|
||||
_inherit = 'calendar.event'
|
||||
|
||||
@api.model
|
||||
def default_get(self, fields):
|
||||
defaults = super(CalendarEvent, self).default_get(fields)
|
||||
if 'res_model_id' not in defaults and defaults.get('opportunity_id'):
|
||||
defaults['res_model_id'] = self.env.ref('model_crm_lead').id
|
||||
if 'res_id' not in defaults and defaults.get('opportunity_id'):
|
||||
defaults['res_id'] = defaults['opportunity_id']
|
||||
return defaults
|
||||
|
||||
def _compute_is_highlighted(self):
|
||||
super(CalendarEvent, self)._compute_is_highlighted()
|
||||
if self.env.context.get('active_model') == 'crm.lead':
|
||||
|
||||
@@ -8,6 +8,15 @@ class CalendarEvent(models.Model):
|
||||
""" Model for Calendar Event """
|
||||
_inherit = 'calendar.event'
|
||||
|
||||
@api.model
|
||||
def default_get(self, fields):
|
||||
defaults = super(CalendarEvent, self).default_get(fields)
|
||||
if 'res_model_id' not in defaults and defaults.get('applicant_id'):
|
||||
defaults['res_model_id'] = self.env.ref('model_hr_applicant').id
|
||||
if 'res_id' not in defaults and defaults.get('applicant_id'):
|
||||
defaults['res_id'] = defaults['applicant_id']
|
||||
return defaults
|
||||
|
||||
def _compute_is_highlighted(self):
|
||||
super(CalendarEvent, self)._compute_is_highlighted()
|
||||
applicant_id = self.env.context.get('active_id')
|
||||
|
||||
Reference in New Issue
Block a user