* New Configuration wizard : create calendors for sections which are selected in wizard
* The field code of crm.case have to be unique and when the server  restart it produces identics sequencies 
* Management of the true date format ( instead of a datetime with 9:00  fixed) 
* Add the creation date of the object and the modification date (needed  for iCal on Mac)
* automatic completion of end date if the start date and the length is give
* if the OpenERP field selected for dtend is an integer or a float (instead of a date), write dtstart+duration when generating the ics for dtend. Same for parsing .ics files.

bzr revid: hmo@tinyerp.com-20090508085408-ot6c3mywkmbsi3q2
This commit is contained in:
Harry (Open ERP)
2009-05-08 14:24:08 +05:30
parent 6bc5008acb
commit 1386b88195
8 changed files with 286 additions and 13 deletions
+1
View File
@@ -21,4 +21,5 @@
##############################################################################
import document
import document_ics_config_wizard
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
+1 -1
View File
@@ -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,
+54 -9
View File
@@ -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:
+15 -1
View File
@@ -6,6 +6,20 @@
<field name="code">.ics</field>
<field name="name">ICS Calendar</field>
</record>
</data>
<data noupdate="1">
<record id="seq_type_crm_case_code" model="ir.sequence.type">
<field name="name">CRM Case Code</field>
<field name="code">crm.case</field>
</record>
<record id="seq_sale_order" model="ir.sequence">
<field name="name">CRM Case</field>
<field name="code">crm.case</field>
<field name="prefix">CASE</field>
<field name="padding">3</field>
</record>
</data>
</openerp>
+6 -1
View File
@@ -26,6 +26,11 @@
<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_field6">
<field name="name">dtend</field>
<field name="field_id" ref="crm.field_crm_case_date_deadline"/>
<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"/>
@@ -38,7 +43,7 @@
</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="field_id" ref="crm.field_crm_case_description"/>
<field name="content_id" ref="dir_content_calendar"/>
</record>
<record model="document.directory.ics.fields" id="dir_field5">
@@ -0,0 +1,133 @@
# -*- encoding: utf-8 -*-
##############################################################################
#
# OpenERP, Open Source Management Solution
# Copyright (C) 2004-2009 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 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:
@@ -0,0 +1,50 @@
<?xml version="1.0" encoding="utf-8"?>
<openerp>
<data>
<record id="view_document_ics_config_directories" model="ir.ui.view">
<field name="name">Configure Calendars for Sections</field>
<field name="model">document.ics.crm.wizard</field>
<field name="type">form</field>
<field name="arch" type="xml">
<form string="Configure Calendars for CRM Sections">
<separator colspan="4" string="Create Pre-Configured Calendars"/>
<newline/>
<field name="meeting"/>
<field name="opportunity"/>
<field name="phonecall"/>
<field name="lead"/>
<field name="claims"/>
<field name="bugs"/>
<field name="helpdesk"/>
<field name="jobs"/>
<field name="fund"/>
<newline/>
<group col="4" colspan="4">
<button icon="gtk-cancel" name="action_cancel" type="object" special="cancel" string="Cancel"/>
<button icon="gtk-go-forward" name="action_create" string="Next" type="object"/>
</group>
</form>
</field>
</record>
<record id="action_view_document_ics_config_directories" model="ir.actions.act_window">
<field name="name">Configure Calendars for Sections </field>
<field name="type">ir.actions.act_window</field>
<field name="res_model">document.ics.crm.wizard</field>
<field name="view_type">form</field>
<field name="view_mode">form</field>
<field name="target">new</field>
</record>
<!-- register configuration wizard -->
<record id="config_wizard_step_case_section_menu" model="ir.actions.todo">
<field name="name">Create Calendars for CRM Case Section</field>
<field name="note">This Configuration step use to create Calendars in document for all Case Sections</field>
<field name="action_id" ref="action_view_document_ics_config_directories"/>
</record>
</data>
</openerp>
+26 -1
View File
@@ -20,6 +20,31 @@
</field>
</field>
</record>
<record model="ir.ui.view" id="view_case_inherit_form">
<field name="name">crm.case.code.form</field>
<field name="model">crm.case</field>
<field name="type">form</field>
<field name="inherit_id" ref="crm.crm_case-view"/>
<field name="arch" type="xml">
<field name="priority" position="after">
<field name="code"/>
</field>
</field>
</record>
<record model="ir.ui.view" id="view_case_inherit_form1">
<field name="name">crm.case.inherit.form1</field>
<field name="model">crm.case</field>
<field name="type">form</field>
<field name="inherit_id" ref="crm.crm_case-view"/>
<field name="arch" type="xml">
<field name="date" position="replace">
<field name="date" on_change="on_change_duration(date, duration)" required="1"/>
<field name="duration" string="Duration(In Hour)" on_change="on_change_duration(date, duration)" widget="float_time"/>
</field>
</field>
</record>
</data>
</openerp>