2009-12-18 13:44:31 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
2009-12-04 08:40:21 +00:00
|
|
|
##############################################################################
|
2010-01-05 09:30:49 +00:00
|
|
|
#
|
2009-12-04 08:40:21 +00:00
|
|
|
# OpenERP, Open Source Management Solution
|
2009-12-18 13:44:31 +00:00
|
|
|
# Copyright (C) 2004-2009 Tiny SPRL (<http://tiny.be>).
|
2009-12-04 08:40:21 +00:00
|
|
|
#
|
|
|
|
# This program is free software: you can redistribute it and/or modify
|
2009-12-18 13:44:31 +00:00
|
|
|
# it under the terms of the GNU Affero General Public License as
|
|
|
|
# published by the Free Software Foundation, either version 3 of the
|
|
|
|
# License, or (at your option) any later version.
|
2009-12-04 08:40:21 +00:00
|
|
|
#
|
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
2009-12-18 13:44:31 +00:00
|
|
|
# GNU Affero General Public License for more details.
|
2009-12-04 08:40:21 +00:00
|
|
|
#
|
2009-12-18 13:44:31 +00:00
|
|
|
# You should have received a copy of the GNU Affero General Public License
|
2010-01-05 09:30:49 +00:00
|
|
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
2009-12-04 08:40:21 +00:00
|
|
|
#
|
|
|
|
##############################################################################
|
|
|
|
|
2009-12-23 05:47:42 +00:00
|
|
|
from caldav import common
|
2009-12-22 13:14:25 +00:00
|
|
|
from osv import fields, osv
|
2009-12-08 14:19:27 +00:00
|
|
|
import datetime
|
2009-12-22 13:14:25 +00:00
|
|
|
import base64
|
|
|
|
import re
|
|
|
|
import time
|
2009-12-04 08:40:21 +00:00
|
|
|
import tools
|
2009-12-31 12:57:20 +00:00
|
|
|
from tools.translate import _
|
2010-01-04 14:37:51 +00:00
|
|
|
from dateutil import parser
|
[IMP,FIX]:improve crm_calendar to handle virtual ids as string for reports,wizard,attachment,browse,read,search,ir_values(set,get),unlink,create,copy,write(partial) and fixed export_ics procedure
bzr revid: nch@tinyerp.com-20091210123425-y175qt0b3bgtxix9
2009-12-10 12:34:25 +00:00
|
|
|
|
2009-12-29 08:48:04 +00:00
|
|
|
class crm_meeting(osv.osv):
|
2010-01-05 09:30:49 +00:00
|
|
|
_name = 'crm.meeting'
|
2009-12-29 08:48:04 +00:00
|
|
|
_description = "Meeting Cases"
|
|
|
|
_order = "id desc"
|
2010-01-05 09:37:58 +00:00
|
|
|
_inherits = {'crm.case': "inherit_case_id"}
|
2009-12-04 08:40:21 +00:00
|
|
|
__attribute__ = {
|
2010-01-05 09:37:58 +00:00
|
|
|
'class': {'field': 'class', 'type': 'text'},
|
|
|
|
'created': {'field': 'create_date', 'type': 'datetime'}, # keep none for now
|
|
|
|
'description': {'field': 'description', 'type': 'text'},
|
|
|
|
'dtstart': {'field': 'date', 'type': 'datetime'},
|
|
|
|
'location': {'field': 'location', 'type': 'text'},
|
|
|
|
#'organizer': {'field': 'partner_id', 'sub-field': 'name', 'type': 'many2one'},
|
|
|
|
'priority': {'field': 'priority', 'type': 'int'},
|
|
|
|
'dtstamp' : {'field': 'date', 'type': 'datetime'},
|
|
|
|
'seq': None,
|
|
|
|
'status': {'field': 'state', 'type': 'selection', 'mapping': {'TENTATIVE': 'draft', \
|
|
|
|
'CONFIRMED': 'open' , 'CANCELLED': 'cancel'}},
|
|
|
|
'summary': {'field': 'name', 'type': 'text'},
|
|
|
|
'transp': {'field': 'transparent', 'type': 'text'},
|
|
|
|
'uid': {'field': 'id', 'type': 'text'},
|
|
|
|
'url': {'field': 'caldav_url', 'type': 'text'},
|
|
|
|
'recurid': None,
|
|
|
|
# 'attach': {'field': 'attachment_ids', 'sub-field': 'datas', 'type': 'list'},
|
2010-01-06 06:16:37 +00:00
|
|
|
'attendee': {'field': 'attendees', 'type': 'text'},
|
2010-01-05 09:37:58 +00:00
|
|
|
# 'categories': {'field': 'categ_id', 'sub-field': 'name'},
|
|
|
|
# 'categories': {'field':None , 'sub-field': 'name', 'type': 'text'},
|
|
|
|
'comment': None,
|
|
|
|
'contact': None,
|
|
|
|
'exdate' : {'field': 'exdate', 'type': 'datetime'},
|
|
|
|
'exrule' : {'field': 'exrule', 'type': 'text'},
|
|
|
|
'rstatus': None,
|
|
|
|
'related': None,
|
|
|
|
'resources': None,
|
|
|
|
'rdate': None,
|
|
|
|
'rrule': {'field': 'rrule', 'type': 'text'},
|
|
|
|
'x-openobject-model': {'value': _name, 'type': 'text'},
|
|
|
|
# 'duration': {'field': 'duration'},
|
|
|
|
'dtend': {'field': 'date_closed', 'type': 'datetime'},
|
|
|
|
'valarm': {'field': 'alarm_id', 'type': 'many2one', 'object': 'crm.caldav.alarm'},
|
2010-01-05 09:30:49 +00:00
|
|
|
}
|
[IMP,FIX]:improve crm_calendar to handle virtual ids as string for reports,wizard,attachment,browse,read,search,ir_values(set,get),unlink,create,copy,write(partial) and fixed export_ics procedure
bzr revid: nch@tinyerp.com-20091210123425-y175qt0b3bgtxix9
2009-12-10 12:34:25 +00:00
|
|
|
|
2009-12-04 08:40:21 +00:00
|
|
|
_columns = {
|
2010-01-06 06:16:37 +00:00
|
|
|
'inherit_case_id': fields.many2one('crm.case', 'Case', ondelete='cascade'),
|
|
|
|
'date_deadline': fields.datetime('Deadline', help="Deadline Date is automatically computed from Start Date + Duration"),
|
|
|
|
'class': fields.selection([('public', 'Public'), ('private', 'Private'), \
|
|
|
|
('confidential', 'Confidential')], 'Privacy'),
|
2010-01-05 09:37:58 +00:00
|
|
|
'location': fields.char('Location', size=264, help="Gives Location of Meeting"),
|
|
|
|
'freebusy': fields.text('FreeBusy'),
|
2010-01-06 06:16:37 +00:00
|
|
|
'show_as': fields.selection([('free', 'Free'), \
|
|
|
|
('busy', 'Busy')],
|
|
|
|
'show_as'),
|
2010-01-05 09:37:58 +00:00
|
|
|
'caldav_url': fields.char('Caldav URL', size=264),
|
|
|
|
'exdate': fields.text('Exception Date/Times', help="This property defines the list\
|
2009-12-22 13:14:25 +00:00
|
|
|
of date/time exceptions for arecurring calendar component."),
|
2010-01-05 09:37:58 +00:00
|
|
|
'exrule': fields.char('Exception Rule', size=352, help="defines a rule or repeating pattern\
|
2009-12-22 13:14:25 +00:00
|
|
|
for anexception to a recurrence set"),
|
2010-01-06 06:16:37 +00:00
|
|
|
'rrule': fields.char('Recurrent Rule', size=352, invisible="True"),
|
|
|
|
'rrule_type' : fields.selection([('none', 'None'), ('daily', 'Daily'), \
|
|
|
|
('weekly', 'Weekly'), ('monthly', 'Monthly'), ('yearly', 'Yearly'), ('custom','Custom')], 'Recurrency'),
|
|
|
|
'attendees': fields.text('Attendees'),
|
2010-01-05 09:37:58 +00:00
|
|
|
'alarm_id': fields.many2one('crm.caldav.alarm', 'Alarm'),
|
2010-01-06 06:16:37 +00:00
|
|
|
'attendee_ids' : fields.many2many('res.users', 'crm_meeting_attendee_rel',
|
|
|
|
'crm_meeting_id', 'user_id', 'Attendee')
|
2009-12-04 08:40:21 +00:00
|
|
|
}
|
[IMP,FIX]:improve crm_calendar to handle virtual ids as string for reports,wizard,attachment,browse,read,search,ir_values(set,get),unlink,create,copy,write(partial) and fixed export_ics procedure
bzr revid: nch@tinyerp.com-20091210123425-y175qt0b3bgtxix9
2009-12-10 12:34:25 +00:00
|
|
|
|
2010-01-05 09:30:49 +00:00
|
|
|
_defaults = {
|
2010-01-06 06:16:37 +00:00
|
|
|
'class': lambda *a: 'public',
|
2009-12-29 08:48:04 +00:00
|
|
|
}
|
2010-01-05 09:30:49 +00:00
|
|
|
|
2010-01-06 06:16:37 +00:00
|
|
|
def on_change_duration(self, cr, uid, id, date, duration):
|
|
|
|
if not date:
|
|
|
|
return {}
|
|
|
|
start_date = datetime.datetime.fromtimestamp(time.mktime(time.strptime(date, "%Y-%m-%d %H:%M:%S")))
|
|
|
|
if duration >= 0 :
|
|
|
|
end = start_date + datetime.timedelta(hours=duration)
|
|
|
|
if duration < 0:
|
|
|
|
raise osv.except_osv(_('Warning !'),
|
|
|
|
_('You can not set negative Duration.'))
|
|
|
|
|
|
|
|
res = {'value' : {'date_deadline' : end.strftime('%Y-%m-%d %H:%M:%S')}}
|
|
|
|
return res
|
2010-01-05 09:30:49 +00:00
|
|
|
|
2009-12-15 09:19:34 +00:00
|
|
|
def run_scheduler(self, cr, uid, automatic=False, use_new_cursor=False, \
|
|
|
|
context=None):
|
2009-12-08 14:19:27 +00:00
|
|
|
if not context:
|
2009-12-22 13:14:25 +00:00
|
|
|
context = {}
|
2009-12-29 08:48:04 +00:00
|
|
|
cr.execute('select c.id as id, crm_case.date as date, alarm.id as alarm_id, alarm.name as name,\
|
2009-12-08 14:19:27 +00:00
|
|
|
alarm.trigger_interval, alarm.trigger_duration, alarm.trigger_related, \
|
2009-12-29 08:48:04 +00:00
|
|
|
alarm.trigger_occurs from crm_meeting c \
|
|
|
|
join crm_case on c.inherit_case_id = crm_case.id \
|
2009-12-08 14:19:27 +00:00
|
|
|
join crm_caldav_alarm alarm on (alarm.id=c.alarm_id) \
|
2009-12-15 09:19:34 +00:00
|
|
|
where alarm_id is not null and alarm.active=True')
|
2010-01-05 09:30:49 +00:00
|
|
|
case_with_alarm = cr.dictfetchall()
|
2009-12-29 08:48:04 +00:00
|
|
|
case_obj = self.pool.get('crm.meeting')
|
2009-12-08 14:19:27 +00:00
|
|
|
attendee_obj = self.pool.get('crm.caldav.attendee')
|
|
|
|
mail_to = []
|
|
|
|
for alarmdata in case_with_alarm:
|
|
|
|
dtstart = datetime.datetime.strptime(alarmdata['date'], "%Y-%m-%d %H:%M:%S")
|
2009-12-17 06:26:30 +00:00
|
|
|
if alarmdata['trigger_interval'] == 'DAYS':
|
|
|
|
delta = datetime.timedelta(days=alarmdata['trigger_duration'])
|
|
|
|
if alarmdata['trigger_interval'] == 'HOURS':
|
|
|
|
delta = datetime.timedelta(hours=alarmdata['trigger_duration'])
|
|
|
|
if alarmdata['trigger_interval'] == 'MINUTES':
|
|
|
|
delta = datetime.timedelta(minutes=alarmdata['trigger_duration'])
|
|
|
|
alarm_time = dtstart + (alarmdata['trigger_occurs']== 'AFTER' and delta or -delta)
|
2009-12-08 14:19:27 +00:00
|
|
|
if datetime.datetime.now() >= alarm_time:
|
2009-12-16 06:52:41 +00:00
|
|
|
case_val = case_obj.browse(cr, uid, alarmdata.get('id'), context)[0]
|
2009-12-08 14:19:27 +00:00
|
|
|
for att in case_val.attendees:
|
2010-01-05 09:37:58 +00:00
|
|
|
if att.cn.rsplit(': ')[-1]:
|
|
|
|
mail_to.append(att.cn.rsplit(': ')[-1])
|
2009-12-08 14:19:27 +00:00
|
|
|
if mail_to:
|
2010-01-05 09:30:49 +00:00
|
|
|
sub = 'Event Reminder for ' + case_val.name or ''
|
2009-12-15 09:19:34 +00:00
|
|
|
body = (case_val.name or '')+ '\n\t' + (case_val.description or '') + '\n\nEvent time: ' \
|
|
|
|
+(case_val.date) + '\n\nLocation: ' + (case_val.location or '') + \
|
2009-12-08 14:19:27 +00:00
|
|
|
'\n\nMembers Details: ' + '\n'.join(mail_to)
|
|
|
|
tools.email_send(
|
2009-12-15 09:19:34 +00:00
|
|
|
case_val.user_id.address_id.email,
|
|
|
|
mail_to,
|
|
|
|
sub,
|
2009-12-08 14:19:27 +00:00
|
|
|
body
|
|
|
|
)
|
|
|
|
cr.execute('update crm_caldav_alarm set active=False\
|
|
|
|
where id = %s' % alarmdata['alarm_id'])
|
|
|
|
cr.commit()
|
|
|
|
return True
|
|
|
|
|
2009-12-04 08:40:21 +00:00
|
|
|
def export_cal(self, cr, uid, ids, context={}):
|
2010-01-05 09:37:58 +00:00
|
|
|
crm_data = self.read(cr, uid, ids, [], context ={'read':True})
|
2009-12-04 08:40:21 +00:00
|
|
|
event_obj = self.pool.get('caldav.event')
|
2009-12-16 14:16:20 +00:00
|
|
|
event_obj.__attribute__.update(self.__attribute__)
|
2010-01-05 09:30:49 +00:00
|
|
|
|
2009-12-16 14:16:20 +00:00
|
|
|
attendee_obj = self.pool.get('caldav.attendee')
|
|
|
|
crm_attendee = self.pool.get('crm.caldav.attendee')
|
|
|
|
attendee_obj.__attribute__.update(crm_attendee.__attribute__)
|
2010-01-05 09:30:49 +00:00
|
|
|
|
2009-12-16 14:16:20 +00:00
|
|
|
alarm_obj = self.pool.get('caldav.alarm')
|
|
|
|
crm_alarm = self.pool.get('crm.caldav.alarm')
|
|
|
|
alarm_obj.__attribute__.update(crm_alarm.__attribute__)
|
2010-01-05 09:30:49 +00:00
|
|
|
|
2009-12-29 08:48:04 +00:00
|
|
|
ical = event_obj.export_ical(cr, uid, crm_data, {'model': 'crm.meeting'})
|
2009-12-16 14:16:20 +00:00
|
|
|
caendar_val = ical.serialize()
|
|
|
|
caendar_val = caendar_val.replace('"', '').strip()
|
|
|
|
return caendar_val
|
2009-12-04 08:40:21 +00:00
|
|
|
|
2009-12-28 07:06:10 +00:00
|
|
|
def import_cal(self, cr, uid, data, context={}):
|
2009-12-24 13:35:49 +00:00
|
|
|
file_content = base64.decodestring(data)
|
2009-12-04 08:40:21 +00:00
|
|
|
event_obj = self.pool.get('caldav.event')
|
|
|
|
event_obj.__attribute__.update(self.__attribute__)
|
2009-12-22 13:14:25 +00:00
|
|
|
|
2009-12-14 11:07:43 +00:00
|
|
|
attendee_obj = self.pool.get('caldav.attendee')
|
|
|
|
crm_attendee = self.pool.get('crm.caldav.attendee')
|
|
|
|
attendee_obj.__attribute__.update(crm_attendee.__attribute__)
|
2010-01-05 09:30:49 +00:00
|
|
|
|
2009-12-15 13:43:55 +00:00
|
|
|
alarm_obj = self.pool.get('caldav.alarm')
|
|
|
|
crm_alarm = self.pool.get('crm.caldav.alarm')
|
|
|
|
alarm_obj.__attribute__.update(crm_alarm.__attribute__)
|
2009-12-14 11:07:43 +00:00
|
|
|
vals = event_obj.import_ical(cr, uid, file_content)
|
2009-12-21 09:49:00 +00:00
|
|
|
for val in vals:
|
2009-12-30 07:06:19 +00:00
|
|
|
section_id = self.pool.get('crm.case.section').search(cr, uid, \
|
|
|
|
[('name', 'like', 'Meeting%')])[0]
|
2010-01-05 09:37:58 +00:00
|
|
|
val.update({'section_id': section_id})
|
2010-01-05 09:30:49 +00:00
|
|
|
is_exists = common.uid2openobjectid(cr, val['id'], self._name)
|
2009-12-21 09:49:00 +00:00
|
|
|
val.pop('id')
|
2009-12-28 13:36:59 +00:00
|
|
|
if val.has_key('create_date'): val.pop('create_date')
|
|
|
|
val['caldav_url'] = context.get('url') or ''
|
2009-12-24 13:35:49 +00:00
|
|
|
if is_exists:
|
|
|
|
self.write(cr, uid, [is_exists], val)
|
|
|
|
else:
|
|
|
|
case_id = self.create(cr, uid, val)
|
2009-12-21 09:49:00 +00:00
|
|
|
return {'count': len(vals)}
|
2009-12-04 08:40:21 +00:00
|
|
|
|
2010-01-04 14:37:51 +00:00
|
|
|
def get_recurrent_ids(self, cr, uid, ids, start_date, until_date, limit=100):
|
|
|
|
if not limit:
|
|
|
|
limit = 100
|
|
|
|
|
|
|
|
if ids and (start_date or until_date):
|
|
|
|
cr.execute("select m.id, m.rrule, c.date, m.exdate from crm_meeting m\
|
|
|
|
join crm_case c on (c.id=m.inherit_case_id) \
|
2010-01-05 09:37:58 +00:00
|
|
|
where m.id in ("+ ','.join(map(lambda x: str(x), ids))+")")
|
2010-01-04 14:37:51 +00:00
|
|
|
result = []
|
|
|
|
count = 0
|
|
|
|
start_date = start_date and datetime.datetime.strptime(start_date, "%Y-%m-%d") or False
|
|
|
|
until_date = until_date and datetime.datetime.strptime(until_date, "%Y-%m-%d") or False
|
|
|
|
for data in cr.dictfetchall():
|
|
|
|
if count > limit:
|
2010-01-05 09:30:49 +00:00
|
|
|
break
|
|
|
|
event_date = datetime.datetime.strptime(data['date'], "%Y-%m-%d %H:%M:%S")
|
2010-01-04 14:37:51 +00:00
|
|
|
if start_date and start_date <= event_date:
|
|
|
|
start_date = event_date
|
2010-01-05 09:30:49 +00:00
|
|
|
if not data['rrule']:
|
2010-01-04 14:37:51 +00:00
|
|
|
idval = common.real_id2caldav_id(data['id'], data['date'])
|
2010-01-05 09:30:49 +00:00
|
|
|
result.append(idval)
|
|
|
|
count += 1
|
2010-01-04 14:37:51 +00:00
|
|
|
else:
|
|
|
|
exdate = data['exdate'] and data['exdate'].split(',') or []
|
|
|
|
event_obj = self.pool.get('caldav.event')
|
2010-01-05 09:30:49 +00:00
|
|
|
rrule_str = data['rrule']
|
|
|
|
new_rrule_str = []
|
2010-01-04 14:37:51 +00:00
|
|
|
rrule_until_date = False
|
|
|
|
for rule in rrule_str.split(';'):
|
|
|
|
name, value = rule.split('=')
|
|
|
|
if name == "UNTIL":
|
|
|
|
value = parser.parse(value)
|
|
|
|
rrule_until_date = parser.parse(value.strftime("%Y-%m-%d"))
|
|
|
|
if until_date and until_date >= rrule_until_date:
|
2010-01-05 09:30:49 +00:00
|
|
|
until_date = rrule_until_date
|
2010-01-04 14:37:51 +00:00
|
|
|
if until_date:
|
|
|
|
until_date = until_date.strftime("%Y%m%d%H%M%S")
|
|
|
|
value = until_date
|
2010-01-05 09:37:58 +00:00
|
|
|
new_rule = '%s=%s' % (name, value)
|
2010-01-04 14:37:51 +00:00
|
|
|
new_rrule_str.append(new_rule)
|
|
|
|
new_rrule_str = ';'.join(new_rrule_str)
|
2010-01-05 09:30:49 +00:00
|
|
|
start_date = datetime.datetime.strptime(data['date'], "%Y-%m-%d %H:%M:%S")
|
2010-01-04 14:37:51 +00:00
|
|
|
rdates = event_obj.get_recurrent_dates(str(new_rrule_str), exdate, start_date)
|
2010-01-05 09:30:49 +00:00
|
|
|
for rdate in rdates:
|
2010-01-04 14:37:51 +00:00
|
|
|
idval = common.real_id2caldav_id(data['id'], rdate)
|
2010-01-05 09:30:49 +00:00
|
|
|
result.append(idval)
|
2010-01-04 14:37:51 +00:00
|
|
|
count += 1
|
2010-01-05 09:30:49 +00:00
|
|
|
ids = result
|
2010-01-04 14:37:51 +00:00
|
|
|
return ids
|
|
|
|
|
|
|
|
def search(self, cr, uid, args, offset=0, limit=100, order=None,
|
2010-01-05 09:30:49 +00:00
|
|
|
context=None, count=False):
|
2010-01-04 14:37:51 +00:00
|
|
|
args_without_date = []
|
|
|
|
start_date = False
|
|
|
|
until_date = False
|
|
|
|
for arg in args:
|
|
|
|
if arg[0] not in ('date', unicode('date')):
|
|
|
|
args_without_date.append(arg)
|
|
|
|
else:
|
|
|
|
if arg[1] in ('>', '>='):
|
|
|
|
start_date = arg[2]
|
|
|
|
elif arg[1] in ('<', '<='):
|
|
|
|
until_date = arg[2]
|
|
|
|
|
|
|
|
res = super(crm_meeting, self).search(cr, uid, args_without_date, offset,
|
2009-12-04 08:40:21 +00:00
|
|
|
limit, order, context, count)
|
2010-01-05 09:30:49 +00:00
|
|
|
return self.get_recurrent_ids(cr, uid, res, start_date, until_date, limit)
|
|
|
|
|
[IMP,FIX]:improve crm_calendar to handle virtual ids as string for reports,wizard,attachment,browse,read,search,ir_values(set,get),unlink,create,copy,write(partial) and fixed export_ics procedure
bzr revid: nch@tinyerp.com-20091210123425-y175qt0b3bgtxix9
2009-12-10 12:34:25 +00:00
|
|
|
|
2009-12-23 14:06:16 +00:00
|
|
|
def write(self, cr, uid, ids, vals, context=None, check=True, update_check=True):
|
2009-12-29 11:02:22 +00:00
|
|
|
if isinstance(ids, (str, int, long)):
|
|
|
|
select = [ids]
|
|
|
|
else:
|
|
|
|
select = ids
|
[IMP,FIX]:improve crm_calendar to handle virtual ids as string for reports,wizard,attachment,browse,read,search,ir_values(set,get),unlink,create,copy,write(partial) and fixed export_ics procedure
bzr revid: nch@tinyerp.com-20091210123425-y175qt0b3bgtxix9
2009-12-10 12:34:25 +00:00
|
|
|
new_ids = []
|
2009-12-29 11:02:22 +00:00
|
|
|
for id in select:
|
2010-01-04 14:37:51 +00:00
|
|
|
id = common.caldav_id2real_id(id)
|
[IMP,FIX]:improve crm_calendar to handle virtual ids as string for reports,wizard,attachment,browse,read,search,ir_values(set,get),unlink,create,copy,write(partial) and fixed export_ics procedure
bzr revid: nch@tinyerp.com-20091210123425-y175qt0b3bgtxix9
2009-12-10 12:34:25 +00:00
|
|
|
if not id in new_ids:
|
|
|
|
new_ids.append(id)
|
2010-01-05 09:37:58 +00:00
|
|
|
if 'case_id' in vals:
|
2010-01-04 14:37:51 +00:00
|
|
|
vals['case_id'] = common.caldav_id2real_id(vals['case_id'])
|
2009-12-29 08:48:04 +00:00
|
|
|
res = super(crm_meeting, self).write(cr, uid, new_ids, vals, context=context)
|
2009-12-04 08:40:21 +00:00
|
|
|
return res
|
[IMP,FIX]:improve crm_calendar to handle virtual ids as string for reports,wizard,attachment,browse,read,search,ir_values(set,get),unlink,create,copy,write(partial) and fixed export_ics procedure
bzr revid: nch@tinyerp.com-20091210123425-y175qt0b3bgtxix9
2009-12-10 12:34:25 +00:00
|
|
|
|
2009-12-29 08:48:04 +00:00
|
|
|
def browse(self, cr, uid, ids, context=None, list_class=None, fields_process={}):
|
|
|
|
if isinstance(ids, (str, int, long)):
|
|
|
|
select = [ids]
|
|
|
|
else:
|
2010-01-05 09:30:49 +00:00
|
|
|
select = ids
|
2010-01-05 09:37:58 +00:00
|
|
|
select = map(lambda x: common.caldav_id2real_id(x), select)
|
2010-01-05 09:30:49 +00:00
|
|
|
res = super(crm_meeting, self).browse(cr, uid, select, context, list_class, fields_process)
|
2009-12-29 08:48:04 +00:00
|
|
|
if isinstance(ids, (str, int, long)):
|
|
|
|
return res and res[0] or False
|
|
|
|
return res
|
2009-12-04 08:40:21 +00:00
|
|
|
|
2010-01-05 09:30:49 +00:00
|
|
|
def read(self, cr, uid, ids, fields=None, context={}, load='_classic_read'):
|
2010-01-04 14:37:51 +00:00
|
|
|
if isinstance(ids, (str, int, long)):
|
|
|
|
select = [ids]
|
2009-12-04 14:15:17 +00:00
|
|
|
else:
|
2010-01-04 14:37:51 +00:00
|
|
|
select = ids
|
2010-01-05 09:37:58 +00:00
|
|
|
select = map(lambda x: (x, common.caldav_id2real_id(x)), select)
|
2010-01-04 14:37:51 +00:00
|
|
|
result = []
|
2009-12-29 08:48:04 +00:00
|
|
|
if fields and 'date' not in fields:
|
|
|
|
fields.append('date')
|
2010-01-05 09:30:49 +00:00
|
|
|
for caldav_id, real_id in select:
|
2010-01-04 14:37:51 +00:00
|
|
|
res = super(crm_meeting, self).read(cr, uid, real_id, fields=fields, context=context, \
|
|
|
|
load=load)
|
2010-01-05 09:30:49 +00:00
|
|
|
ls = common.caldav_id2real_id(caldav_id, with_date=True)
|
|
|
|
if not isinstance(ls, (str, int, long)) and len(ls) >= 2:
|
2010-01-04 14:37:51 +00:00
|
|
|
res['date'] = ls[1]
|
|
|
|
res['id'] = caldav_id
|
2010-01-05 09:30:49 +00:00
|
|
|
|
2010-01-04 14:37:51 +00:00
|
|
|
result.append(res)
|
|
|
|
if isinstance(ids, (str, int, long)):
|
2010-01-05 09:30:49 +00:00
|
|
|
return result and result[0] or False
|
[IMP,FIX]:improve crm_calendar to handle virtual ids as string for reports,wizard,attachment,browse,read,search,ir_values(set,get),unlink,create,copy,write(partial) and fixed export_ics procedure
bzr revid: nch@tinyerp.com-20091210123425-y175qt0b3bgtxix9
2009-12-10 12:34:25 +00:00
|
|
|
return result
|
|
|
|
|
2010-01-05 09:30:49 +00:00
|
|
|
def copy(self, cr, uid, id, default=None, context={}):
|
2010-01-04 14:37:51 +00:00
|
|
|
return super(crm_meeting, self).copy(cr, uid, common.caldav_id2real_id(id), \
|
2009-12-23 05:47:42 +00:00
|
|
|
default, context)
|
[IMP,FIX]:improve crm_calendar to handle virtual ids as string for reports,wizard,attachment,browse,read,search,ir_values(set,get),unlink,create,copy,write(partial) and fixed export_ics procedure
bzr revid: nch@tinyerp.com-20091210123425-y175qt0b3bgtxix9
2009-12-10 12:34:25 +00:00
|
|
|
|
2009-12-04 08:40:21 +00:00
|
|
|
def unlink(self, cr, uid, ids, context=None):
|
|
|
|
for id in ids:
|
2010-01-04 14:37:51 +00:00
|
|
|
ls = common.caldav_id2real_id(caldav_id)
|
2010-01-05 09:30:49 +00:00
|
|
|
if not isinstance(ls, (str, int, long)) and len(ls) >= 2:
|
2010-01-04 14:37:51 +00:00
|
|
|
date_new = ls[1]
|
|
|
|
for record in self.read(cr, uid, [common.caldav_id2real_id(id)], \
|
2010-01-01 10:23:13 +00:00
|
|
|
['date', 'rrule', 'exdate']):
|
2009-12-23 07:00:48 +00:00
|
|
|
if record['rrule']:
|
2010-01-05 09:30:49 +00:00
|
|
|
exdate = (record['exdate'] and (record['exdate'] + ',') or '') + \
|
2009-12-23 07:00:48 +00:00
|
|
|
''.join((re.compile('\d')).findall(date_new)) + 'Z'
|
|
|
|
if record['date'] == date_new:
|
2010-01-05 09:37:58 +00:00
|
|
|
self.write(cr, uid, [common.caldav_id2real_id(id)], {'exdate': exdate})
|
2009-12-23 07:00:48 +00:00
|
|
|
else:
|
2010-01-05 09:37:58 +00:00
|
|
|
ids = map(lambda x: common.caldav_id2real_id(x), ids)
|
2010-01-04 14:37:51 +00:00
|
|
|
return super(crm_meeting, self).unlink(cr, uid, common.caldav_id2real_id(ids))
|
2009-12-04 08:40:21 +00:00
|
|
|
else:
|
2009-12-29 08:48:04 +00:00
|
|
|
return super(crm_meeting, self).unlink(cr, uid, ids)
|
2009-12-14 11:07:43 +00:00
|
|
|
|
[IMP,FIX]:improve crm_calendar to handle virtual ids as string for reports,wizard,attachment,browse,read,search,ir_values(set,get),unlink,create,copy,write(partial) and fixed export_ics procedure
bzr revid: nch@tinyerp.com-20091210123425-y175qt0b3bgtxix9
2009-12-10 12:34:25 +00:00
|
|
|
def create(self, cr, uid, vals, context={}):
|
|
|
|
if 'case_id' in vals:
|
2010-01-04 14:37:51 +00:00
|
|
|
vals['case_id'] = common.caldav_id2real_id(vals['case_id'])
|
2009-12-29 08:48:04 +00:00
|
|
|
return super(crm_meeting, self).create(cr, uid, vals, context)
|
[IMP,FIX]:improve crm_calendar to handle virtual ids as string for reports,wizard,attachment,browse,read,search,ir_values(set,get),unlink,create,copy,write(partial) and fixed export_ics procedure
bzr revid: nch@tinyerp.com-20091210123425-y175qt0b3bgtxix9
2009-12-10 12:34:25 +00:00
|
|
|
|
2009-12-29 11:02:22 +00:00
|
|
|
|
|
|
|
def _map_ids(self, method, cr, uid, ids, *args, **argv):
|
2010-01-03 06:57:57 +00:00
|
|
|
if isinstance(ids, (str, int, long)):
|
|
|
|
select = [ids]
|
|
|
|
else:
|
2010-01-05 09:30:49 +00:00
|
|
|
select = ids
|
2010-01-03 06:57:57 +00:00
|
|
|
case_data = self.browse(cr, uid, select)
|
2009-12-29 11:02:22 +00:00
|
|
|
new_ids = []
|
|
|
|
for case in case_data:
|
|
|
|
if case.inherit_case_id:
|
|
|
|
new_ids.append(case.inherit_case_id.id)
|
2010-01-05 09:30:49 +00:00
|
|
|
res = getattr(self.pool.get('crm.case'), method)(cr, uid, new_ids, *args, **argv)
|
2010-01-03 06:57:57 +00:00
|
|
|
if isinstance(ids, (str, int, long)) and isinstance(res, list):
|
|
|
|
return res and res[0] or False
|
|
|
|
return res
|
2010-01-06 10:33:27 +00:00
|
|
|
|
|
|
|
def onchange_rrule_type(self, cr, uid, ids, type, *args, **argv):
|
|
|
|
if type == 'none':
|
|
|
|
return {'value': {'rrule': ''}}
|
|
|
|
if type == 'custom':
|
|
|
|
return {}
|
|
|
|
rrule = self.pool.get('caldav.set.rrule')
|
|
|
|
rrulestr = rrule.compute_rule_string(cr, uid, {'freq': type.upper(),\
|
|
|
|
'interval': 1})
|
|
|
|
return {'value': {'rrule': rrulestr}}
|
|
|
|
|
|
|
|
|
2009-12-29 11:02:22 +00:00
|
|
|
def onchange_case_id(self, cr, uid, ids, *args, **argv):
|
2010-01-05 09:30:49 +00:00
|
|
|
return self._map_ids('onchange_case_id', cr, uid, ids, *args, **argv)
|
2009-12-29 11:02:22 +00:00
|
|
|
def onchange_partner_id(self, cr, uid, ids, *args, **argv):
|
2010-01-05 09:30:49 +00:00
|
|
|
return self._map_ids('onchange_partner_id', cr, uid, ids, *args, **argv)
|
2009-12-29 11:02:22 +00:00
|
|
|
def onchange_partner_address_id(self, cr, uid, ids, *args, **argv):
|
2010-01-05 09:30:49 +00:00
|
|
|
return self._map_ids('onchange_partner_address_id', cr, uid, ids, *args, **argv)
|
2009-12-29 11:02:22 +00:00
|
|
|
def onchange_categ_id(self, cr, uid, ids, *args, **argv):
|
2010-01-05 09:30:49 +00:00
|
|
|
return self._map_ids('onchange_categ_id', cr, uid, ids, *args, **argv)
|
|
|
|
def case_close(self, cr, uid, ids, *args, **argv):
|
|
|
|
return self._map_ids('case_close', cr, uid, ids, *args, **argv)
|
|
|
|
def case_open(self, cr, uid, ids, *args, **argv):
|
|
|
|
return self._map_ids('case_open', cr, uid, ids, *args, **argv)
|
|
|
|
def case_cancel(self, cr, uid, ids, *args, **argv):
|
|
|
|
return self._map_ids('case_cancel', cr, uid, ids, *args, **argv)
|
|
|
|
def case_reset(self, cr, uid, ids, *args, **argv):
|
|
|
|
return self._map_ids('case_reset', cr, uid, ids, *args, **argv)
|
|
|
|
|
|
|
|
def msg_new(self, cr, uid, msg):
|
2010-01-03 06:57:57 +00:00
|
|
|
mailgate_obj = self.pool.get('mail.gateway')
|
|
|
|
msg_body = mailgate_obj.msg_body_get(msg)
|
|
|
|
data = {
|
2010-01-05 09:30:49 +00:00
|
|
|
'name': msg['Subject'],
|
|
|
|
'email_from': msg['From'],
|
|
|
|
'email_cc': msg['Cc'],
|
|
|
|
'user_id': False,
|
|
|
|
'description': msg_body['body'],
|
|
|
|
'history_line': [(0, 0, {'description': msg_body['body'], 'email': msg['From'] })],
|
2010-01-03 06:57:57 +00:00
|
|
|
}
|
|
|
|
res = mailgate_obj.partner_get(cr, uid, msg['From'])
|
|
|
|
if res:
|
|
|
|
data.update(res)
|
2010-01-05 09:30:49 +00:00
|
|
|
res = self.create(cr, uid, data)
|
2010-01-03 06:57:57 +00:00
|
|
|
return res
|
|
|
|
|
|
|
|
def msg_update(self, cr, uid, ids, *args, **argv):
|
2010-01-05 09:30:49 +00:00
|
|
|
return self._map_ids('msg_update', cr, uid, ids, *args, **argv)
|
2010-01-03 06:57:57 +00:00
|
|
|
def emails_get(self, cr, uid, ids, *args, **argv):
|
2010-01-05 09:30:49 +00:00
|
|
|
return self._map_ids('emails_get', cr, uid, ids, *args, **argv)
|
|
|
|
def msg_send(self, cr, uid, ids, *args, **argv):
|
|
|
|
return self._map_ids('msg_send', cr, uid, ids, *args, **argv)
|
2009-12-29 11:02:22 +00:00
|
|
|
|
2009-12-29 08:48:04 +00:00
|
|
|
crm_meeting()
|
2009-12-04 08:40:21 +00:00
|
|
|
|
|
|
|
|
2009-12-29 11:02:22 +00:00
|
|
|
class crm_meeting_generic_wizard(osv.osv_memory):
|
|
|
|
_name = 'crm.meeting.generic_wizard'
|
|
|
|
|
|
|
|
_columns = {
|
2010-01-05 09:30:49 +00:00
|
|
|
'section_id': fields.many2one('crm.case.section', 'Section', required=True),
|
|
|
|
'user_id': fields.many2one('res.users', 'Responsible'),
|
2009-12-29 11:02:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
def _get_default_section(self, cr, uid, context):
|
2010-01-05 09:30:49 +00:00
|
|
|
case_id = context.get('active_id', False)
|
2009-12-29 11:02:22 +00:00
|
|
|
if not case_id:
|
|
|
|
return False
|
|
|
|
case_obj = self.pool.get('crm.meeting')
|
2010-01-05 09:30:49 +00:00
|
|
|
case = case_obj.read(cr, uid, case_id, ['state', 'section_id'])
|
2009-12-29 11:02:22 +00:00
|
|
|
if case['state'] in ('done'):
|
|
|
|
raise osv.except_osv(_('Error !'), _('You can not assign Closed Case.'))
|
|
|
|
return case['section_id']
|
|
|
|
|
|
|
|
|
|
|
|
_defaults = {
|
|
|
|
'section_id': _get_default_section
|
|
|
|
}
|
|
|
|
def action_create(self, cr, uid, ids, context=None):
|
|
|
|
case_obj = self.pool.get('crm.meeting')
|
2010-01-05 09:30:49 +00:00
|
|
|
case_id = context.get('active_id', [])
|
2009-12-29 11:02:22 +00:00
|
|
|
res = self.read(cr, uid, ids)[0]
|
2009-12-31 12:57:20 +00:00
|
|
|
case = case_obj.browse(cr, uid, case_id)
|
|
|
|
if case.state in ('done'):
|
2009-12-29 11:02:22 +00:00
|
|
|
raise osv.except_osv(_('Error !'), _('You can not assign Closed Case.'))
|
|
|
|
new_case_id = case_obj.copy(cr, uid, case_id, default=
|
|
|
|
{
|
2010-01-05 09:37:58 +00:00
|
|
|
'section_id': res.get('section_id', False),
|
|
|
|
'user_id': res.get('user_id', False),
|
|
|
|
'case_id': case.inherit_case_id.id
|
2010-01-05 09:30:49 +00:00
|
|
|
}, context=context)
|
2009-12-29 11:02:22 +00:00
|
|
|
case_obj.case_close(cr, uid, [case_id])
|
2009-12-31 12:57:20 +00:00
|
|
|
data_obj = self.pool.get('ir.model.data')
|
|
|
|
result = data_obj._get_id(cr, uid, 'crm', 'view_crm_case_meetings_filter')
|
|
|
|
search_view = data_obj.read(cr, uid, result, ['res_id'])
|
2010-01-05 09:30:49 +00:00
|
|
|
new_case = case_obj.read(cr, uid, new_case_id, ['id'])
|
|
|
|
value = {
|
|
|
|
'name': _('Meetings'),
|
|
|
|
'view_type': 'form',
|
|
|
|
'view_mode': 'calendar, tree, form',
|
|
|
|
'res_model': 'crm.meeting',
|
|
|
|
'type': 'ir.actions.act_window',
|
2009-12-31 12:57:20 +00:00
|
|
|
'search_view_id': search_view['res_id']
|
|
|
|
}
|
|
|
|
return value
|
2009-12-29 11:02:22 +00:00
|
|
|
|
|
|
|
crm_meeting_generic_wizard()
|
|
|
|
|
2010-01-05 13:48:22 +00:00
|
|
|
class res_users(osv.osv):
|
|
|
|
_inherit = 'res.users'
|
|
|
|
|
|
|
|
def _get_user_avail(self, cr, uid, ids, name, args, context=None):
|
|
|
|
res={}
|
|
|
|
if not context or not context.get('model'):
|
|
|
|
return {}
|
|
|
|
else:
|
|
|
|
model = context.get('model')
|
|
|
|
obj = self.pool.get(model)
|
|
|
|
event_obj = obj.browse(cr, uid, context['active_id'])
|
|
|
|
event_start = event_obj.date
|
|
|
|
event_end = datetime.datetime.strptime(event_obj.date, "%Y-%m-%d %H:%M:%S") \
|
|
|
|
+ datetime.timedelta(hours=event_obj.duration)
|
|
|
|
for id in ids:
|
|
|
|
datas = self.browse(cr, uid, id)
|
|
|
|
cr.execute("""SELECT c.date as start, (c.date::timestamp \
|
|
|
|
+ c.duration * interval '1 hour') as end \
|
|
|
|
from crm_meeting m \
|
|
|
|
join crm_case c on (c.id=m.inherit_case_id)\
|
|
|
|
where c.user_id = %s
|
|
|
|
and m.id not in (""" % (datas['id']) + str(context['active_id']) +")")
|
|
|
|
dates = cr.dictfetchall()
|
|
|
|
overlaps = False
|
|
|
|
# check event time
|
|
|
|
for date in dates:
|
|
|
|
start = date['start']
|
|
|
|
end = date['end']
|
|
|
|
cr.execute("SELECT (timestamp '%s', timestamp '%s') OVERLAPS\
|
|
|
|
(timestamp '%s', timestamp '%s')" % (event_start, event_end, start, end))
|
|
|
|
over = cr.fetchone()[0]
|
|
|
|
if over:
|
|
|
|
overlaps = True
|
|
|
|
|
|
|
|
# check for attendee added already
|
|
|
|
cr.execute("""select att.user_id , c.id
|
|
|
|
from crm_caldav_attendee att
|
|
|
|
inner join crm_attendee_rel rel on (rel.attendee_id=att.id)
|
|
|
|
join crm_meeting m on (rel.case_id=m.id)
|
|
|
|
join crm_case c on (m.inherit_case_id = c.id )
|
|
|
|
where (c.date, c.date::timestamp + c.duration * interval '1 hour') overlaps\
|
|
|
|
(timestamp '%s', timestamp '%s')""" % (event_start, event_end))
|
|
|
|
added_data = filter(lambda x: x.get('user_id')==id, cr.dictfetchall())
|
|
|
|
if added_data:
|
|
|
|
overlaps = True
|
|
|
|
if overlaps:
|
|
|
|
res[id] = 'busy'
|
|
|
|
else:
|
|
|
|
res[id] = 'free'
|
|
|
|
return res
|
|
|
|
|
|
|
|
_columns = {
|
|
|
|
'availability': fields.function(_get_user_avail, type='selection', \
|
|
|
|
selection=[('free', 'Free'), ('busy', 'Busy')], \
|
|
|
|
string='Free/Busy', method=True),
|
|
|
|
}
|
|
|
|
|
|
|
|
res_users()
|
|
|
|
|
|
|
|
class invite_attendee_wizard(osv.osv_memory):
|
|
|
|
_name = "caldav.invite.attendee"
|
|
|
|
_description = "Invite Attendees"
|
|
|
|
|
|
|
|
_columns = {
|
|
|
|
'users': fields.many2many('res.users', 'invite_user_rel', \
|
|
|
|
'invite_id', 'user_id', 'Users'),
|
|
|
|
'availability': fields.selection([('free', 'Free'), \
|
2010-01-06 10:33:27 +00:00
|
|
|
('busy', 'Busy'), ('both', 'Both')], 'User Avaliability')
|
2010-01-05 13:48:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
_defaults = {
|
|
|
|
'availability': lambda *x: 'free',
|
|
|
|
}
|
|
|
|
|
|
|
|
def do_invite(self, cr, uid, ids, context={}):
|
|
|
|
#TODO: Add attendee
|
|
|
|
return {}
|
|
|
|
|
|
|
|
invite_attendee_wizard()
|
2009-12-29 08:48:04 +00:00
|
|
|
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
|