From 97d7f15ab8ca6583130f80a66f24c551e2b4bf5d Mon Sep 17 00:00:00 2001 From: "rpa (Open ERP)" Date: Fri, 29 Jan 2010 16:09:44 +0530 Subject: [PATCH] [IMP]: base_calendar, caldav: Moved unmapped fields to its proper modules * Put proper validation for duplicate field mapping bzr revid: rpa@openerp.co.in-20100129103944-vjep376dv02oftwx --- addons/base_calendar/base_calendar.py | 57 +++++++++++++------- addons/base_calendar/base_calendar_view.xml | 2 +- addons/caldav/caldav_data.xml | 58 +-------------------- addons/crm/crm_meeting_data.xml | 4 +- 4 files changed, 42 insertions(+), 79 deletions(-) diff --git a/addons/base_calendar/base_calendar.py b/addons/base_calendar/base_calendar.py index 168da55eaf7..71117227fa9 100644 --- a/addons/base_calendar/base_calendar.py +++ b/addons/base_calendar/base_calendar.py @@ -194,9 +194,7 @@ class CalDAV(object): def create_ics(self, cr, uid, datas, name, ical, context=None): if not datas: - model = context.get('model', None) - war_str = "No data available" + (model and " for " + model) or "" - raise osv.except_osv(_('Warning !'), _(war_str)) + return for data in datas: vevent = ical.add(name) for field in self.__attribute__.keys(): @@ -333,21 +331,18 @@ class Calendar(CalDAV, osv.osv): } def export_cal(self, cr, uid, datas, vobj='vevent', context={}): - try: - cal = self.browse(cr, uid, datas[0]) - ical = vobject.iCalendar() - for line in cal.line_ids: - if line.name in ('alarm', 'attendee'): - continue - mod_obj = self.pool.get(line.object_id.model) - data_ids = mod_obj.search(cr, uid, eval(line.domain), context=context) - datas = mod_obj.read(cr, uid, data_ids, context=context) - context.update({'model': line.object_id.model}) - self.__attribute__ = get_attribute_mapping(cr, uid, line.name, context) - self.create_ics(cr, uid, datas, line.name, ical, context=context) - return ical.serialize() - except Exception, e: - raise osv.except_osv(('Error !'), (str(e))) + cal = self.browse(cr, uid, datas[0]) + ical = vobject.iCalendar() + for line in cal.line_ids: + if line.name in ('valarm', 'attendee'): + continue + mod_obj = self.pool.get(line.object_id.model) + data_ids = mod_obj.search(cr, uid, eval(line.domain), context=context) + datas = mod_obj.read(cr, uid, data_ids, context=context) + context.update({'model': line.object_id.model}) + self.__attribute__ = get_attribute_mapping(cr, uid, line.name, context) + self.create_ics(cr, uid, datas, line.name, ical, context=context) + return ical.serialize() def import_cal(self, cr, uid, content, data_id=None, context=None): ical_data = base64.decodestring(content) @@ -378,7 +373,7 @@ class basic_calendar_line(osv.osv): _description = 'Calendar Lines' _columns = { 'name': fields.selection([('vevent', 'Event'), ('vtodo', 'TODO'), \ - ('alarm', 'Alarm'), \ + ('valarm', 'Alarm'), \ ('attendee', 'Attendee')], \ string="Type", size=64), 'object_id': fields.many2one('ir.model', 'Object'), @@ -428,6 +423,30 @@ class basic_calendar_fields(osv.osv): 'fn': lambda *a: 'field', } + def create(self, cr, uid, vals, context={}): + cr.execute('select name from basic_calendar_attributes \ + where id=%s' % (vals.get('name'))) + name = cr.fetchone() + name = name[0] + if name in ('valarm', 'attendee'): + f_obj = self.pool.get('ir.model.fields') + field = f_obj.browse(cr, uid, vals['field_id'], context=context) + relation = field.relation + line_obj = self.pool.get('basic.calendar.lines') + l_id = line_obj.search(cr, uid, [('name', '=', name)]) + if l_id: + line = line_obj.browse(cr, uid, l_id, context=context)[0] + line_rel = line.object_id.model + if (relation != 'NULL') and (not relation == line_rel): + raise osv.except_osv(_('Warning !'), _('Please provide proper configuration of "%s" in Calendar Lines' % (name))) + cr.execute("Select count(id) from basic_calendar_fields \ + where name=%s and type_id=%s" % (vals.get('name'), vals.get('type_id'))) + res = cr.fetchone() + if res: + if res[0] > 0: + raise osv.except_osv(_('Warning !'), _('Can not map same field more than once')) + return super(basic_calendar_fields, self).create(cr, uid, vals, context=context) + basic_calendar_fields() class Event(CalDAV, osv.osv_memory): diff --git a/addons/base_calendar/base_calendar_view.xml b/addons/base_calendar/base_calendar_view.xml index 0165e483f53..f5b4a274a95 100644 --- a/addons/base_calendar/base_calendar_view.xml +++ b/addons/base_calendar/base_calendar_view.xml @@ -19,7 +19,7 @@ - +
diff --git a/addons/caldav/caldav_data.xml b/addons/caldav/caldav_data.xml index b909bf1dc82..ae380e8f0d7 100644 --- a/addons/caldav/caldav_data.xml +++ b/addons/caldav/caldav_data.xml @@ -143,7 +143,7 @@ - alarm + valarm @@ -170,13 +170,6 @@ field - - - - - field - - @@ -198,13 +191,6 @@ field - - - - - field - - @@ -219,13 +205,6 @@ field - - - - - field - - @@ -284,13 +263,6 @@ - - - - - field - - @@ -298,13 +270,6 @@ field - - - - - field - - @@ -333,13 +298,6 @@ field - - - - - field - - @@ -347,13 +305,6 @@ field - - - - - field - - @@ -368,13 +319,6 @@ field - - - - - hours - - diff --git a/addons/crm/crm_meeting_data.xml b/addons/crm/crm_meeting_data.xml index e1c6a9cadfb..789708c6a35 100644 --- a/addons/crm/crm_meeting_data.xml +++ b/addons/crm/crm_meeting_data.xml @@ -44,14 +44,14 @@ - + field - +