From e0d5d2e12028a401c4a4c38ecc07acaef47b8dd4 Mon Sep 17 00:00:00 2001 From: "nch@tinyerp.com" <> Date: Thu, 10 Dec 2009 18:00:23 +0530 Subject: [PATCH 1/4] [FIX]:invalid timezone arg problem bzr revid: nch@tinyerp.com-20091210123023-15fh9ule6o4803hn --- addons/caldav/calendar.py | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/addons/caldav/calendar.py b/addons/caldav/calendar.py index 60d0a650a79..b7b80005564 100644 --- a/addons/caldav/calendar.py +++ b/addons/caldav/calendar.py @@ -109,7 +109,7 @@ class Calendar(CalDAV, osv.osv_memory): elif child_name == "vtimezone": timezone = Timezone() timezone.import_ical(cr, uid, child) - return True + return True def export_ical(self, cr, uid, ids): # Read openobject data in ical format @@ -182,7 +182,7 @@ class Event(CalDAV, osv.osv_memory): 'transp' : None, # Use: O-1, Type: TEXT, Defines whether an event is transparent or not to busy time searches. 'uid' : None, # Use: O-1, Type: TEXT, Defines the persistent, globally unique identifier for the calendar component. 'url' : None, # Use: O-1, Type: URL, Defines a Uniform Resource Locator (URL) associated with the iCalendar object. - 'recurid' : None, + 'recurid' : None, 'attach' : None, # Use: O-n, Type: BINARY, Provides the capability to associate a document object with a calendar component. 'attendee' : None, # Use: O-n, Type: CAL-ADDRESS, Defines an "Attendee" within a calendar component. 'categories' : None, # Use: O-n, Type: TEXT, Defines the categories for a calendar component. @@ -190,13 +190,13 @@ class Event(CalDAV, osv.osv_memory): 'contact' : None, # Use: O-n, Type: TEXT, Used to represent contact information or alternately a reference to contact information associated with the calendar component. 'exdate' : None, # Use: O-n, Type: DATE-TIME, Defines the list of date/time exceptions for a recurring calendar component. 'exrule' : None, # Use: O-n, Type: RECUR, Defines a rule or repeating pattern for an exception to a recurrence set. - 'rstatus' : None, + 'rstatus' : None, 'related' : None, # Use: O-n, Specify the relationship of the alarm trigger with respect to the start or end of the calendar component. # like A trigger set 5 minutes after the end of the event or to-do.---> TRIGGER;RELATED=END:PT5M 'resources' : None, # Use: O-n, Type: TEXT, Defines the equipment or resources anticipated for an activity specified by a calendar entity like RESOURCES:EASEL,PROJECTOR,VCR, LANGUAGE=fr:1 raton-laveur 'rdate' : None, # Use: O-n, Type: DATE-TIME, Defines the list of date/times for a recurrence set. 'rrule' : None, # Use: O-n, Type: RECUR, Defines a rule or repeating pattern for recurring events, to-dos, or time zone definitions. - 'x-prop' : None, + 'x-prop' : None, 'duration' : None, # Use: O-1, Type: DURATION, Specifies a positive duration of time. 'dtend' : None, # Use: O-1, Type: DATE-TIME, Specifies the date and time that a calendar component ends. } @@ -209,14 +209,14 @@ class Event(CalDAV, osv.osv_memory): startdate = todate(startdate) rset1 = rrulestr(rrulestring, dtstart=startdate, forceset=True) for date in exdate: - datetime_obj = datetime.strptime(date, "%Y-%m-%d %H:%M:%S", timezone=True) + datetime_obj = datetime.strptime(date, "%Y-%m-%d %H:%M:%S") # datetime_obj_utc = datetime_obj.replace(tzinfo=timezone('UTC')) rset1._exdate.append(datetime_obj) re_dates = rset1._iter() - recurrent_dates = map(lambda x:x.strftime('%Y-%m-%d %H:%M:%S', timezone=True), re_dates) + recurrent_dates = map(lambda x:x.strftime('%Y-%m-%d %H:%M:%S'), re_dates) return recurrent_dates - def search(self, cr, uid, args, offset=0, limit=None, order=None, + def search(self, cr, uid, args, offset=0, limit=None, order=None, context=None, count=False): # put logic for recurrent event # example : 123-20091111170822 @@ -243,7 +243,7 @@ class Journal(CalDAV): } class FreeBusy(CalDAV): - __attribute__ = { + __attribute__ = { 'contact' : None, # Use: O-1, Type: Text, Represent contact information or alternately a reference to contact information associated with the calendar component. 'dtstart' : None, # Use: O-1, Type: DATE-TIME, Specifies when the calendar component begins. 'dtend' : None, # Use: O-1, Type: DATE-TIME, Specifies the date and time that a calendar component ends. @@ -255,8 +255,8 @@ class FreeBusy(CalDAV): 'attendee' : None, # Use: O-n, Type: CAL-ADDRESS, Defines an "Attendee" within a calendar component. 'comment' : None, # Use: O-n, Type: TEXT, Specifies non-processing information intended to provide a comment to the calendar user. 'freebusy' : None, # Use: O-n, Type: PERIOD, Defines one or more free or busy time intervals. - 'rstatus' : None, - 'X-prop' : None, + 'rstatus' : None, + 'X-prop' : None, } class Timezone(CalDAV): @@ -277,7 +277,7 @@ class Timezone(CalDAV): class Alarm(CalDAV): __attribute__ = { - + 'action' : None, # Use: R-1, Type: Text, defines the action to be invoked when an alarm is triggered LIKE "AUDIO" / "DISPLAY" / "EMAIL" / "PROCEDURE" 'description' : None, # Type: Text, Provides a more complete description of the calendar component, than that provided by the "SUMMARY" property. Use:- R-1 for DISPLAY,Use:- R-1 for EMAIL,Use:- R-1 for PROCEDURE 'summary' : None, # Use: R-1, Type: Text Which contains the text to be used as the message subject. Use for EMAIL @@ -286,9 +286,9 @@ class Alarm(CalDAV): 'duration' : None, # Type: DURATION, Duration' and 'repeat' are both optional, and MUST NOT occur more than once each, but if one occurs, so MUST the other. Use:- 0-1 for AUDIO, EMAIL and PROCEDURE, Use:- 0-n for DISPLAY 'repeat' : None, # Type: INTEGER, Duration' and 'repeat' are both optional, and MUST NOT occur more than once each, but if one occurs, so MUST the other. Use:- 0-1 for AUDIO, EMAIL and PROCEDURE, Use:- 0-n for DISPLAY 'attach' : None, # Use:- O-n : which MUST point to a sound resource, which is rendered when the alarm is triggered for AUDIO, Use:- O-n : which are intended to be sent as message attachments for EMAIL, Use:- R-1:which MUST point to a procedure resource, which is invoked when the alarm is triggered for PROCEDURE. - 'x-prop' : None, + 'x-prop' : None, } - + def import_ical(self, cr, uid, ical_data): for val in ical_data.getChildren(): if self.__attribute__.has_key(val.name.lower()): From 6ef425eb9ba53031aed0c6d62efd20dc99d4dc99 Mon Sep 17 00:00:00 2001 From: "nch@tinyerp.com" <> Date: Thu, 10 Dec 2009 18:04:25 +0530 Subject: [PATCH 2/4] [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 --- addons/crm/crm_calendar.py | 237 ++++++++++++++++++++++++------------- 1 file changed, 156 insertions(+), 81 deletions(-) diff --git a/addons/crm/crm_calendar.py b/addons/crm/crm_calendar.py index bb8802ca755..2baaec876dc 100644 --- a/addons/crm/crm_calendar.py +++ b/addons/crm/crm_calendar.py @@ -31,6 +31,13 @@ from datetime import datetime from time import strftime from pytz import timezone import tools +from service import web_services + +def str2int(string_id = None): + if string_id: + if isinstance(string_id,str): + return int(string_id.split('-')[0]) + return string_id class crm_section(osv.osv): _name = 'crm.case.section' @@ -50,7 +57,7 @@ class crm_caldav_attendee(osv.osv): _name = 'crm.caldav.attendee' _description = 'Attendee information' _rec_name = 'cutype' - + __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. @@ -64,22 +71,22 @@ class crm_caldav_attendee(osv.osv): '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. } - + _columns = { 'cutype' : fields.selection([('INDIVIDUAL', 'INDIVIDUAL'), ('GROUP', 'GROUP'), \ - ('RESOURCE', 'RESOURCE'), ('ROOM', 'ROOM'), ('UNKNOWN', 'UNKNOWN') ], 'CUTYPE'), - 'member' : fields.char('Member', size=124), + ('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'), + ('OPT-PARTICIPANT', 'OPT-PARTICIPANT'), ('NON-PARTICIPANT', 'NON-PARTICIPANT')], 'ROLE'), 'partstat' : fields.selection([('NEEDS-ACTION', 'NEEDS-ACTION'), ('ACCEPTED', 'ACCEPTED'), \ - ('DECLINED', 'DECLINED'), ('TENTATIVE', 'TENTATIVE'), ('DELEGATED', 'DELEGATED')], 'PARTSTAT'), - '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), + ('DECLINED', 'DECLINED'), ('TENTATIVE', 'TENTATIVE'), ('DELEGATED', 'DELEGATED')], 'PARTSTAT'), + '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), } crm_caldav_attendee() @@ -88,44 +95,44 @@ class crm_case(osv.osv): _name = 'crm.case' _inherit = 'crm.case' _description = 'Cases' - + __attribute__ = { - 'class' : {'field':'class', 'type':'text'}, + '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'}, - #'last-mod' : {'field':'write_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, + 'description' : {'field':'description', 'type':'text'}, + 'dtstart' : {'field':'date', 'type':'datetime'}, + #'last-mod' : {'field':'write_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'}, - 'attendee' : {'field':'attendees', 'type':'text'}, + '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'}, + 'attendee' : {'field':'attendees', 'type':'text'}, # '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'}, -# 'duration' : {'field':'duration'}, - 'dtend' : {'field':'date_closed', 'type':'datetime'}, + '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'}, +# 'duration' : {'field':'duration'}, + 'dtend' : {'field':'date_closed', 'type':'datetime'}, } - + def _get_location(self, cr, uid, ids, name, arg, context=None): res = {} for case in self.browse(cr, uid, ids): @@ -140,7 +147,7 @@ class crm_case(osv.osv): else: res[case.id] = '' return res - + def _get_rdates(self, cr, uid, ids, name, arg, context=None): res = {} context.update({'read':True}) @@ -151,26 +158,26 @@ class crm_case(osv.osv): event_obj = self.pool.get('caldav.event') res[case['id']] = str(event_obj.get_recurrent_dates(str(rule), exdate, case['date'])) return res - + _columns = { 'class' : fields.selection([('PUBLIC', 'PUBLIC'), ('PRIVATE', 'PRIVATE'), \ - ('CONFIDENTIAL', 'CONFIDENTIAL')], 'Class'), - 'location' : fields.function(_get_location, method=True, store = True, string='Location', type='text'), - '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'), + ('CONFIDENTIAL', 'CONFIDENTIAL')], 'Class'), + 'location' : fields.function(_get_location, method=True, store = True, string='Location', type='text'), + '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'), - 'attendees': fields.many2many('crm.caldav.attendee', 'crm_attendee_rel', 'case_id', 'attendee_id', 'Attendees'), + store=True, type='text'), + 'attendees': fields.many2many('crm.caldav.attendee', 'crm_attendee_rel', 'case_id', 'attendee_id', 'Attendees'), } - + _defaults = { - 'caldav_url': lambda *a: 'http://localhost:8080', - 'class': lambda *a: 'PUBLIC', - 'transparent': lambda *a: 'OPAQUE', + 'caldav_url': lambda *a: 'http://localhost:8080', + 'class': lambda *a: 'PUBLIC', + 'transparent': lambda *a: 'OPAQUE', } - + def export_cal(self, cr, uid, ids, context={}): crm_data = self.read(cr, uid, ids, []) ical = vobject.iCalendar() @@ -182,7 +189,7 @@ class crm_case(osv.osv): if key == 'uid': uid_val += str(crm[val['field']]) continue - if val == None or key == 'rrule': + if val == None or key == 'rrule': continue if val.has_key('field') and val.has_key('sub-field') and crm[val['field']] and crm[val['field']]: vevent.add(key).value = crm[val['field']][1] @@ -195,7 +202,7 @@ class crm_case(osv.osv): startdate = datetime.strptime(crm['date'], "%Y-%m-%d %H:%M:%S") if not startdate: startdate = datetime.now() - rset1 = rrulestr(str(crm[event_obj.__attribute__['rrule']['field']]), dtstart=startdate, forceset=True) + rset1 = rrulestr(str(crm[self.__attribute__['rrule']['field']]), dtstart=startdate, forceset=True) vevent.rruleset = rset1 vevent.add('uid').value = uid_val return ical.serialize()#.replace(vobject.icalendar.CRLF, vobject.icalendar.LF).strip() @@ -227,25 +234,29 @@ class crm_case(osv.osv): case_id = self.create(cr, uid, vals) return - def search(self, cr, uid, args, offset=0, limit=None, order=None, + 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, + res = super(crm_case, self).search(cr, uid, args, offset, limit, order, context, count) return res - + def write(self, cr, uid, ids, vals, context=None): - res = super(crm_case, self).write(cr, uid, ids, vals, context=context) + new_ids = [] + for id in ids: + id = str2int(id) + if not id in new_ids: + new_ids.append(id) + if 'case_id' in vals : + vals['case_id'] = str2int(vals['case_id']) + res = super(crm_case, self).write(cr, uid, new_ids, vals, context=context) return res - + def browse(self, cr, uid, select, context=None, list_class=None, fields_process={}): - if not type(select) == list : - # Called from code - id = int(str(select).split('-')[0]) - return super(crm_case, self).browse(cr, uid, id, context, list_class, fields_process) - select = map(lambda x:int(str(x).split('-')[0]), select) + if not isinstance(select,list): select = [select] + select = map(lambda x:str2int(x), select) return super(crm_case, self).browse(cr, uid, select, context, list_class, fields_process) - def read(self, cr, uid, ids, fields=None, context={}, + def read(self, cr, uid, ids, fields=None, context={}, load='_classic_read'): """ logic for recurrent event example : 123-20091111170822""" @@ -253,11 +264,9 @@ class crm_case(osv.osv): return super(crm_case, self).read(cr, uid, ids, fields=fields, context=context, load=load) if not type(ids) == list : # Called from code - ids = int(str(ids).split('-')[0]) - res = super(crm_case, self).read(cr, uid, ids, fields=fields, context=context, load=load) - return res + return super(crm_case, self).read(cr, uid, str2int(ids), fields=fields, context=context, load=load) else: - ids = map(lambda x:int(str(x).split('-')[0]), ids) + ids = map(lambda x:str2int(x), ids) res = super(crm_case, self).read(cr, uid, ids, fields=fields, context=context, load=load) read_ids = ",".join([str(x) for x in ids]) cr.execute('select id,rrule,rdates from crm_case where id in (%s)' % read_ids) @@ -283,18 +292,27 @@ class crm_case(osv.osv): val['id'] = id + '-' + ''.join(idval) val1 = val.copy() result += [val1] - return result - + return result + + def copy(self, cr, uid, id, default=None, context={}): + return super(crm_case, self).copy(cr, uid, str2int(id), default, context) + def unlink(self, cr, uid, ids, context=None): #TODO: Change RRULE for id in ids: if len(str(id).split('-')) > 1: date_new = time.strftime("%Y-%m-%d %H:%M:%S", time.strptime(str(str(id).split('-')[1]), "%Y%m%d%H%M%S")) - for record in self.read(cr, uid, [str(id).split('-')[0]], ['date', 'rdates', 'rrule']): + for record in self.read(cr, uid, [str2int(id)], ['date', 'rdates', 'rrule']): if record['date'] == date_new: - self.write(cr, uid, [int(str(id).split('-')[0])], {'rrule' : record['rrule'] +"\n" + str(date_new)}) + self.write(cr, uid, [str2int(id)], {'rrule' : record['rrule'] +"\n" + str(date_new)}) else: return super(crm_case, self).unlink(cr, uid, ids) + + def create(self, cr, uid, vals, context={}): + if 'case_id' in vals: + vals['case_id'] = str2int(vals['case_id']) + return super(crm_case, self).create(cr, uid, vals, context) + crm_case() @@ -308,4 +326,61 @@ class ir_attachment(osv.osv): args1.append(map(lambda x:str(x).split('-')[0], arg)) return super(ir_attachment, self).search_count(cr, user, args1, context) + def search(self, cr, uid, args, offset=0, limit=None, order=None, + context=None, count=False): + new_args = [] + if len(args) > 1: + new_args = [args[0]] + if args[1][0] == 'res_id': + new_args.append((args[1][0],args[1][1],str2int(args[1][2]))) + if new_args: + args = new_args + return super(ir_attachment, self).search(cr, uid, args, offset=offset, + limit=limit, order=order, + context=context, count=False) ir_attachment() + +class ir_values(osv.osv): + _inherit = 'ir.values' + + def set(self, cr, uid, key, key2, name, models, value, replace=True, isobject=False, meta=False, preserve_user=False, company=False): + new_model = [] + for data in models: + if isinstance(data,tuple): + new_model.append((data[0],str2int(data[1]))) + else: + new_model.append(data) + return super(ir_values,self).set(cr, uid, key, key2, name, new_model, value, replace, isobject, meta, preserve_user, company) + + def get(self, cr, uid, key, key2, models, meta=False, context={}, res_id_req=False, without_user=True, key2_req=True): + new_model = [] + for data in models: + if isinstance(data,tuple): + new_model.append((data[0],str2int(data[1]))) + else: + new_model.append(data) + return super(ir_values,self).get(cr, uid, key, key2, new_model, meta, context, res_id_req, without_user, key2_req) + +ir_values() + +class virtual_report_spool(web_services.report_spool): + def exp_report(self, db, uid, object, ids, datas=None, context=None): + new_ids = [] + for id in ids: + new_ids.append(str2int(id)) + datas['id'] = str2int(datas['id']) + res=super(virtual_report_spool,self).exp_report( db, uid, object, new_ids, datas, context) + return res +virtual_report_spool() + +class virtual_wizard(web_services.wizard): + def exp_execute(self, db, uid, wiz_id, datas, action='init', context=None): + new_ids = [] + if 'id' in datas: + datas['id'] = str2int(datas['id']) + for id in datas['ids']: + new_ids.append(str2int(id)) + datas['ids'] = new_ids + res=super(virtual_wizard,self).exp_execute(db, uid, wiz_id, datas, action, context) + return res +virtual_wizard() \ No newline at end of file From cd5daff908fd44a70887d8b6470fcce6b0ed1ec0 Mon Sep 17 00:00:00 2001 From: "nch@tinyerp.com" <> Date: Fri, 11 Dec 2009 15:03:59 +0530 Subject: [PATCH 3/4] [FIX,IMP]:meeting_planify wizard and improvement in caldev virtual ids concept bzr revid: nch@tinyerp.com-20091211093359-sp44ovvm3g8kmhnh --- addons/crm/crm_calendar.py | 58 +++++++++++++++++----------- addons/crm/wizard/meeting_planify.py | 2 +- 2 files changed, 36 insertions(+), 24 deletions(-) diff --git a/addons/crm/crm_calendar.py b/addons/crm/crm_calendar.py index 2baaec876dc..24e755794cd 100644 --- a/addons/crm/crm_calendar.py +++ b/addons/crm/crm_calendar.py @@ -33,11 +33,11 @@ from pytz import timezone import tools from service import web_services -def str2int(string_id = None): - if string_id: - if isinstance(string_id,str): - return int(string_id.split('-')[0]) - return string_id +def caldevIDs2readIDs(caldev_ID = None): + if caldev_ID: + if isinstance(caldev_ID,str): + return int(caldev_ID.split('-')[0]) + return caldev_ID class crm_section(osv.osv): _name = 'crm.case.section' @@ -243,17 +243,17 @@ class crm_case(osv.osv): def write(self, cr, uid, ids, vals, context=None): new_ids = [] for id in ids: - id = str2int(id) + id = caldevIDs2readIDs(id) if not id in new_ids: new_ids.append(id) if 'case_id' in vals : - vals['case_id'] = str2int(vals['case_id']) + vals['case_id'] = caldevIDs2readIDs(vals['case_id']) res = super(crm_case, self).write(cr, uid, new_ids, vals, context=context) return res def browse(self, cr, uid, select, context=None, list_class=None, fields_process={}): if not isinstance(select,list): select = [select] - select = map(lambda x:str2int(x), select) + select = map(lambda x:caldevIDs2readIDs(x), select) return super(crm_case, self).browse(cr, uid, select, context, list_class, fields_process) def read(self, cr, uid, ids, fields=None, context={}, @@ -264,9 +264,9 @@ class crm_case(osv.osv): return super(crm_case, self).read(cr, uid, ids, fields=fields, context=context, load=load) if not type(ids) == list : # Called from code - return super(crm_case, self).read(cr, uid, str2int(ids), fields=fields, context=context, load=load) + return super(crm_case, self).read(cr, uid, caldevIDs2readIDs(ids), fields=fields, context=context, load=load) else: - ids = map(lambda x:str2int(x), ids) + ids = map(lambda x:caldevIDs2readIDs(x), ids) res = super(crm_case, self).read(cr, uid, ids, fields=fields, context=context, load=load) read_ids = ",".join([str(x) for x in ids]) cr.execute('select id,rrule,rdates from crm_case where id in (%s)' % read_ids) @@ -295,22 +295,22 @@ class crm_case(osv.osv): return result def copy(self, cr, uid, id, default=None, context={}): - return super(crm_case, self).copy(cr, uid, str2int(id), default, context) + return super(crm_case, self).copy(cr, uid, caldevIDs2readIDs(id), default, context) def unlink(self, cr, uid, ids, context=None): #TODO: Change RRULE for id in ids: if len(str(id).split('-')) > 1: date_new = time.strftime("%Y-%m-%d %H:%M:%S", time.strptime(str(str(id).split('-')[1]), "%Y%m%d%H%M%S")) - for record in self.read(cr, uid, [str2int(id)], ['date', 'rdates', 'rrule']): + for record in self.read(cr, uid, [caldevIDs2readIDs(id)], ['date', 'rdates', 'rrule']): if record['date'] == date_new: - self.write(cr, uid, [str2int(id)], {'rrule' : record['rrule'] +"\n" + str(date_new)}) + self.write(cr, uid, [caldevIDs2readIDs(id)], {'rrule' : record['rrule'] +"\n" + str(date_new)}) else: return super(crm_case, self).unlink(cr, uid, ids) def create(self, cr, uid, vals, context={}): if 'case_id' in vals: - vals['case_id'] = str2int(vals['case_id']) + vals['case_id'] = caldevIDs2readIDs(vals['case_id']) return super(crm_case, self).create(cr, uid, vals, context) crm_case() @@ -332,7 +332,7 @@ class ir_attachment(osv.osv): if len(args) > 1: new_args = [args[0]] if args[1][0] == 'res_id': - new_args.append((args[1][0],args[1][1],str2int(args[1][2]))) + new_args.append((args[1][0],args[1][1],caldevIDs2readIDs(args[1][2]))) if new_args: args = new_args return super(ir_attachment, self).search(cr, uid, args, offset=offset, @@ -347,7 +347,7 @@ class ir_values(osv.osv): new_model = [] for data in models: if isinstance(data,tuple): - new_model.append((data[0],str2int(data[1]))) + new_model.append((data[0],caldevIDs2readIDs(data[1]))) else: new_model.append(data) return super(ir_values,self).set(cr, uid, key, key2, name, new_model, value, replace, isobject, meta, preserve_user, company) @@ -356,30 +356,42 @@ class ir_values(osv.osv): new_model = [] for data in models: if isinstance(data,tuple): - new_model.append((data[0],str2int(data[1]))) + new_model.append((data[0],caldevIDs2readIDs(data[1]))) else: new_model.append(data) return super(ir_values,self).get(cr, uid, key, key2, new_model, meta, context, res_id_req, without_user, key2_req) ir_values() +class ir_model(osv.osv): + _inherit = 'ir.model' + def read(self, cr, uid, ids, fields=None, context={}, + 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 + class virtual_report_spool(web_services.report_spool): def exp_report(self, db, uid, object, ids, datas=None, context=None): + if object == 'printscreen.list': + return super(virtual_report_spool,self).exp_report( db, uid, object, ids, datas, context) new_ids = [] for id in ids: - new_ids.append(str2int(id)) - datas['id'] = str2int(datas['id']) - res=super(virtual_report_spool,self).exp_report( db, uid, object, new_ids, datas, context) - return res + new_ids.append(caldevIDs2readIDs(id)) + datas['id'] = caldevIDs2readIDs(datas['id']) + 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) virtual_report_spool() class virtual_wizard(web_services.wizard): def exp_execute(self, db, uid, wiz_id, datas, action='init', context=None): new_ids = [] if 'id' in datas: - datas['id'] = str2int(datas['id']) + datas['id'] = caldevIDs2readIDs(datas['id']) for id in datas['ids']: - new_ids.append(str2int(id)) + new_ids.append(caldevIDs2readIDs(id)) datas['ids'] = new_ids res=super(virtual_wizard,self).exp_execute(db, uid, wiz_id, datas, action, context) return res diff --git a/addons/crm/wizard/meeting_planify.py b/addons/crm/wizard/meeting_planify.py index bf654f2d7b7..cb47dacd5b3 100644 --- a/addons/crm/wizard/meeting_planify.py +++ b/addons/crm/wizard/meeting_planify.py @@ -45,7 +45,7 @@ class make_meeting(wizard.interface): def _selectPartner(self, cr, uid, data, context): case_obj = pooler.get_pool(cr.dbname).get('crm.case') case = case_obj.browse(cr, uid, data['id']) - return {'date': case.date, 'duration': case.duration or 2.0} + return {'date': case[0].date, 'duration': case[0].duration or 2.0} def _makeMeeting(self, cr, uid, data, context): pool = pooler.get_pool(cr.dbname) From ee60a6ed52a7d6c1c3feeb26de5f889cf3548e4e Mon Sep 17 00:00:00 2001 From: "nch@tinyerp.com" <> Date: Tue, 15 Dec 2009 12:04:09 +0530 Subject: [PATCH 4/4] [FIX]:sometimes ids come in list format too bzr revid: nch@tinyerp.com-20091215063409-torqn4w49qj2tk18 --- addons/crm/crm_calendar.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/addons/crm/crm_calendar.py b/addons/crm/crm_calendar.py index 24e755794cd..1254c04bd56 100644 --- a/addons/crm/crm_calendar.py +++ b/addons/crm/crm_calendar.py @@ -346,7 +346,7 @@ class ir_values(osv.osv): def set(self, cr, uid, key, key2, name, models, value, replace=True, isobject=False, meta=False, preserve_user=False, company=False): new_model = [] for data in models: - if isinstance(data,tuple): + if type(data) in (list,tuple): new_model.append((data[0],caldevIDs2readIDs(data[1]))) else: new_model.append(data) @@ -355,7 +355,7 @@ class ir_values(osv.osv): def get(self, cr, uid, key, key2, models, meta=False, context={}, res_id_req=False, without_user=True, key2_req=True): new_model = [] for data in models: - if isinstance(data,tuple): + if type(data) in (list,tuple): new_model.append((data[0],caldevIDs2readIDs(data[1]))) else: new_model.append(data)