2009-12-04 08:40:21 +00:00
# -*- encoding: utf-8 -*-
##############################################################################
#
# OpenERP, Open Source Management Solution
# Copyright (C) 2004-2009 Tiny SPRL (<http://tiny.be>). All Rights Reserved
# $Id$
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# 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
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################
from osv import fields , osv
from time import strftime
import time
import base64
import vobject
from dateutil . rrule import *
from dateutil import parser
2009-12-08 14:19:27 +00:00
import datetime
2009-12-04 08:40:21 +00:00
from time import strftime
from pytz import timezone
import tools
[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
from service import web_services
2009-12-11 09:33:59 +00:00
def caldevIDs2readIDs ( caldev_ID = None ) :
if caldev_ID :
2009-12-15 09:19:34 +00:00
if isinstance ( caldev_ID , str ) :
2009-12-11 09:33:59 +00:00
return int ( caldev_ID . split ( ' - ' ) [ 0 ] )
return caldev_ID
2009-12-04 08:40:21 +00:00
2009-12-04 14:15:17 +00:00
class crm_caldav_attendee ( osv . osv ) :
_name = ' crm.caldav.attendee '
2009-12-04 08:40:21 +00:00
_description = ' Attendee information '
_rec_name = ' cutype '
[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
__attribute__ = {
' cutype ' : { ' field ' : ' cutype ' , ' type ' : ' text ' } , # Use: 0-1 Specify the type of calendar user specified by the property like "INDIVIDUAL"/"GROUP"/"RESOURCE"/"ROOM"/"UNKNOWN".
' member ' : { ' field ' : ' member ' , ' type ' : ' text ' } , # Use: 0-1 Specify the group or list membership of the calendar user specified by the property.
2009-12-14 11:07:43 +00:00
' role ' : { ' field ' : ' role ' , ' type ' : ' selection ' } , # Use: 0-1 Specify the participation role for the calendar user specified by the property like "CHAIR"/"REQ-PARTICIPANT"/"OPT-PARTICIPANT"/"NON-PARTICIPANT"
2009-12-04 08:40:21 +00:00
' partstat ' : { ' field ' : ' partstat ' , ' type ' : ' text ' } , # Use: 0-1 Specify the participation status for the calendar user specified by the property. like use for VEVENT :- "NEEDS-ACTION"/"ACCEPTED"/"DECLINED"/"TENTATIVE"/"DELEGATED", use for VTODO :-"NEEDS-ACTION"/"ACCEPTED"/"DECLINED"/"TENTATIVE"/"DELEGATED"/"COMPLETED"/"IN-PROCESS" and use for VJOURNAL :- "NEEDS-ACTION"/"ACCEPTED"/"DECLINED".
' rsvp ' : { ' field ' : ' rsvp ' , ' type ' : ' boolean ' } , # Use: 0-1 Specify whether there is an expectation of a favor of a reply from the calendar user specified by the property value like TRUE / FALSE.
' delegated-to ' : { ' field ' : ' delegated_to ' , ' type ' : ' char ' } , # Use: 0-1 Specify the calendar users to whom the calendar user specified by the property has delegated participation.
' delegated-from ' : { ' field ' : ' delegated_from ' , ' type ' : ' char ' } , # Use: 0-1 Specify the calendar users that have delegated their participation to the calendar user specified by the property.
' sent-by ' : { ' field ' : ' sent_by ' , ' type ' : ' text ' } , # Use: 0-1 Specify the calendar user that is acting on behalf of the calendar user specified by the property.
' cn ' : { ' field ' : ' cn ' , ' type ' : ' text ' } , # Use: 0-1 Specify the common name to be associated with the calendar user specified by the property.
' dir ' : { ' field ' : ' dir ' , ' type ' : ' text ' } , # Use: 0-1 Specify reference to a directory entry associated with the calendar user specified by the property.
' language ' : { ' field ' : ' language ' , ' type ' : ' text ' } , # Use: 0-1 Specify the language for text values in a property or property parameter.
}
[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 = {
' cutype ' : fields . selection ( [ ( ' INDIVIDUAL ' , ' INDIVIDUAL ' ) , ( ' GROUP ' , ' GROUP ' ) , \
( ' RESOURCE ' , ' RESOURCE ' ) , ( ' ROOM ' , ' ROOM ' ) , ( ' UNKNOWN ' , ' UNKNOWN ' ) ] , ' CUTYPE ' ) ,
' member ' : fields . char ( ' Member ' , size = 124 ) ,
' role ' : fields . selection ( [ ( ' CHAIR ' , ' CHAIR ' ) , ( ' REQ-PARTICIPANT ' , ' REQ-PARTICIPANT ' ) , \
( ' OPT-PARTICIPANT ' , ' OPT-PARTICIPANT ' ) , ( ' NON-PARTICIPANT ' , ' NON-PARTICIPANT ' ) ] , ' ROLE ' ) ,
' partstat ' : fields . selection ( [ ( ' NEEDS-ACTION ' , ' NEEDS-ACTION ' ) , ( ' ACCEPTED ' , ' ACCEPTED ' ) , \
2009-12-15 09:19:34 +00:00
( ' DECLINED ' , ' DECLINED ' ) , ( ' TENTATIVE ' , ' TENTATIVE ' ) , \
( ' DELEGATED ' , ' DELEGATED ' ) ] , ' PARTSTAT ' ) ,
2009-12-04 08:40:21 +00:00
' rsvp ' : fields . boolean ( ' RSVP ' ) ,
' delegated_to ' : fields . char ( ' DELEGATED-TO ' , size = 124 ) ,
' delegated_from ' : fields . char ( ' DELEGATED-FROM ' , size = 124 ) ,
' sent_by ' : fields . char ( ' SENT-BY ' , size = 124 ) ,
' cn ' : fields . char ( ' CN ' , size = 124 ) ,
' dir ' : fields . char ( ' DIR ' , size = 124 ) ,
' language ' : fields . char ( ' LANGUAGE ' , size = 124 ) ,
}
2009-12-08 14:19:27 +00:00
_defaults = {
' cn ' : lambda * x : ' MAILTO: ' ,
}
2009-12-04 14:15:17 +00:00
crm_caldav_attendee ( )
2009-12-04 08:40:21 +00:00
2009-12-07 14:02:31 +00:00
class crm_caldav_alarm ( osv . osv ) :
_name = ' crm.caldav.alarm '
_description = ' Event alarm information '
2009-12-15 13:43:55 +00:00
2009-12-07 14:02:31 +00:00
__attribute__ = {
2009-12-15 13:43:55 +00:00
' action ' : { ' field ' : ' action ' , ' type ' : ' text ' } ,
' description ' : { ' field ' : ' name ' , ' type ' : ' text ' } ,
' summary ' : { ' field ' : ' description ' , ' type ' : ' text ' } ,
' attendee ' : { ' field ' : ' attendee ' , ' type ' : ' text ' } ,
2009-12-16 14:16:20 +00:00
' trigger_related ' : { ' field ' : ' trigger_related ' , ' type ' : ' text ' } ,
2009-12-15 13:43:55 +00:00
' trigger_duration ' : { ' field ' : ' trigger_duration ' , ' type ' : ' text ' } ,
' trigger_occurs ' : { ' field ' : ' trigger_occurs ' , ' type ' : ' text ' } ,
' trigger_interval ' : { ' field ' : ' trigger_interval ' , ' type ' : ' text ' } ,
' duration ' : { ' field ' : ' duration ' , ' type ' : ' text ' } ,
' repeat ' : { ' field ' : ' repeat ' , ' type ' : ' text ' } ,
' attach ' : { ' field ' : ' attach ' , ' type ' : ' text ' } ,
2009-12-07 14:02:31 +00:00
}
_columns = {
' name ' : fields . char ( ' Summary ' , size = 124 ) ,
' action ' : fields . selection ( [ ( ' AUDIO ' , ' AUDIO ' ) , ( ' DISPLAY ' , ' DISPLAY ' ) , \
( ' PROCEDURE ' , ' PROCEDURE ' ) , ( ' EMAIL ' , ' EMAIL ' ) ] , ' Action ' , required = True ) ,
' description ' : fields . text ( ' Description ' ) ,
2009-12-15 09:19:34 +00:00
' attendee ' : fields . many2many ( ' crm.caldav.attendee ' , ' alarm_attendee_rel ' , \
' alarm_id ' , ' attendee_id ' , ' Attendees ' ) ,
2009-12-16 14:16:20 +00:00
' trigger_occurs ' : fields . selection ( [ ( ' BEFORE ' , ' BEFORE ' ) , ( ' AFTER ' , ' AFTER ' ) ] \
2009-12-07 14:02:31 +00:00
, ' Trigger time ' , required = True ) ,
2009-12-16 14:16:20 +00:00
' trigger_interval ' : fields . selection ( [ ( ' MINUTES ' , ' MINUTES ' ) , ( ' HOURS ' , ' HOURS ' ) , \
2009-12-07 14:02:31 +00:00
( ' DAYS ' , ' DAYS ' ) ] , ' Trugger duration ' , required = True ) ,
2009-12-16 14:16:20 +00:00
' trigger_duration ' : fields . integer ( ' TIme ' , required = True ) ,
2009-12-17 06:26:30 +00:00
' trigger_related ' : fields . selection ( [ ( ' start ' , ' The event starts ' ) , ( ' end ' , \
2009-12-15 09:19:34 +00:00
' The event ends ' ) ] , ' Trigger Occures at ' , required = True ) ,
2009-12-07 14:02:31 +00:00
' duration ' : fields . integer ( ' Duration ' ) ,
' repeat ' : fields . integer ( ' Repeat ' ) , # TODO
' attach ' : fields . binary ( ' Attachment ' ) ,
2009-12-08 14:19:27 +00:00
' active ' : fields . boolean ( ' Active ' ) ,
2009-12-07 14:02:31 +00:00
}
2009-12-16 06:52:41 +00:00
2009-12-07 14:02:31 +00:00
_defaults = {
' action ' : lambda * x : ' EMAIL ' ,
2009-12-16 14:16:20 +00:00
' trigger_interval ' : lambda * x : ' MINUTES ' ,
' trigger_duration ' : lambda * x : 5 ,
' trigger_occurs ' : lambda * x : ' BEFORE ' ,
2009-12-17 06:26:30 +00:00
' trigger_related ' : lambda * x : ' start ' ,
2009-12-07 14:02:31 +00:00
}
crm_caldav_alarm ( )
2009-12-04 08:40:21 +00:00
class crm_case ( osv . osv ) :
_name = ' crm.case '
_inherit = ' crm.case '
_description = ' Cases '
[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
__attribute__ = {
' 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 ' } ,
[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
#'last-mod' : {'field':'write_date', 'type':'datetime'},
2009-12-04 08:40:21 +00:00
' location ' : { ' field ' : ' location ' , ' type ' : ' text ' } ,
2009-12-15 13:43:55 +00:00
# 'organizer' : {'field':'partner_id', 'sub-field':'name', 'type':'many2one'},
2009-12-04 08:40:21 +00:00
' 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'},
2009-12-14 11:07:43 +00:00
' attendee ' : { ' field ' : ' attendees ' , ' type ' : ' many2many ' , ' object ' : ' crm.caldav.attendee ' } ,
2009-12-04 08:40:21 +00:00
# 'categories' : {'field':'categ_id', 'sub-field':'name'},
# 'categories' : {'field':None , 'sub-field':'name', 'type':'text'}, # keep none for now
' comment ' : None ,
' contact ' : None ,
' exdate ' : None ,
' exrule ' : None ,
' rstatus ' : None ,
' related ' : None ,
' resources ' : None ,
' rdate ' : None ,
' rrule ' : { ' field ' : ' rrule ' , ' type ' : ' text ' } ,
' x-openobject-id ' : { ' field ' : ' id ' , ' type ' : ' text ' } ,
' x-openobject-model ' : { ' value ' : _name , ' type ' : ' text ' } ,
[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
# 'duration' : {'field':'duration'},
2009-12-04 08:40:21 +00:00
' dtend ' : { ' field ' : ' date_closed ' , ' type ' : ' datetime ' } ,
2009-12-15 13:43:55 +00:00
' valarm ' : { ' field ' : ' alarm_id ' , ' type ' : ' many2one ' , ' object ' : ' crm.caldav.alarm ' } ,
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
2009-12-04 08:40:21 +00:00
def _get_location ( self , cr , uid , ids , name , arg , context = None ) :
res = { }
for case in self . browse ( cr , uid , ids ) :
if case . partner_address_id :
add = case . partner_address_id
st = add . street and add . street + ' , \n ' or ' '
st2 = add . street2 and add . street2 + ' , \n ' or ' '
ct = add . city and add . city + ' , \n ' or ' '
zip = add . zip and add . zip or ' '
country = add . country_id and add . country_id . name + ' , \n ' or ' '
res [ case . id ] = st + st2 + ct + country + zip
else :
res [ case . id ] = ' '
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 _get_rdates ( self , cr , uid , ids , name , arg , context = None ) :
res = { }
context . update ( { ' read ' : True } )
for case in self . read ( cr , uid , ids , [ ' date ' , ' rrule ' ] , context = context ) :
if case [ ' rrule ' ] :
rule = case [ ' rrule ' ] . split ( ' \n ' ) [ 0 ]
exdate = case [ ' rrule ' ] . split ( ' \n ' ) [ 1 : ]
event_obj = self . pool . get ( ' caldav.event ' )
res [ case [ ' id ' ] ] = str ( event_obj . get_recurrent_dates ( str ( rule ) , exdate , case [ ' date ' ] ) )
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
_columns = {
' class ' : fields . selection ( [ ( ' PUBLIC ' , ' PUBLIC ' ) , ( ' PRIVATE ' , ' PRIVATE ' ) , \
( ' CONFIDENTIAL ' , ' CONFIDENTIAL ' ) ] , ' Class ' ) ,
2009-12-15 09:19:34 +00:00
' location ' : fields . function ( _get_location , method = True , store = True , \
string = ' Location ' , type = ' text ' ) ,
2009-12-04 08:40:21 +00:00
' freebusy ' : fields . text ( ' FreeBusy ' ) ,
' transparent ' : fields . selection ( [ ( ' OPAQUE ' , ' OPAQUE ' ) , ( ' TRANSPARENT ' , ' TRANSPARENT ' ) ] , ' Trensparent ' ) ,
' caldav_url ' : fields . char ( ' Caldav URL ' , size = 34 ) ,
' rrule ' : fields . text ( ' Recurrent Rule ' ) ,
' rdates ' : fields . function ( _get_rdates , method = True , string = ' Recurrent Dates ' , \
store = True , type = ' text ' ) ,
2009-12-15 09:19:34 +00:00
' attendees ' : fields . many2many ( ' crm.caldav.attendee ' , ' crm_attendee_rel ' , ' case_id ' , \
' attendee_id ' , ' Attendees ' ) ,
' alarm_id ' : fields . many2one ( ' crm.caldav.alarm ' , ' Alarm ' ) ,
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
2009-12-04 08:40:21 +00:00
_defaults = {
' caldav_url ' : lambda * a : ' http://localhost:8080 ' ,
' class ' : lambda * a : ' PUBLIC ' ,
' transparent ' : lambda * a : ' OPAQUE ' ,
}
2009-12-08 14:19:27 +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 :
context = { }
cr . execute ( ' select c.id as id, c.date as date, alarm.id as alarm_id, alarm.name as name, \
alarm . trigger_interval , alarm . trigger_duration , alarm . trigger_related , \
alarm . trigger_occurs from crm_case c \
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 ' )
2009-12-08 14:19:27 +00:00
case_with_alarm = cr . dictfetchall ( )
case_obj = self . pool . get ( ' crm.case ' )
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 )
print ' alarm_time ' , alarm_time
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 :
2009-12-16 06:52:41 +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 :
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 \n Event time: ' \
+ ( case_val . date ) + ' \n \n Location: ' + ( case_val . location or ' ' ) + \
2009-12-08 14:19:27 +00:00
' \n \n Members 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 ' % a larmdata[ ' alarm_id ' ])
cr . commit ( )
return True
2009-12-04 08:40:21 +00:00
def export_cal ( self , cr , uid , ids , context = { } ) :
2009-12-07 14:02:31 +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__ )
attendee_obj = self . pool . get ( ' caldav.attendee ' )
crm_attendee = self . pool . get ( ' crm.caldav.attendee ' )
attendee_obj . __attribute__ . update ( crm_attendee . __attribute__ )
alarm_obj = self . pool . get ( ' caldav.alarm ' )
crm_alarm = self . pool . get ( ' crm.caldav.alarm ' )
alarm_obj . __attribute__ . update ( crm_alarm . __attribute__ )
ical = event_obj . export_ical ( cr , uid , crm_data )
caendar_val = ical . serialize ( )
caendar_val = caendar_val . replace ( ' " ' , ' ' ) . strip ( )
return caendar_val
2009-12-04 08:40:21 +00:00
def import_cal ( self , cr , uid , ids , data , context = { } ) :
file_content = base64 . decodestring ( data [ ' form ' ] [ ' file_path ' ] )
event_obj = self . pool . get ( ' caldav.event ' )
event_obj . __attribute__ . update ( self . __attribute__ )
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__ )
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-04 08:40:21 +00:00
# TODO: Select proper section
section_id = self . pool . get ( ' crm.case.section ' ) . search ( cr , uid , [ ] ) [ 0 ]
vals . update ( { ' section_id ' : section_id } )
vals . pop ( ' id ' )
vals . pop ( ' create_date ' )
case_id = self . create ( cr , uid , vals )
return
def search ( self , cr , uid , args , offset = 0 , limit = None , order = None ,
context = None , count = False ) :
res = super ( crm_case , self ) . search ( cr , uid , args , offset ,
limit , order , context , count )
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 write ( self , cr , uid , ids , vals , context = None ) :
[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 = [ ]
for id in ids :
2009-12-11 09:33:59 +00:00
id = caldevIDs2readIDs ( 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 )
if ' case_id ' in vals :
2009-12-11 09:33:59 +00:00
vals [ ' case_id ' ] = caldevIDs2readIDs ( vals [ ' case_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
res = super ( crm_case , 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-04 08:40:21 +00:00
def browse ( self , cr , uid , select , context = None , list_class = None , fields_process = { } ) :
2009-12-15 09:19:34 +00:00
if not isinstance ( select , list ) : select = [ select ]
2009-12-11 09:33:59 +00:00
select = map ( lambda x : caldevIDs2readIDs ( x ) , select )
2009-12-04 08:40:21 +00:00
return super ( crm_case , self ) . browse ( cr , uid , select , context , list_class , fields_process )
def read ( self , cr , uid , ids , fields = None , context = { } ,
load = ' _classic_read ' ) :
""" logic for recurrent event
example : 123 - 20091111170822 """
if context and context . has_key ( ' read ' ) :
2009-12-15 09:19:34 +00:00
return super ( crm_case , self ) . read ( cr , uid , ids , fields = fields , context = context , \
load = load )
2009-12-04 14:15:17 +00:00
if not type ( ids ) == list :
# Called from code
2009-12-15 09:19:34 +00:00
return super ( crm_case , self ) . read ( cr , uid , caldevIDs2readIDs ( ids ) , fields = fields , \
context = context , load = load )
2009-12-04 14:15:17 +00:00
else :
2009-12-11 09:33:59 +00:00
ids = map ( lambda x : caldevIDs2readIDs ( x ) , ids )
2009-12-04 08:40:21 +00:00
res = super ( crm_case , self ) . read ( cr , uid , ids , fields = fields , context = context , load = load )
read_ids = " , " . join ( [ str ( x ) for x in ids ] )
2009-12-09 04:47:34 +00:00
if not read_ids :
return [ ]
2009-12-04 08:40:21 +00:00
cr . execute ( ' select id,rrule,rdates from crm_case where id in ( %s ) ' % read_ids )
rrules = filter ( lambda x : not x [ ' rrule ' ] == None , cr . dictfetchall ( ) )
rdates = [ ]
2009-12-04 14:15:17 +00:00
if not rrules :
return res
result = res + [ ]
2009-12-04 08:40:21 +00:00
for data in rrules :
if data [ ' rrule ' ] and data [ ' rdates ' ] : # delete 2nd condition at last
rdates = eval ( data [ ' rdates ' ] )
for res_temp in res :
if res_temp [ ' id ' ] == data [ ' id ' ] :
val = res_temp
if rdates :
result . remove ( val )
for rdate in rdates :
import re
idval = ( re . compile ( ' \ d ' ) ) . findall ( rdate )
val [ ' date ' ] = rdate
id = str ( val [ ' id ' ] ) . split ( ' - ' ) [ 0 ]
val [ ' id ' ] = id + ' - ' + ' ' . join ( idval )
val1 = val . copy ( )
result + = [ val1 ]
[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
def copy ( self , cr , uid , id , default = None , context = { } ) :
2009-12-11 09:33:59 +00:00
return super ( crm_case , self ) . copy ( cr , uid , caldevIDs2readIDs ( id ) , 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 ) :
#TODO: Change RRULE
for id in ids :
if len ( str ( id ) . split ( ' - ' ) ) > 1 :
2009-12-15 09:19:34 +00:00
date_new = time . strftime ( " % Y- % m- %d % H: % M: % S " , \
time . strptime ( str ( str ( id ) . split ( ' - ' ) [ 1 ] ) , " % Y % m %d % H % M % S " ) )
2009-12-11 09:33:59 +00:00
for record in self . read ( cr , uid , [ caldevIDs2readIDs ( id ) ] , [ ' date ' , ' rdates ' , ' rrule ' ] ) :
2009-12-04 08:40:21 +00:00
if record [ ' date ' ] == date_new :
2009-12-15 09:19:34 +00:00
self . write ( cr , uid , [ caldevIDs2readIDs ( id ) ] , \
{ ' rrule ' : record [ ' rrule ' ] + " \n " + str ( date_new ) } )
2009-12-04 08:40:21 +00:00
else :
return super ( crm_case , 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 :
2009-12-11 09:33:59 +00:00
vals [ ' case_id ' ] = caldevIDs2readIDs ( vals [ ' case_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
return super ( crm_case , self ) . create ( cr , uid , vals , context )
2009-12-04 08:40:21 +00:00
crm_case ( )
class ir_attachment ( osv . osv ) :
_name = ' ir.attachment '
_inherit = ' ir.attachment '
def search_count ( self , cr , user , args , context = None ) :
args1 = [ ]
for arg in args :
args1 . append ( map ( lambda x : str ( x ) . split ( ' - ' ) [ 0 ] , arg ) )
return super ( ir_attachment , self ) . search_count ( cr , user , args1 , context )
2009-12-15 09:19:34 +00:00
def search ( self , cr , uid , args , offset = 0 , limit = None , order = None ,
[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
context = None , count = False ) :
new_args = [ ]
if len ( args ) > 1 :
new_args = [ args [ 0 ] ]
if args [ 1 ] [ 0 ] == ' res_id ' :
2009-12-15 09:19:34 +00:00
new_args . append ( ( args [ 1 ] [ 0 ] , args [ 1 ] [ 1 ] , caldevIDs2readIDs ( args [ 1 ] [ 2 ] ) ) )
[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 new_args :
args = new_args
2009-12-15 09:19:34 +00:00
return super ( ir_attachment , self ) . search ( cr , uid , args , offset = offset ,
limit = limit , order = order ,
[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
context = context , count = False )
2009-12-04 08:40:21 +00:00
ir_attachment ( )
[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
class ir_values ( osv . osv ) :
_inherit = ' ir.values '
2009-12-15 09:19:34 +00:00
def set ( self , cr , uid , key , key2 , name , models , value , replace = True , isobject = False , \
meta = False , preserve_user = False , company = 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
new_model = [ ]
for data in models :
2009-12-15 09:19:34 +00:00
if type ( data ) in ( list , tuple ) :
new_model . append ( ( data [ 0 ] , caldevIDs2readIDs ( data [ 1 ] ) ) )
[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
else :
new_model . append ( data )
2009-12-15 09:19:34 +00:00
return super ( ir_values , self ) . set ( cr , uid , key , key2 , name , new_model , value , \
replace , isobject , meta , preserve_user , company )
[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-15 09:19:34 +00:00
def get ( self , cr , uid , key , key2 , models , meta = False , context = { } , res_id_req = False , \
without_user = True , key2_req = True ) :
[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_model = [ ]
for data in models :
2009-12-15 09:19:34 +00:00
if type ( data ) in ( list , tuple ) :
new_model . append ( ( data [ 0 ] , caldevIDs2readIDs ( data [ 1 ] ) ) )
[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
else :
new_model . append ( data )
2009-12-15 09:19:34 +00:00
return super ( ir_values , self ) . get ( cr , uid , key , key2 , new_model , meta , context , \
res_id_req , without_user , key2_req )
[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
ir_values ( )
2009-12-11 09:33:59 +00:00
class ir_model ( osv . osv ) :
2009-12-15 09:19:34 +00:00
2009-12-11 09:33:59 +00:00
_inherit = ' ir.model '
2009-12-15 09:19:34 +00:00
def read ( self , cr , uid , ids , fields = None , context = { } ,
2009-12-11 09:33:59 +00:00
load = ' _classic_read ' ) :
data = super ( ir_model , self ) . read ( cr , uid , ids , fields = fields , context = context , load = load )
if data :
for val in data :
val [ ' id ' ] = caldevIDs2readIDs ( val [ ' id ' ] )
return data
2009-12-15 09:19:34 +00:00
ir_model ( )
2009-12-11 09:33:59 +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
class virtual_report_spool ( web_services . report_spool ) :
2009-12-15 09:19:34 +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 exp_report ( self , db , uid , object , ids , datas = None , context = None ) :
2009-12-11 09:33:59 +00:00
if object == ' printscreen.list ' :
2009-12-15 09:19:34 +00:00
return super ( virtual_report_spool , self ) . exp_report ( db , uid , object , ids , datas , 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
new_ids = [ ]
for id in ids :
2009-12-11 09:33:59 +00:00
new_ids . append ( caldevIDs2readIDs ( id ) )
datas [ ' id ' ] = caldevIDs2readIDs ( datas [ ' id ' ] )
2009-12-15 09:19:34 +00:00
super ( virtual_report_spool , self ) . exp_report ( db , uid , object , new_ids , datas , context )
return super ( virtual_report_spool , self ) . exp_report ( db , uid , object , new_ids , datas , 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
virtual_report_spool ( )
class virtual_wizard ( web_services . wizard ) :
def exp_execute ( self , db , uid , wiz_id , datas , action = ' init ' , context = None ) :
2009-12-17 06:17:00 +00:00
if wiz_id not in self . wiz_uid :
2009-12-18 10:25:13 +00:00
# TODO : To Check why need it
if wiz_id == 1 :
wiz_name = ' base_setup.base_setup '
if wiz_id == 2 :
wiz_name = ' module.upgrade '
super ( virtual_wizard , self ) . exp_create ( db , uid , wiz_name , datas )
[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 = [ ]
if ' id ' in datas :
2009-12-11 09:33:59 +00:00
datas [ ' id ' ] = caldevIDs2readIDs ( datas [ ' 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
for id in datas [ ' ids ' ] :
2009-12-11 09:33:59 +00:00
new_ids . append ( caldevIDs2readIDs ( 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
datas [ ' ids ' ] = new_ids
2009-12-15 09:19:34 +00:00
res = super ( virtual_wizard , self ) . exp_execute ( db , uid , wiz_id , datas , action , 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
return res
2009-12-15 09:19:34 +00:00
2009-12-18 10:25:13 +00:00
virtual_wizard ( )