diff --git a/addons/document_ics/__init__.py b/addons/document_ics/__init__.py
index faf96b9d189..a651d00614b 100644
--- a/addons/document_ics/__init__.py
+++ b/addons/document_ics/__init__.py
@@ -21,4 +21,5 @@
##############################################################################
import document
+import document_ics_config_wizard
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
diff --git a/addons/document_ics/__terp__.py b/addons/document_ics/__terp__.py
index d5adf71e88f..9e3d85295da 100644
--- a/addons/document_ics/__terp__.py
+++ b/addons/document_ics/__terp__.py
@@ -30,7 +30,7 @@
'website': 'http://www.openerp.com',
'depends': ['document', 'crm_configuration'],
'init_xml': ['document_data.xml'],
- 'update_xml': ['document_view.xml', 'security/ir.model.access.csv'],
+ 'update_xml': ['document_view.xml', 'security/ir.model.access.csv','document_ics_config_wizard.xml'],
'demo_xml': ['document_demo.xml'],
'installable': True,
'active': False,
diff --git a/addons/document_ics/document.py b/addons/document_ics/document.py
index f936c352d83..048a82c7680 100644
--- a/addons/document_ics/document.py
+++ b/addons/document_ics/document.py
@@ -28,6 +28,7 @@ import base64
import datetime
import time
import random
+import tools
ICS_TAGS = {
'summary':'normal',
@@ -35,7 +36,7 @@ ICS_TAGS = {
'dtstart':'date' ,
'dtend':'date' ,
'created':'date' ,
- 'dt-stamp':'date' ,
+ 'dtstamp':'date' ,
'last-modified':'normal' ,
'url':'normal' ,
'attendee':'multiple',
@@ -50,7 +51,7 @@ 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),
+ '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()
@@ -105,6 +106,12 @@ class document_directory_content(osv.osv):
return True
def process_read_ics(self, cr, uid, node, context={}):
+ def ics_datetime(idate, short=False):
+ if short:
+ return datetime.date.fromtimestamp(time.mktime(time.strptime(idate, '%Y-%m-%d')))
+ else:
+ return datetime.datetime.strptime(idate, '%Y-%m-%d %H:%M:%S')
+
import vobject
obj_class = self.pool.get(node.content.ics_object_id.model)
# Can be improved to use context and active_id !
@@ -113,21 +120,31 @@ class document_directory_content(osv.osv):
cal = vobject.iCalendar()
for obj in obj_class.browse(cr, uid, ids, context):
event = cal.add('vevent')
+ # Fix dtstamp et last-modified with create and write date on the object line
+ perm = obj_class.perm_read(cr, uid, [obj.id], context)
+ event.add('created').value = ics_datetime(time.strftime('%Y-%m-%d %H:%M:%S'))
+ event.add('dtstamp').value = ics_datetime(perm[0]['create_date'][:19])
+ if perm[0]['write_date']:
+ event.add('last-modified').value = ics_datetime(perm[0]['write_date'][:19])
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))
+ value = 'OpenERP-%s_%s@%s' % (node.content.ics_object_id.model, str(obj.id), cr.dbname,)
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 ''
event.add(field.name).value = value 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')
+ elif ICS_TAGS[field.name]=='date' and value:
+ if field.name == 'dtstart':
+ date_start = start_date = datetime.datetime.fromtimestamp(time.mktime(time.strptime(value , "%Y-%m-%d %H:%M:%S")))
+ if field.name == 'dtend' and isinstance(value, float):
+ value = (start_date + datetime.timedelta(hours=value)).strftime('%Y-%m-%d %H:%M:%S')
+ if len(value)==10:
+ value = ics_datetime(value, True)
+ else:
+ value = ics_datetime(value)
event.add(field.name).value = value
s= StringIO.StringIO(cal.serialize().encode('utf8'))
s.name = node
@@ -138,8 +155,36 @@ document_directory_content()
class crm_case(osv.osv):
_inherit = 'crm.case'
_columns = {
- 'code': fields.char('Calendar Code', size=64)
+ 'code': fields.char('Calendar Code', size=64),
+ 'date_deadline': fields.datetime('Deadline', help="Deadline Date is automatically computed from Start Date + Duration"),
}
+
+ _defaults = {
+ 'code': lambda obj, cr, uid, context: obj.pool.get('ir.sequence').get(cr, uid, 'crm.case'),
+ }
+
+ def copy(self, cr, uid, id, default=None, context=None):
+ """
+ code field must be unique in ICS file
+ """
+ if not default: default = {}
+ if not context: context = {}
+ default.update({'code': self.pool.get('ir.sequence').get(cr, uid, 'crm.case'), 'id': False})
+ return super(crm_case, self).copy(cr, uid, id, default, context)
+
+ def on_change_duration(self, cr, uid, id, date, duration):
+ if not date:
+ return {}
+ start_date = datetime.datetime.fromtimestamp(time.mktime(time.strptime(date, "%Y-%m-%d %H:%M:%S")))
+ if duration >= 0 :
+ end = start_date + datetime.timedelta(hours=duration)
+ if duration < 0:
+ raise osv.except_osv(_('Warning !'),
+ _('You can not set negative Duration.'))
+
+ res = {'value' : {'date_deadline' : end.strftime('%Y-%m-%d %H:%M:%S')}}
+ return res
+
crm_case()
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
diff --git a/addons/document_ics/document_data.xml b/addons/document_ics/document_data.xml
index 5e2873aee6f..d2e83a35f40 100644
--- a/addons/document_ics/document_data.xml
+++ b/addons/document_ics/document_data.xml
@@ -6,6 +6,20 @@
.ics
ICS Calendar
-
+
+
+
+
+ CRM Case Code
+ crm.case
+
+
+ CRM Case
+ crm.case
+ CASE
+ 3
+
+
+
diff --git a/addons/document_ics/document_demo.xml b/addons/document_ics/document_demo.xml
index eb939cfd515..964be6511e0 100644
--- a/addons/document_ics/document_demo.xml
+++ b/addons/document_ics/document_demo.xml
@@ -26,6 +26,11 @@
+
+ dtend
+
+
+
summary
@@ -38,7 +43,7 @@
description
-
+
diff --git a/addons/document_ics/document_ics_config_wizard.py b/addons/document_ics/document_ics_config_wizard.py
new file mode 100644
index 00000000000..9a2b738ce50
--- /dev/null
+++ b/addons/document_ics/document_ics_config_wizard.py
@@ -0,0 +1,133 @@
+ # -*- encoding: utf-8 -*-
+##############################################################################
+#
+# OpenERP, Open Source Management Solution
+# Copyright (C) 2004-2009 Tiny SPRL (). 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 .
+#
+##############################################################################
+
+import time
+import tools
+from osv import fields, osv, orm
+import os
+import mx.DateTime
+import base64
+import pooler
+
+SECTION_NAME = {
+ 'meeting' : 'Meetings',
+ 'lead':'Prospects',
+ 'opportunity':'Opportunities',
+ 'jobs':'Jobs',
+ 'bugs':'Bug Tracking',
+ 'fund':'Fund Raising',
+ 'helpdesk':'HelpDesk',
+ 'claims':'Claims',
+ 'phonecall':'Phone Calls',
+ }
+
+ICS_TAGS = {
+ 'summary':'Description',
+ 'uid':'Calendar Code' ,
+ 'dtstart':'Date' ,
+ 'dtend':'Deadline' ,
+ 'url':'Partner Email' ,
+ 'description':'Your action',
+ }
+
+class document_ics_crm_wizard(osv.osv_memory):
+ _name='document.ics.crm.wizard'
+ _columns = {
+ 'name':fields.char('Name', size=64),
+ 'meeting' : fields.boolean('Calendar of Meetings', help="Manages the calendar of meetings of the users."),
+ 'lead' : fields.boolean('Prospect', help="Allows you to track and manage prospects which are pre-sales requests or contacts, the very first contact with a customer request."),
+ 'opportunity' : fields.boolean('Business Opportunities', help="Tracks identified business opportunities for your sales pipeline."),
+ 'jobs' : fields.boolean('Jobs Hiring Process', help="Help you to organise the jobs hiring process: evaluation, meetings, email integration..."),
+ 'document_ics':fields.boolean('Shared Calendar', help=" Will allow you to synchronise your Open ERP calendars with your phone, outlook, Sunbird, ical, ..."),
+ 'bugs' : fields.boolean('Bug Tracking', help="Used by companies to track bugs and support requests on softwares"),
+ 'helpdesk': fields.boolean('Helpdesk', help="Manages an Helpdesk service."),
+ 'fund' : fields.boolean('Fund Raising Operations', help="This may help associations in their fund raising process and tracking."),
+ 'claims' : fields.boolean('Claims', help="Manages the supplier and customers claims, including your corrective or preventive actions."),
+ 'phonecall' : fields.boolean('Phone Calls', help="Help you to encode the result of a phone call or to planify a list of phone calls to process."),
+ }
+ _defaults = {
+ 'meeting': lambda *args: True,
+ 'opportunity': lambda *args: True,
+ 'phonecall': lambda *args: True,
+ }
+
+ def action_create(self, cr, uid, ids, context=None):
+ data=self.read(cr, uid, ids, [])[0]
+ dir_obj = self.pool.get('document.directory')
+ dir_cont_obj = self.pool.get('document.directory.content')
+ dir_id = dir_obj.search(cr, uid, [('name', '=', 'Calendars')])
+ if dir_id:
+ dir_id = dir_id[0]
+ else:
+ dir_id = dir_obj.create(cr, uid, {'name': 'Calendars' ,'user_id' : uid, 'type': 'directory'})
+ for section in ['meeting', 'lead', 'opportunity', 'jobs', 'bugs', 'fund', 'helpdesk', 'claims', 'phonecall']:
+ if (not data[section]):
+ continue
+ else:
+ section_id=self.pool.get('crm.case.section').search(cr, uid, [('name', '=', SECTION_NAME[section])])
+ if not section_id:
+ continue
+ else:
+ object_id=self.pool.get('ir.model').search(cr, uid, [('name', '=', 'Case')])[0]
+
+ vals_cont={
+ 'name': SECTION_NAME[section],
+ 'sequence': 1,
+ 'directory_id': dir_id,
+ 'suffix': section,
+ 'extension': '.ics',
+ 'ics_object_id': object_id,
+ 'ics_domain': [('section_id', '=', section_id[0])],
+ 'include_name' : False
+ }
+
+ content_id = dir_cont_obj.create(cr, uid, vals_cont)
+
+ ics_obj=self.pool.get('document.directory.ics.fields')
+ for tag in ['description', 'url', 'summary', 'dtstart', 'dtend', 'uid']:
+ field_id = self.pool.get('ir.model.fields').search(cr, uid, [('model_id.name', '=', 'Case'), ('field_description', '=', ICS_TAGS[tag])])[0]
+ vals_ics={
+ 'field_id': field_id ,
+ 'name': tag ,
+ 'content_id': content_id ,
+ }
+ ics_obj.create(cr, uid, vals_ics)
+
+ return {
+ 'view_type': 'form',
+ "view_mode": 'form',
+ 'res_model': 'ir.actions.configuration.wizard',
+ 'type': 'ir.actions.act_window',
+ 'target':'new',
+ }
+ def action_cancel(self, cr, uid, ids, conect=None):
+ return {
+ 'view_type': 'form',
+ "view_mode": 'form',
+ 'res_model': 'ir.actions.configuration.wizard',
+ 'type': 'ir.actions.act_window',
+ 'target':'new',
+ }
+
+document_ics_crm_wizard()
+
+# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
diff --git a/addons/document_ics/document_ics_config_wizard.xml b/addons/document_ics/document_ics_config_wizard.xml
new file mode 100644
index 00000000000..9c2132bc89d
--- /dev/null
+++ b/addons/document_ics/document_ics_config_wizard.xml
@@ -0,0 +1,50 @@
+
+
+
+
+
+ Configure Calendars for Sections
+ document.ics.crm.wizard
+ form
+
+
+
+
+
+
+ Configure Calendars for Sections
+ ir.actions.act_window
+ document.ics.crm.wizard
+ form
+ form
+ new
+
+
+
+
+
+
+
+
+
diff --git a/addons/document_ics/document_view.xml b/addons/document_ics/document_view.xml
index bdc82d5e6d2..1623be30af6 100644
--- a/addons/document_ics/document_view.xml
+++ b/addons/document_ics/document_view.xml
@@ -20,6 +20,31 @@
-
+
+
+ crm.case.code.form
+ crm.case
+ form
+
+
+
+
+
+
+
+
+
+ crm.case.inherit.form1
+ crm.case
+ form
+
+
+
+
+
+
+
+
+