summaryrefslogtreecommitdiff
path: root/addons/document_ics
diff options
context:
space:
mode:
authorNaresh Choksy <nch@tinyerp.com>2008-11-04 11:16:45 +0530
committerNaresh Choksy <nch@tinyerp.com>2008-11-04 11:16:45 +0530
commit2a4096b752f3634fe255ecd78e842e11d1801a67 (patch)
tree9ed47e680afe293497461adf430f146c60e97da2 /addons/document_ics
parent54651e2f34af1412df5ab5d3e371bdc4d0600b23 (diff)
parentda8aa7411aef2f2b962b2b67b73563dce4c45bee (diff)
merges
bzr revid: nch@tinyerp.com-20081104054645-pqtvoho3hiyjb2yf
Diffstat (limited to 'addons/document_ics')
-rw-r--r--addons/document_ics/__init__.py23
-rw-r--r--addons/document_ics/__terp__.py40
-rw-r--r--addons/document_ics/document.py145
-rw-r--r--addons/document_ics/document_data.xml11
-rw-r--r--addons/document_ics/document_demo.xml46
-rw-r--r--addons/document_ics/document_view.xml25
-rw-r--r--addons/document_ics/security/ir.model.access.csv3
7 files changed, 293 insertions, 0 deletions
diff --git a/addons/document_ics/__init__.py b/addons/document_ics/__init__.py
new file mode 100644
index 00000000000..34f033ff550
--- /dev/null
+++ b/addons/document_ics/__init__.py
@@ -0,0 +1,23 @@
+# -*- encoding: utf-8 -*-
+##############################################################################
+#
+# OpenERP, Open Source Management Solution
+# Copyright (C) 2004-2008 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/>.
+#
+##############################################################################
+
+import document
diff --git a/addons/document_ics/__terp__.py b/addons/document_ics/__terp__.py
new file mode 100644
index 00000000000..ba665a6efba
--- /dev/null
+++ b/addons/document_ics/__terp__.py
@@ -0,0 +1,40 @@
+# -*- encoding: utf-8 -*-
+##############################################################################
+#
+# OpenERP, Open Source Management Solution
+# Copyright (C) 2004-2008 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/>.
+#
+##############################################################################
+{
+ "name" : "Suport for iCal based on Document Management System",
+ "version" : "1.0",
+ "author" : "Tiny",
+ "category" : "Generic Modules/Others",
+ "website": "http://www.tinyerp.com",
+ "description": """Allows to synchronize calendars with others applications.""",
+ "depends" : ["document","crm_configuration"],
+ "init_xml" : ["document_data.xml"],
+ "update_xml" : [
+ "document_view.xml",
+ "security/ir.model.access.csv",
+ ],
+ "demo_xml" : [
+ "document_demo.xml"
+ ],
+ "active": False,
+ "installable": True
+}
diff --git a/addons/document_ics/document.py b/addons/document_ics/document.py
new file mode 100644
index 00000000000..e131ecaa9a4
--- /dev/null
+++ b/addons/document_ics/document.py
@@ -0,0 +1,145 @@
+# -*- encoding: utf-8 -*-
+##############################################################################
+#
+# OpenERP, Open Source Management Solution
+# Copyright (C) 2004-2008 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 osv, fields
+from osv.orm import except_orm
+import os
+import StringIO
+import base64
+import datetime
+import time
+import random
+
+ICS_TAGS = {
+ 'summary':'normal',
+ 'uid':'normal' ,
+ 'dtstart':'date' ,
+ 'dtend':'date' ,
+ 'created':'date' ,
+ 'dt-stamp':'date' ,
+ 'last-modified':'normal' ,
+ 'url':'normal' ,
+ 'attendee':'multiple',
+ 'location':'normal',
+ 'categories': 'normal',
+ 'description':'normal'
+}
+
+class document_directory_ics_fields(osv.osv):
+ _name = 'document.directory.ics.fields'
+ _columns = {
+ 'field_id': fields.many2one('ir.model.fields', 'Open ERP Field', required=True),
+ 'name': fields.selection(map(lambda x: (x,x), ICS_TAGS.keys()),'ICS Value', required=True),
+ 'content_id': fields.many2one('document.directory.content', 'Content', required=True, ondelete='cascade')
+ }
+document_directory_ics_fields()
+
+class document_directory_content(osv.osv):
+ _inherit = 'document.directory.content'
+ _columns = {
+ 'ics_object_id': fields.many2one('ir.model', 'Object'),
+ 'ics_domain': fields.char('Domain', size=64),
+ 'ics_field_ids': fields.one2many('document.directory.ics.fields', 'content_id', 'Fields Mapping')
+ }
+ _defaults = {
+ 'ics_domain': lambda *args: '[]'
+ }
+ def process_write_ics(self, cr, uid, node, data, context={}):
+ import vobject
+ parsedCal = vobject.readOne(data)
+ fields = {}
+ fobj = self.pool.get('document.directory.content')
+ content = fobj.browse(cr, uid, node.content.id, context)
+
+ idomain = {}
+ for d in eval(content.ics_domain):
+ idomain[d[0]]=d[2]
+ for n in content.ics_field_ids:
+ fields[n.name] = n.field_id.name
+ if 'uid' not in fields:
+ return True
+ for child in parsedCal.getChildren():
+ result = {}
+ uuid = None
+ for event in child.getChildren():
+ if event.name.lower()=='uid':
+ uuid = event.value
+ if event.name.lower() in fields:
+ if ICS_TAGS[event.name.lower()]=='normal':
+ result[fields[event.name.lower()]] = event.value.encode('utf8')
+ elif ICS_TAGS[event.name.lower()]=='date':
+ result[fields[event.name.lower()]] = event.value.strftime('%Y-%m-%d %H:%M:%S')
+ if not uuid:
+ continue
+
+ fobj = self.pool.get(content.ics_object_id.model)
+ id = fobj.search(cr, uid, [(fields['uid'], '=', uuid.encode('utf8'))], context=context)
+ if id:
+ fobj.write(cr, uid, id, result, context=context)
+ else:
+ r = idomain.copy()
+ r.update(result)
+ fobj.create(cr, uid, r, context=context)
+
+ return True
+
+ def process_read_ics(self, cr, uid, node, context={}):
+ import vobject
+ obj_class = self.pool.get(node.content.ics_object_id.model)
+ # Can be improved to use context and active_id !
+ domain = eval(node.content.ics_domain)
+ ids = obj_class.search(cr, uid, domain, context)
+ cal = vobject.iCalendar()
+ for obj in obj_class.browse(cr, uid, ids, context):
+ event = cal.add('vevent')
+ for field in node.content.ics_field_ids:
+ value = getattr(obj, field.field_id.name)
+ if (not value) and field.name=='uid':
+ value = 'OpenERP-'+str(random.randint(1999999999, 9999999999))
+ obj_class.write(cr, uid, [obj.id], {field.field_id.name: value})
+ if ICS_TAGS[field.name]=='normal':
+ if type(value)==type(obj):
+ value=value.name
+ value = value or ''
+ print value
+ event.add(field.name).value = value and value.decode('utf8') or ''
+ elif ICS_TAGS[field.name]=='date':
+ dt = value or time.strftime('%Y-%m-%d %H:%M:%S')
+ if len(dt)==10:
+ dt = dt+' 09:00:00'
+ value = datetime.datetime.strptime(dt, '%Y-%m-%d %H:%M:%S')
+ if field.name=='dtend':
+ value += datetime.timedelta(hours=2)
+ event.add(field.name).value = value
+ s= StringIO.StringIO(cal.serialize().encode('utf8'))
+ s.name = node
+ cr.commit()
+ return s
+document_directory_content()
+
+class crm_case(osv.osv):
+ _inherit = 'crm.case'
+ _columns = {
+ 'code': fields.char('Calendar Code', size=64)
+ }
+crm_case()
+
diff --git a/addons/document_ics/document_data.xml b/addons/document_ics/document_data.xml
new file mode 100644
index 00000000000..5e2873aee6f
--- /dev/null
+++ b/addons/document_ics/document_data.xml
@@ -0,0 +1,11 @@
+<?xml version="1.0"?>
+<openerp>
+<data>
+
+ <record model="document.directory.content.type" id="ics">
+ <field name="code">.ics</field>
+ <field name="name">ICS Calendar</field>
+ </record>
+
+</data>
+</openerp>
diff --git a/addons/document_ics/document_demo.xml b/addons/document_ics/document_demo.xml
new file mode 100644
index 00000000000..013c990c71a
--- /dev/null
+++ b/addons/document_ics/document_demo.xml
@@ -0,0 +1,46 @@
+<?xml version="1.0"?>
+<openerp>
+<data noupdate="1">
+
+ <record model="document.directory" id="dir_calendars">
+ <field name="name">Calendars</field>
+ </record>
+
+ <record model="document.directory.content" id="dir_content_calendar">
+ <field name="name">Calendars</field>
+ <field name="suffix">meetings</field>
+ <field name="directory_id" ref="dir_calendars"/>
+ <field name="extension">.ics</field>
+ <field name="include_name" eval="False"/>
+ <field name="ics_object_id" ref="crm.model_crm_case"/>
+ <field name="ics_domain">[('section_id','=','Calendar')]</field>
+ </record>
+
+ <record model="document.directory.ics.fields" id="dir_field1">
+ <field name="name">dtstart</field>
+ <field name="field_id" ref="crm.field_crm_case_date"/>
+ <field name="content_id" ref="dir_content_calendar"/>
+ </record>
+ <record model="document.directory.ics.fields" id="dir_field2">
+ <field name="name">summary</field>
+ <field name="field_id" ref="crm.field_crm_case_name"/>
+ <field name="content_id" ref="dir_content_calendar"/>
+ </record>
+ <record model="document.directory.ics.fields" id="dir_field3">
+ <field name="name">uid</field>
+ <field name="field_id" ref="field_crm_case_code"/>
+ <field name="content_id" ref="dir_content_calendar"/>
+ </record>
+ <record model="document.directory.ics.fields" id="dir_field4">
+ <field name="name">description</field>
+ <field name="field_id" ref="crm_configuration.field_crm_case_note"/>
+ <field name="content_id" ref="dir_content_calendar"/>
+ </record>
+ <record model="document.directory.ics.fields" id="dir_field5">
+ <field name="name">url</field>
+ <field name="field_id" ref="crm.field_crm_case_email_from"/>
+ <field name="content_id" ref="dir_content_calendar"/>
+ </record>
+
+</data>
+</openerp>
diff --git a/addons/document_ics/document_view.xml b/addons/document_ics/document_view.xml
new file mode 100644
index 00000000000..bdc82d5e6d2
--- /dev/null
+++ b/addons/document_ics/document_view.xml
@@ -0,0 +1,25 @@
+<openerp>
+<data>
+
+ <record model="ir.ui.view" id="view_document_directory_form">
+ <field name="name">document.directory</field>
+ <field name="model">document.directory</field>
+ <field name="type">form</field>
+ <field name="inherit_id" ref="document.view_document_directory_form"/>
+ <field name="arch" type="xml">
+ <field name="report_id" position="after">
+ <separator string="ICS Calendar" colspan="4"/>
+ <field name="ics_object_id"/>
+ <field name="ics_domain"/>
+ <field name="ics_field_ids" colspan="4">
+ <tree string="ICS Mapping" editable="bottom">
+ <field name="name"/>
+ <field name="field_id" domain="[('model_id','=',parent.ics_object_id)]"/>
+ </tree>
+ </field>
+ </field>
+ </field>
+ </record>
+
+</data>
+</openerp>
diff --git a/addons/document_ics/security/ir.model.access.csv b/addons/document_ics/security/ir.model.access.csv
new file mode 100644
index 00000000000..a89c5b296a7
--- /dev/null
+++ b/addons/document_ics/security/ir.model.access.csv
@@ -0,0 +1,3 @@
+"id","name","model_id:id","group_id:id","perm_read","perm_write","perm_create","perm_unlink"
+"access_document_directory_ics_fields_all","document.directory.ics.fields all","model_document_directory_ics_fields",,1,0,0,0
+"access_document_directory_ics_fields_manager","document.directory.ics.fields group system","model_document_directory_ics_fields","base.group_system",1,1,1,1