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
|
2010-01-12 09:18:39 +00:00
|
|
|
# Copyright (C) 2004-2010 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
|
2010-01-12 12:06:53 +00:00
|
|
|
from datetime import datetime, timedelta
|
|
|
|
from dateutil import parser
|
2009-12-22 13:14:25 +00:00
|
|
|
from osv import fields, osv
|
2010-01-12 12:06:53 +00:00
|
|
|
from tools.translate import _
|
2009-12-22 13:14:25 +00:00
|
|
|
import base64
|
|
|
|
import re
|
[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-12 09:40:08 +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-12 09:40:08 +00:00
|
|
|
_inherit = "crm.case"
|
|
|
|
|
2009-12-04 08:40:21 +00:00
|
|
|
__attribute__ = {
|
2010-01-12 09:40:08 +00:00
|
|
|
'class': {'field': 'class', 'type': 'selection'},
|
|
|
|
'created': {'field': 'create_date', 'type': 'datetime'},
|
|
|
|
'description': {'field': 'description', 'type': 'text'},
|
|
|
|
'dtstart': {'field': 'date', 'type': 'datetime'},
|
|
|
|
'location': {'field': 'location', 'type': 'text'},
|
2010-01-05 09:37:58 +00:00
|
|
|
#'organizer': {'field': 'partner_id', 'sub-field': 'name', 'type': 'many2one'},
|
2010-01-12 09:40:08 +00:00
|
|
|
'priority': {'field': 'priority', 'type': 'int'},
|
2010-01-12 12:06:53 +00:00
|
|
|
'dtstamp': {'field': 'date', 'type': 'datetime'},
|
2010-01-12 09:40:08 +00:00
|
|
|
'seq': None,
|
2010-01-12 12:06:53 +00:00
|
|
|
'status': {'field': 'state', 'type': 'selection', 'mapping': \
|
|
|
|
{'tentative': 'draft', 'confirmed': 'open', \
|
|
|
|
'cancelled': 'cancel'}},
|
2010-01-12 09:40:08 +00:00
|
|
|
'summary': {'field': 'name', 'type': 'text'},
|
|
|
|
'transp': {'field': 'transparent', 'type': 'text'},
|
|
|
|
'uid': {'field': 'id', 'type': 'text'},
|
|
|
|
'url': {'field': 'caldav_url', 'type': 'text'},
|
2010-01-18 09:54:36 +00:00
|
|
|
'recurrence-id': {'field': 'recurrent_id', 'type': 'datetime'},
|
2010-01-13 13:29:33 +00:00
|
|
|
'attendee': {'field': 'attendee_ids', 'type': 'many2many', 'object': 'calendar.attendee'},
|
2010-01-19 05:25:39 +00:00
|
|
|
'categories': {'field': 'categ_id', 'type': 'many2one', 'object': 'crm.case.categ'},
|
2010-01-12 09:40:08 +00:00
|
|
|
'comment': None,
|
|
|
|
'contact': None,
|
2010-01-12 12:06:53 +00:00
|
|
|
'exdate': {'field': 'exdate', 'type': 'datetime'},
|
|
|
|
'exrule': {'field': 'exrule', 'type': 'text'},
|
2010-01-12 09:40:08 +00:00
|
|
|
'rstatus': None,
|
|
|
|
'related': None,
|
|
|
|
'resources': None,
|
|
|
|
'rdate': None,
|
|
|
|
'rrule': {'field': 'rrule', 'type': 'text'},
|
|
|
|
'x-openobject-model': {'value': _name, 'type': 'text'},
|
|
|
|
'dtend': {'field': 'date_deadline', 'type': 'datetime'},
|
|
|
|
'valarm': {'field': 'caldav_alarm_id', 'type': 'many2one', 'object': 'calendar.alarm'},
|
2010-01-08 14:38:24 +00:00
|
|
|
}
|
2010-01-09 13:55:38 +00:00
|
|
|
|
2010-01-12 09:40:08 +00:00
|
|
|
def _get_duration(self, cr, uid, ids, name, arg, context):
|
|
|
|
res = {}
|
2010-01-12 12:06:53 +00:00
|
|
|
for meeting in self.browse(cr, uid, ids, context=context):
|
|
|
|
start = datetime.strptime(meeting.date, "%Y-%m-%d %H:%M:%S")
|
|
|
|
end = datetime.strptime(meeting.date_deadline[:19], "%Y-%m-%d %H:%M:%S")
|
2010-01-12 09:40:08 +00:00
|
|
|
diff = end - start
|
|
|
|
duration = float(diff.days)* 24 + (float(diff.seconds) / 3600)
|
2010-01-12 12:06:53 +00:00
|
|
|
res[meeting.id] = round(duration, 2)
|
2010-01-12 09:40:08 +00:00
|
|
|
return res
|
2010-01-12 12:06:53 +00:00
|
|
|
|
2010-01-12 09:40:08 +00:00
|
|
|
def _set_duration(self, cr, uid, id, name, value, arg, context):
|
|
|
|
meeting = self.browse(cr, uid, id, context=context)
|
2010-01-12 12:06:53 +00:00
|
|
|
start = datetime.strptime(meeting.date, "%Y-%m-%d %H:%M:%S")
|
|
|
|
end = start + timedelta(hours=value)
|
2010-01-12 09:40:08 +00:00
|
|
|
cr.execute("UPDATE crm_meeting set date_deadline='%s' \
|
2010-01-12 12:06:53 +00:00
|
|
|
where id=%s"% (end.strftime("%Y-%m-%d %H:%M:%S"), id))
|
2010-01-08 14:38:24 +00:00
|
|
|
return True
|
2010-01-12 12:06:53 +00:00
|
|
|
|
2010-01-18 09:54:36 +00:00
|
|
|
def onchange_rrule_type(self, cr, uid, ids, rtype, *args, **argv):
|
|
|
|
if rtype == 'none' or not rtype:
|
2010-01-12 12:06:53 +00:00
|
|
|
return {'value': {'rrule': ''}}
|
2010-01-18 09:54:36 +00:00
|
|
|
if rtype == 'custom':
|
2010-01-12 12:06:53 +00:00
|
|
|
return {}
|
|
|
|
rrule = self.pool.get('calendar.custom.rrule')
|
2010-01-18 09:54:36 +00:00
|
|
|
rrulestr = rrule.compute_rule_string(cr, uid, {'freq': rtype.upper(), \
|
2010-01-12 12:06:53 +00:00
|
|
|
'interval': 1})
|
|
|
|
return {'value': {'rrule': rrulestr}}
|
|
|
|
|
2009-12-04 08:40:21 +00:00
|
|
|
_columns = {
|
2010-01-13 10:35:36 +00:00
|
|
|
'id': fields.integer('ID', readonly=True),
|
2010-01-12 12:06:53 +00:00
|
|
|
'name': fields.char('Description', size=64, required=True),
|
|
|
|
'section_id': fields.many2one('crm.case.section', 'Section', select=True, help='Section to which Case belongs to. Define Responsible user and Email \
|
|
|
|
account for mail gateway.'),
|
2010-01-13 10:35:36 +00:00
|
|
|
'priority': fields.selection([('5','Lowest'),
|
|
|
|
('4','Low'),
|
|
|
|
('3','Normal'),
|
|
|
|
('2','High'),
|
|
|
|
('1','Highest')
|
|
|
|
], 'Priority'),
|
2010-01-12 12:06:53 +00:00
|
|
|
'date': fields.datetime('Date'),
|
|
|
|
'date_deadline': fields.datetime('Deadline'),
|
2010-01-12 09:40:08 +00:00
|
|
|
'duration': fields.function(_get_duration, method=True, \
|
|
|
|
fnct_inv=_set_duration, string='Duration'),
|
2010-01-18 10:03:52 +00:00
|
|
|
'categ_id': fields.many2one('crm.case.categ', 'Category', \
|
2010-01-19 05:25:39 +00:00
|
|
|
domain="[('section_id','=',section_id),('object_id.model', '=', 'crm.meeting')]", \
|
2010-01-12 09:40:08 +00:00
|
|
|
help='Category related to the section.Subdivide the CRM cases \
|
|
|
|
independently or section-wise.'),
|
2010-01-12 12:06:53 +00:00
|
|
|
'description': fields.text('Your action'),
|
2010-01-06 06:16:37 +00:00
|
|
|
'class': fields.selection([('public', 'Public'), ('private', 'Private'), \
|
2010-01-12 09:40:08 +00:00
|
|
|
('confidential', 'Confidential')], 'Mark as'),
|
2010-01-12 12:06:53 +00:00
|
|
|
'location': fields.char('Location', size=264, help="Location of Meeting"),
|
2010-01-06 06:16:37 +00:00
|
|
|
'show_as': fields.selection([('free', 'Free'), \
|
2010-01-12 09:40:08 +00:00
|
|
|
('busy', 'Busy')],
|
|
|
|
'Show as'),
|
|
|
|
'caldav_url': fields.char('Caldav URL', size=264),
|
2010-01-12 12:06:53 +00:00
|
|
|
'exdate': fields.text('Exception Date/Times', help="This property \
|
|
|
|
defines the list of date/time exceptions for arecurring calendar component."),
|
|
|
|
'exrule': fields.char('Exception Rule', size=352, help="defines a \
|
|
|
|
rule or repeating pattern for anexception to a recurrence set"),
|
|
|
|
'rrule': fields.char('Recurrent Rule', size=124),
|
|
|
|
'rrule_type': fields.selection([('none', 'None'), ('daily', 'Daily'), \
|
|
|
|
('weekly', 'Weekly'), ('monthly', 'Monthly'), \
|
|
|
|
('yearly', 'Yearly'), ('custom', 'Custom')], 'Recurrency'),
|
2010-01-13 10:35:36 +00:00
|
|
|
'attendee_ids': fields.many2many('calendar.attendee', 'crm_attendee_rel', 'case_id', 'attendee_id', 'Attendees'),
|
2010-01-12 09:40:08 +00:00
|
|
|
'alarm_id': fields.many2one('res.alarm', 'Alarm'),
|
|
|
|
'caldav_alarm_id': fields.many2one('calendar.alarm', 'Alarm'),
|
2010-01-18 09:54:36 +00:00
|
|
|
'recurrent_uid': fields.integer('Recurrent ID'),
|
|
|
|
'recurrent_id': fields.datetime('Recurrent ID date'),
|
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-12 09:40:08 +00:00
|
|
|
'class': lambda *a: 'public',
|
2010-01-12 12:06:53 +00:00
|
|
|
'show_as': lambda *a: 'busy',
|
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 {}
|
2010-01-12 12:06:53 +00:00
|
|
|
start_date = datetime.strptime(date, "%Y-%m-%d %H:%M:%S")
|
|
|
|
if duration >= 0:
|
2010-01-06 06:16:37 +00:00
|
|
|
end = start_date + datetime.timedelta(hours=duration)
|
|
|
|
if duration < 0:
|
2010-01-12 12:06:53 +00:00
|
|
|
raise osv.except_osv(_('Warning !'),
|
2010-01-06 06:16:37 +00:00
|
|
|
_('You can not set negative Duration.'))
|
2010-01-12 12:06:53 +00:00
|
|
|
res = {'value': {'date_deadline': end.strftime('%Y-%m-%d %H:%M:%S')}}
|
2010-01-06 06:16:37 +00:00
|
|
|
return res
|
2010-01-05 09:30:49 +00:00
|
|
|
|
2009-12-04 08:40:21 +00:00
|
|
|
def export_cal(self, cr, uid, ids, context={}):
|
2010-01-12 12:06:53 +00:00
|
|
|
ids = map(lambda x: common.caldav_id2real_id(x), ids)
|
2010-01-08 14:38:24 +00:00
|
|
|
crm_data = self.read(cr, uid, ids)
|
2010-01-07 13:40:14 +00:00
|
|
|
event_obj = self.pool.get('basic.calendar.event')
|
2009-12-16 14:16:20 +00:00
|
|
|
event_obj.__attribute__.update(self.__attribute__)
|
2010-01-18 09:54:36 +00:00
|
|
|
ical = event_obj.export_ical(cr, uid, crm_data, context={'model': self._name})
|
2010-01-08 14:38:24 +00:00
|
|
|
cal_val = ical.serialize()
|
|
|
|
cal_val = cal_val.replace('"', '').strip()
|
|
|
|
return cal_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)
|
2010-01-07 13:40:14 +00:00
|
|
|
event_obj = self.pool.get('basic.calendar.event')
|
2010-01-09 13:55:38 +00:00
|
|
|
event_obj.__attribute__.update(self.__attribute__)
|
2010-01-13 10:35:36 +00:00
|
|
|
|
|
|
|
attendee_obj = self.pool.get('basic.calendar.attendee')
|
|
|
|
attendee = self.pool.get('calendar.attendee')
|
|
|
|
attendee_obj.__attribute__.update(attendee.__attribute__)
|
|
|
|
|
|
|
|
alarm_obj = self.pool.get('basic.calendar.alarm')
|
|
|
|
alarm = self.pool.get('calendar.alarm')
|
|
|
|
alarm_obj.__attribute__.update(alarm.__attribute__)
|
2010-01-09 13:55:38 +00:00
|
|
|
|
2009-12-14 11:07:43 +00:00
|
|
|
vals = event_obj.import_ical(cr, uid, file_content)
|
2010-01-08 14:38:24 +00:00
|
|
|
ids = []
|
2010-01-08 11:05:05 +00:00
|
|
|
for val in vals:
|
2010-01-18 11:07:30 +00:00
|
|
|
exists, r_id = common.uid2openobjectid(cr, val['id'], self._name, \
|
|
|
|
val.get('recurrent_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 ''
|
2010-01-08 07:02:15 +00:00
|
|
|
val.pop('id')
|
2010-01-18 11:07:30 +00:00
|
|
|
if exists and r_id:
|
|
|
|
val.update({'recurrent_uid': exists})
|
|
|
|
self.write(cr, uid, [r_id], val)
|
|
|
|
ids.append(r_id)
|
|
|
|
elif exists:
|
|
|
|
self.write(cr, uid, [exists], val)
|
|
|
|
ids.append(exists)
|
2009-12-24 13:35:49 +00:00
|
|
|
else:
|
2010-01-09 13:55:38 +00:00
|
|
|
case_id = self.create(cr, uid, val)
|
|
|
|
ids.append(case_id)
|
2010-01-08 14:38:24 +00:00
|
|
|
return ids
|
2009-12-04 08:40:21 +00:00
|
|
|
|
2010-01-11 13:48:18 +00:00
|
|
|
def get_recurrent_ids(self, cr, uid, select, base_start_date, base_until_date, limit=100):
|
2010-01-04 14:37:51 +00:00
|
|
|
if not limit:
|
2010-01-08 09:33:24 +00:00
|
|
|
limit = 100
|
2010-01-11 13:48:18 +00:00
|
|
|
if isinstance(select, (str, int, long)):
|
|
|
|
ids = [select]
|
|
|
|
else:
|
|
|
|
ids = select
|
2010-01-12 05:54:07 +00:00
|
|
|
result = []
|
2010-01-09 12:25:26 +00:00
|
|
|
if ids and (base_start_date or base_until_date):
|
2010-01-12 12:06:53 +00:00
|
|
|
cr.execute("select m.id, m.rrule, m.date, m.exdate \
|
|
|
|
from crm_meeting m\
|
2010-01-05 09:37:58 +00:00
|
|
|
where m.id in ("+ ','.join(map(lambda x: str(x), ids))+")")
|
2010-01-11 13:48:18 +00:00
|
|
|
|
2010-01-09 13:55:38 +00:00
|
|
|
count = 0
|
2010-01-09 12:25:26 +00:00
|
|
|
for data in cr.dictfetchall():
|
2010-01-12 12:06:53 +00:00
|
|
|
start_date = base_start_date and datetime.strptime(base_start_date, "%Y-%m-%d") or False
|
|
|
|
until_date = base_until_date and datetime.strptime(base_until_date, "%Y-%m-%d") or False
|
2010-01-04 14:37:51 +00:00
|
|
|
if count > limit:
|
2010-01-05 09:30:49 +00:00
|
|
|
break
|
2010-01-12 12:06:53 +00:00
|
|
|
event_date = 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-09 12:25:26 +00:00
|
|
|
if start_date and event_date < start_date:
|
|
|
|
continue
|
|
|
|
if until_date and event_date > until_date:
|
|
|
|
continue
|
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 []
|
2010-01-07 13:40:14 +00:00
|
|
|
event_obj = self.pool.get('basic.calendar.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
|
2010-01-07 14:35:43 +00:00
|
|
|
is_until = False
|
2010-01-04 14:37:51 +00:00
|
|
|
for rule in rrule_str.split(';'):
|
|
|
|
name, value = rule.split('=')
|
|
|
|
if name == "UNTIL":
|
2010-01-07 14:35:43 +00:00
|
|
|
is_until = True
|
2010-01-04 14:37:51 +00:00
|
|
|
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:
|
2010-01-09 13:55:38 +00:00
|
|
|
value = until_date.strftime("%Y%m%d%H%M%S")
|
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)
|
2010-01-09 13:55:38 +00:00
|
|
|
if not is_until and until_date:
|
|
|
|
value = until_date.strftime("%Y%m%d%H%M%S")
|
2010-01-07 14:35:43 +00:00
|
|
|
name = "UNTIL"
|
|
|
|
new_rule = '%s=%s' % (name, value)
|
|
|
|
new_rrule_str.append(new_rule)
|
2010-01-04 14:37:51 +00:00
|
|
|
new_rrule_str = ';'.join(new_rrule_str)
|
2010-01-12 12:06:53 +00:00
|
|
|
start_date = 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-12 12:06:53 +00:00
|
|
|
r_date = datetime.strptime(rdate, "%Y-%m-%d %H:%M:%S")
|
2010-01-09 12:25:26 +00:00
|
|
|
if start_date and r_date < start_date:
|
|
|
|
continue
|
|
|
|
if until_date and r_date > until_date:
|
|
|
|
continue
|
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-12 06:06:10 +00:00
|
|
|
if result:
|
|
|
|
ids = result
|
2010-01-11 13:48:18 +00:00
|
|
|
if isinstance(select, (str, int, long)):
|
2010-01-12 06:06:10 +00:00
|
|
|
return ids and ids[0] or False
|
|
|
|
return ids
|
2010-01-04 14:37:51 +00:00
|
|
|
|
2010-01-18 09:54:36 +00:00
|
|
|
def modify_this(self, cr, uid, ids, defaults, context=None, *args):
|
|
|
|
datas = self.read(cr, uid, ids[0], context=context)
|
|
|
|
date = datas.get('date')
|
|
|
|
defaults.update({
|
|
|
|
'recurrent_uid': common.caldav_id2real_id(datas['id']),
|
|
|
|
'recurrent_id': defaults.get('date'),
|
|
|
|
'rrule_type': 'none',
|
|
|
|
'rrule': ''
|
|
|
|
})
|
|
|
|
new_id = self.copy(cr, uid, ids[0], default=defaults, context=context)
|
|
|
|
return new_id
|
|
|
|
|
2010-01-12 12:06:53 +00:00
|
|
|
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 ('<', '<='):
|
2010-01-09 13:55:38 +00:00
|
|
|
until_date = arg[2]
|
2010-01-12 12:06:53 +00:00
|
|
|
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-09 13:55:38 +00:00
|
|
|
return self.get_recurrent_ids(cr, uid, res, start_date, until_date, limit)
|
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-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)
|
2009-12-29 08:48:04 +00:00
|
|
|
res = super(crm_meeting, self).write(cr, uid, new_ids, vals, context=context)
|
2010-01-13 11:22:22 +00:00
|
|
|
if vals.get('alarm_id'):
|
2010-01-13 13:29:33 +00:00
|
|
|
alarm_obj = self.pool.get('res.alarm')
|
|
|
|
alarm_obj.do_alarm_create(cr, uid, new_ids, self._name, 'date')
|
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-12 12:06:53 +00:00
|
|
|
res = super(crm_meeting, self).copy(cr, uid, common.caldav_id2real_id(id), default, context)
|
2010-01-13 13:29:33 +00:00
|
|
|
alarm_obj = self.pool.get('res.alarm')
|
|
|
|
alarm_obj.do_alarm_create(cr, uid, [res], self._name, 'date')
|
2010-01-07 11:51:55 +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-04 08:40:21 +00:00
|
|
|
def unlink(self, cr, uid, ids, context=None):
|
2010-01-07 11:51:55 +00:00
|
|
|
res = False
|
2009-12-04 08:40:21 +00:00
|
|
|
for id in ids:
|
2010-01-06 13:19:46 +00:00
|
|
|
ls = common.caldav_id2real_id(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-07 11:51:55 +00:00
|
|
|
res = 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-07 11:51:55 +00:00
|
|
|
res = super(crm_meeting, self).unlink(cr, uid, common.caldav_id2real_id(ids))
|
2010-01-18 07:01:27 +00:00
|
|
|
alarm_obj = self.pool.get('res.alarm')
|
|
|
|
alarm_obj.do_alarm_unlink(cr, uid, ids, self._name)
|
2009-12-04 08:40:21 +00:00
|
|
|
else:
|
2010-01-13 10:35:36 +00:00
|
|
|
ids = map(lambda x: common.caldav_id2real_id(x), ids)
|
2010-01-07 11:51:55 +00:00
|
|
|
res = super(crm_meeting, self).unlink(cr, uid, ids)
|
2010-01-18 07:01:27 +00:00
|
|
|
alarm_obj = self.pool.get('res.alarm')
|
|
|
|
alarm_obj.do_alarm_unlink(cr, uid, ids, self._name)
|
2010-01-07 11:51:55 +00:00
|
|
|
return res
|
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={}):
|
2010-01-07 11:51:55 +00:00
|
|
|
res = super(crm_meeting, self).create(cr, uid, vals, context)
|
2010-01-13 13:29:33 +00:00
|
|
|
alarm_obj = self.pool.get('res.alarm')
|
|
|
|
alarm_obj.do_alarm_create(cr, uid, [res], self._name, 'date')
|
2010-01-07 11:51:55 +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
|
|
|
crm_meeting()
|
2009-12-04 08:40:21 +00:00
|
|
|
|
2010-01-05 13:48:22 +00:00
|
|
|
class res_users(osv.osv):
|
|
|
|
_inherit = 'res.users'
|
2010-01-08 14:38:24 +00:00
|
|
|
def _get_user_avail(self, cr, uid, ids, context=None):
|
2010-01-12 12:06:53 +00:00
|
|
|
current_datetime = datetime.now().strftime('%Y-%m-%d %H:%M:%S')
|
2010-01-08 14:38:24 +00:00
|
|
|
res = super(res_users, self)._get_user_avail(cr, uid, ids, context)
|
2010-01-12 09:40:08 +00:00
|
|
|
cr.execute("SELECT m.user_id, 'busy' as status \
|
|
|
|
FROM crm_meeting m\
|
|
|
|
where m.date <= %s and m.date_deadline >= %s \
|
2010-01-12 12:06:53 +00:00
|
|
|
and m.user_id = ANY(%s) and m.show_as = %s",
|
|
|
|
(current_datetime, current_datetime, ids, 'busy'))
|
2010-01-08 14:38:24 +00:00
|
|
|
result = cr.dictfetchall()
|
|
|
|
for user_data in result:
|
|
|
|
user_id = user_data['user_id']
|
|
|
|
status = user_data['status']
|
2010-01-09 13:55:38 +00:00
|
|
|
res.update({user_id:status})
|
2010-01-05 13:48:22 +00:00
|
|
|
return res
|
|
|
|
res_users()
|
2010-01-12 09:40:08 +00:00
|
|
|
|
2009-12-29 08:48:04 +00:00
|
|
|
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
|