tfr (Openerp) has proposed merging 
lp:~openerp-dev/openobject-addons/trunk-fix-caldav-issue-tfr into 
lp:openobject-addons.

Requested reviews:
  OpenERP Core Team (openerp)

For more details, see:
https://code.launchpad.net/~openerp-dev/openobject-addons/trunk-fix-caldav-issue-tfr/+merge/67684
-- 
https://code.launchpad.net/~openerp-dev/openobject-addons/trunk-fix-caldav-issue-tfr/+merge/67684
Your team OpenERP R&D Team is subscribed to branch 
lp:~openerp-dev/openobject-addons/trunk-fix-caldav-issue-tfr.
=== modified file 'base_calendar/base_calendar.py'
--- base_calendar/base_calendar.py	2011-07-01 23:41:24 +0000
+++ base_calendar/base_calendar.py	2011-07-12 11:21:45 +0000
@@ -991,15 +991,24 @@
         """
         
         result = {}
+        if not isinstance(ids, list):
+            ids = [ids]
+            
         for datas in self.read(cr, uid, ids, ['id','byday','recurrency', 'month_list','end_date', 'rrule_type', 'select1', 'interval', 'count', 'end_type', 'mo', 'tu', 'we', 'th', 'fr', 'sa', 'su', 'exrule', 'day', 'week_list' ], context=context):
             event = datas['id']
             if datas.get('interval', 0) < 0:
                 raise osv.except_osv(_('Warning!'), _('Interval can not be Negative'))
             if datas.get('count', 0) < 0:
                 raise osv.except_osv(_('Warning!'), _('Count can not be Negative'))
-            result[event] = self.compute_rule_string(datas)
+            if datas['recurrency']:
+                result[event] = self.compute_rule_string(datas)
+            else:
+                result[event] = ""
         return result
-
+    
+      
+    
+    
     _columns = {
         'id': fields.integer('ID'),
         'sequence': fields.integer('Sequence'),
@@ -1173,7 +1182,6 @@
         @param self: the object pointer
         @param datas: dictionary of freq and interval value.
         """
-        
         def get_week_string(freq, datas):
             weekdays = ['mo', 'tu', 'we', 'th', 'fr', 'sa', 'su']
             if freq == 'weekly':
@@ -1205,10 +1213,88 @@
             return ''
         interval_srting = datas.get('interval') and (';INTERVAL=' + str(datas.get('interval'))) or ''
         return 'FREQ=' + freq.upper() + get_week_string(freq, datas) + interval_srting + get_end_date(datas) + get_month_string(freq, datas)
-
+    
+    def _get_empty_rrule_data(self):
+        return  {
+            'byday' : False,
+            'recurrency' : False,
+            'end_date' : False, 
+            'rrule_type' : False, 
+            'select1' : False, 
+            'interval' : 0, 
+            'count' : False, 
+            'end_type' : False, 
+            'mo' : False, 
+            'tu' : False, 
+            'we' : False, 
+            'th' : False, 
+            'fr' : False, 
+            'sa' : False, 
+            'su' : False, 
+            'exrule' : False, 
+            'day' : False, 
+            'week_list' : False
+        }
+
+    def _write_rrule(self, cr, uid, ids, field_value, rule_date=False, context=None):
+        data = self._get_empty_rrule_data()
+        
+        if field_value:
+            data['recurrency'] = True
+            for event in self.browse(cr, uid, ids, context=context):
+                rdate = rule_date or event.date
+                update_data = self._parse_rrule(field_value, dict(data), rdate)
+                data.update(update_data)
+                #parse_rrule
+                self.write(cr, uid, event.id, data, context=context)
+        
+
+    def _parse_rrule(self, rule, data, date_start):
+        day_list = ['mo', 'tu', 'we', 'th', 'fr', 'sa', 'su']
+        rrule_type = ['yearly', 'monthly', 'weekly', 'daily']
+        r = rrule.rrulestr(rule, dtstart=datetime.strptime(date_start, "%Y-%m-%d %H:%M:%S"))
+        
+        if r._freq > 0 and r._freq < 4:
+            data['rrule_type'] = rrule_type[r._freq]
+            
+        data['count'] = r._count
+        data['interval'] = r._interval
+        data['end_date'] = r._until and r._until.strftime("%Y-%m-%d %H:%M:%S")
+        #repeat weekly
+        if r._byweekday:
+            for i in xrange(0,7):
+                if i in r._byweekday:
+                    data[day_list[i]] = True
+            data['rrule_type'] = 'weekly'
+        #repeat monthly bynweekday ((weekday, weeknumber), )
+        if r._bynweekday: 
+            data['week_list'] = day_list[r._bynweekday[0][0]].upper()
+            data['byday'] = r._bynweekday[0][1]
+            data['select1'] = 'day'
+            data['rrule_type'] = 'monthly' 
+           
+        if r._bymonthday:
+            data['day'] = r._bymonthday[0]
+            data['select1'] = 'date'
+            data['rrule_type'] = 'monthly'
+            
+        #yearly but for openerp it's monthly, take same information as monthly but interval is 12 times
+        if r._bymonth:
+            data['interval'] = data['interval'] * 12
+            
+        #FIXEME handle forever case
+        #end of recurrence    
+        #in case of repeat for ever that we do not support right now
+        if not (data.get('count') or data.get('end_date')):
+            data['count'] = 100
+        if data.get('count'):
+            data['end_type'] = 'count'
+        else:
+            data['end_type'] = 'end_date'  
+        return data  
 
     def remove_virtual_id(self, ids):
