[IMP]CRM Action coherence with calendar event for dates (from and to) and partner / attendees

This commit is contained in:
Fabien BOURGEOIS 2017-10-29 10:56:53 +01:00
parent f872725ccd
commit 6a82f32f2c
2 changed files with 29 additions and 1 deletions

View File

@ -18,7 +18,7 @@
""" Calendar Event adaptations """
from odoo import models, fields
from odoo import models, fields, api
class CalendarEvent(models.Model):
@ -26,3 +26,14 @@ class CalendarEvent(models.Model):
_inherit = 'calendar.event'
partner_location_id = fields.Many2one('res.partner', 'Partner location')
crm_action_ids = fields.One2many('crm.action', 'event_id')
@api.multi
def write(self, vals):
""" Ensures date action coherence """
super(CalendarEvent, self).write(vals)
if 'start' in vals:
for event in self:
if event.crm_action_ids:
event.crm_action_ids.write({'date': event.start})
return True

View File

@ -18,6 +18,7 @@
""" CRM Action """
from datetime import timedelta
from odoo import models, fields, api, _
@ -124,6 +125,22 @@ class CrmAction(models.Model):
action.event_id = False
event.unlink()
@api.multi
def write(self, vals):
""" Ensures date event and basic partner_id coherence """
super(CrmAction, self).write(vals)
for action in self:
if action.event_id:
if action.event_id.start != action.date:
stop = fields.Datetime.from_string(action.date) + \
timedelta(hours=action.event_id.duration)
action.event_id.write({'start': action.date,
'stop': fields.Datetime.to_string(stop)})
if action.partner_id and \
action.partner_id not in action.event_id.partner_ids:
action.event_id.partner_ids |= action.partner_id
return True
class CrmActionType(models.Model):
""" CRM Action Type """