-        if isinstance(ids, (str, int)):
+        if isinstance(ids, (str, int, long)):
             return base_calendar_id2real_id(ids)
             
         if isinstance(ids, (list, tuple)):
@@ -1239,7 +1325,6 @@
                     if until_date:
                         continue
                     until_date = arg[2]
-        
         res = super(calendar_event, self).search(cr, uid, args_without_date, \
                                  0, 0, order, context, count=False)
         res = self.get_recurrent_ids(cr, uid, res, start_date, until_date, limit, context=context)
@@ -1278,6 +1363,8 @@
             except Exception:
                 return True
   
+    
+        
     def write(self, cr, uid, ids, vals, context=None, check=True, update_check=True):
         if context is None:
             context = {}
@@ -1285,6 +1372,9 @@
             select = [ids]
         else:
             select = ids
+            
+       
+            
         new_ids = []
         res = False
         for event_id in select:
@@ -1336,6 +1426,13 @@
             context=context)
         vals.update(updated_vals.get('value', {}))
         if new_ids:
+            if 'rrule' in vals.keys():
+                if 'date' in vals.keys():
+                    date_to_write = vals['date']
+                else:
+                    date_to_write = False
+                self._write_rrule(cr, uid, new_ids, vals['rrule'], date_to_write, context)
+                
             res = super(calendar_event, self).write(cr, uid, new_ids, vals, context=context)
 
         if ('alarm_id' in vals or 'base_calendar_alarm_id' in vals)\
@@ -1462,6 +1559,11 @@
 
         if vals.get('vtimezone', '') and vals.get('vtimezone', '').startswith('/freeassociation.sourceforge.net/tzfile/'):
             vals['vtimezone'] = vals['vtimezone'][40:]
+        
+        if 'date' in vals and 'rrule' in vals and vals['rrule']:
+            update_datas = self._parse_rrule(vals['rrule'], self._get_empty_rrule_data(), vals['date'])
+            update_datas['recurrency'] = True
+            vals.update(update_datas)
 
         updated_vals = self.onchange_dates(cr, uid, [],
             vals.get('date', False),

=== modified file 'caldav/caldav_node.py'
--- caldav/caldav_node.py	2011-01-18 16:50:15 +0000
+++ caldav/caldav_node.py	2011-07-12 11:21:45 +0000
@@ -324,7 +324,6 @@
         uid = self.context.uid
 
         res = self.set_data(cr, data)
-
         if res and len(res):
             # We arbitrarily construct only the first node of the data
             # that have been imported. ICS may have had more elements,
@@ -332,6 +331,7 @@
             assert isinstance(res[0], (int, long))
             fnodes = fil_obj.get_calendar_objects(cr, uid, [self.calendar_id], self,
                     domain=[('id','=',res[0])], context=ctx)
+            
             if self.context.get('DAV-client','') in ('iPhone', 'iCalendar',):
                 # For those buggy clients, register the alias
                 bca_obj = fil_obj.pool.get('basic.calendar.alias')

=== modified file 'caldav/calendar.py'
--- caldav/calendar.py	2011-01-14 09:34:28 +0000
+++ caldav/calendar.py	2011-07-12 11:21:45 +0000
@@ -121,10 +121,10 @@
     for mas in mailz:
         m = mege.match(mas.strip())
         if not m:
-            # one of the rare non-matching strings is "sad" :(
-            # retz.append({ 'name': mas.strip() })
-            # continue
-            raise ValueError("Invalid email address %r" % mas)
+            #one of the rare non-matching strings is "sad" :(
+            retz.append({ 'name': mas.strip() })
+            continue
+            # raise ValueError("Invalid email address %r" % mas)
         rd = {  'name': m.group(1).strip(),
                 'email': m.group(5), }
         if m.group(2):
@@ -189,6 +189,9 @@
         field = obj.ical_get(map_dict, 'field')
         field_type = obj.ical_get(map_dict, 'type')
         if field:
+            #ignore write date, this field is resered for the orm
+            if field == 'write_date':
+                continue
             if field_type == 'selection':
                 if not map_val:
                     continue
@@ -299,7 +302,6 @@
         att_data = []
         exdates = []
         _server_tzinfo = pytz.timezone(tools.get_server_timezone())
-
         for cal_data in child.getChildren():
             if cal_data.name.lower() == 'organizer':
                 dmail = { 'name': cal_data.params.get('CN', ['',])[0],
@@ -552,7 +554,7 @@
             @param data_id: Get Data’s ID or False
             @param context: A standard dictionary for contextual values
         """
-
+        
         ical_data = content
         self.__attribute__ = get_attribute_mapping(cr, uid, self._calname, context)
         parsedCal = vobject.readOne(ical_data)

=== modified file 'project_caldav/project_caldav.py'
--- project_caldav/project_caldav.py	2011-01-14 00:11:01 +0000
+++ project_caldav/project_caldav.py	2011-07-12 11:21:45 +0000
@@ -28,7 +28,7 @@
 
 class project_task(osv.osv):
     _name = "project.task"
-    _inherit = ["calendar.todo", "project.task"]
+    _inherit = ["project.task", "calendar.todo"]
     _columns = {
         # force inherit from project.project_task so that 
         # calendar.todo.active is masked oute
@@ -42,11 +42,11 @@
                                   help='If the task is created the state is \'Draft\'.\n If the task is started, the state becomes \'In Progress\'.\n If review is needed the task is in \'Pending\' state.\
                                   \n If the task is over, the states is set to \'Done\'.'),
     }
+    
     _defaults = {
         'state': 'draft',
     }
 
-
     def open_task(self, cr, uid, ids, context=None):
         """
         Open Task Form for Project Task.
@@ -109,6 +109,8 @@
                 self.write(cr, uid, [exists], val)
                 ids.append(exists)
             else:
+                #set user_id with id, needed later
+                val.update({'user_id' : uid})
                 task_id = self.create(cr, uid, val)
                 ids.append(task_id)
         return ids

=== modified file 'project_caldav/project_caldav_view.xml'
--- project_caldav/project_caldav_view.xml	2011-01-14 00:11:01 +0000
+++ project_caldav/project_caldav_view.xml	2011-07-12 11:21:45 +0000
@@ -65,9 +65,9 @@
             <field name="type">form</field>
             <field name="arch" type="xml">
                 <field name="progress" position="after">
-                    <field name="recurrency"/>      
-                     <field name="edit_all" attrs="{'invisible':[('recurrency','=', False)]}"
-                                on_change="onchange_edit_all(rrule_type,edit_all)"/>                    
+                    <!--     Recurrency of task not well implemented for now, remove the option-->     
+                     <field name="recurrency" invisible="1"/>
+                     <field name="edit_all" attrs="{'invisible':[('recurrency','=', False)]}"/>                    
                 </field>
             </field>
         </record>
@@ -79,46 +79,57 @@
             <field name="type">form</field>
             <field name="arch" type="xml">
                 <notebook colspan="4" position="inside">
-                    <page string="Recurrency Option" attrs="{'invisible':[('recurrency','=',False)]}">
-                        <group colspan="2" col="4" >
-                             <field name="rrule_type" string="Recurrency" colspan="1" attrs="{'readonly':[('recurrent_uid','!=',False)]}"/>
-                        </group>
-                        <newline/>
-                        <group col="4" colspan="6" name="rrule">
-                            <separator string="Recurrency Rule" colspan="8"/>
-                            <group col="6" colspan="4">
-                                <field name="interval" string="Repeat Times" attrs="{'readonly': [('end_date','!=',False)]}"/>
-                                <field name="count" attrs="{'readonly': [('end_date','!=',False)]}"/>
-                                <field name="end_date" attrs="{'invisible': [('readonly','!=',False)]}"/>
+                    <page string="Recurrency Option" attrs="{'invisible': [('recurrency','=',False)], 'readonly': ['|', ('recurrent_uid','!=',False), ('state','=','done')]}">
+                        <group col="4" colspan="4" name="rrule">
+                            <group col="4" colspan="4">
+                                <field name="rrule_type" string="Recurrency period" />
+                                <field name="interval" />                               
+                                                       
+                                
+                                <separator string="End of recurrency" colspan="4"/>
+                                <field name="end_type" />
+                                <label string=" " colspan="2" />
+                                <newline />
+                                <field name="count" attrs="{'invisible' : [('end_type', '!=', 'count')] }"/>
+                                <label string=" " colspan="2" />
+                                <newline />
+                                <field name="end_date" attrs="{'invisible' : [('end_type', '!=', 'end_date')], 'required': [('end_type', '=', 'end_date')]}"/>
+                                <newline />
+                           
+                      
                             </group>
-                            <group col="14" colspan="4" name="Select weekdays" 
-                                    attrs="{'invisible' :[('rrule_type','not in', ['weekly','daily_working'])]}">
+                            <group col="8" colspan="4" name="Select weekdays" attrs="{'invisible' :[('rrule_type','not in', ['weekly'])]}">
+                                <separator string="Choose day where repeat the meeting" colspan="8"/>
                                 <field name="mo" colspan="1" />
                                 <field name="tu" colspan="1" />
                                 <field name="we" colspan="1" />
                                 <field name="th" colspan="1" />
                                 <newline/>
                                 <field name="fr" colspan="1" />
-                                <field name="sa" colspan="1"  attrs="{'invisible': [('rrule_type','=','daily_working')]}"/>
-                                <field name="su" colspan="1"  attrs="{'invisible': [('rrule_type','=','daily_working')]}"/>
+                                <field name="sa" colspan="1"  />
+                                <field name="su" colspan="1"  />
                                 <newline />
                             </group>
-                            <group col="10" colspan="4" attrs="{'invisible': [('rrule_type','!=','monthly'), ('rrule_type','!=','yearly')]}">
-                                <group col="2" colspan="1">
-                                <field name="select1" />
-                                </group>
-                                <group col="2" colspan="1" attrs="{'invisible' : [('select1','=','day')]}">
-                                <field name="day" attrs="{'required' : [('select1','=','date')]}" />
-                                </group>
-                                <group col="3" colspan="1" attrs="{'invisible' : [('select1','=','date')]}">
-                                <field name="byday" string="The" attrs="{'required' : [('select1','=','day')]}" />
-                                <field name="week_list" nolabel="1" attrs="{'required' : [('select1','=','day')]}" />
-                                </group>
-                                <group col="1" colspan="1" attrs="{'invisible' : [('rrule_type','!=','yearly')]}">
-                                <field name="month_list" string="of" colspan="1" attrs="{'required' : [('rrule_type','=','yearly')]}" />
+                            <group col="10" colspan="4"
+                                attrs="{'invisible' : [('rrule_type','!=','monthly')]}">
+                                <separator string="Choose day in the month where repeat the meeting" colspan="12"/>
+                                <group col="2" colspan="1">
+                                    <field name="select1" />
+                                </group>
+                                <group col="2" colspan="1">
+                                    <field name="day"
+                                        attrs="{'required' : [('select1','=','date'), ('rrule_type','=','monthly')],
+                                            'invisible' : [('select1','=','day')]}" />
+                                </group>
+                                <group col="3" colspan="1">
+                                    <field name="byday" string="The"
+                                        attrs="{'required' : [('select1','=','day'), ('rrule_type','=','monthly')], 'invisible' : [('select1','=','date')]}" />
+                                    <field name="week_list" nolabel="1"
+                                        attrs="{'required' : [('select1','=','day'), ('rrule_type','=','monthly')], 'invisible' : [('select1','=','date')]}" />
                                 </group>
                             </group>
                         </group>
+
                     </page>
                  </notebook>
             </field>

_______________________________________________
Mailing list: https://launchpad.net/~openerp-dev-gtk
Post to     : [email protected]
Unsubscribe : https://launchpad.net/~openerp-dev-gtk
More help   : https://help.launchpad.net/ListHelp

Reply via email to