[REF+IMP] document
bzr revid: hmo@tinyerp.com-20100413110320-9x1fy7l432sinxvd
This commit is contained in:
parent
5227249134
commit
6a94de909b
|
@ -25,31 +25,60 @@ import pooler
|
|||
import tools
|
||||
import time
|
||||
import base64
|
||||
from document import nodes
|
||||
import StringIO
|
||||
|
||||
class node_database(nodes.node_database):
|
||||
def _child_get(self, cr, name=False, parent_id=False, domain=None):
|
||||
dirobj = self.context._dirobj
|
||||
uid = self.context.uid
|
||||
ctx = self.context.context.copy()
|
||||
ctx.update(self.dctx)
|
||||
if not domain:
|
||||
domain = []
|
||||
domain2 = domain + [('calendar_collection','=', False)]
|
||||
res = super(node_database, self)._child_get(cr, name=name, parent_id=parent_id, domain=domain2)
|
||||
where = [('parent_id','=',parent_id)]
|
||||
domain2 = domain + [('calendar_collection','=', True)]
|
||||
if name:
|
||||
where.append(('name','=',name))
|
||||
if domain2:
|
||||
where += domain2
|
||||
|
||||
class node_calendar(object):
|
||||
def __init__(self, path, context, calendar):
|
||||
self.path = path
|
||||
self.context = context
|
||||
self.calendar_id = calendar.id
|
||||
self.mimetype = 'ics'
|
||||
self.create_date = calendar.create_date
|
||||
self.write_date = calendar.write_date or calendar.create_date
|
||||
self.content_length = 0
|
||||
self.displayname = calendar.name
|
||||
where2 = where + [('type', '=', 'directory')]
|
||||
ids = dirobj.search(cr, uid, where2, context=ctx)
|
||||
for dirr in dirobj.browse(cr,uid,ids,context=ctx):
|
||||
res.append(node_calendar_collection(dirr.name,self,self.context,dirr))
|
||||
return res
|
||||
|
||||
class node_calendar_collection(nodes.node_dir):
|
||||
def get_dav_props(self, cr):
|
||||
res = {}
|
||||
return res
|
||||
|
||||
def get_data(self, cr, uid):
|
||||
calendar_obj = pooler.get_pool(cr.dbname).get('basic.calendar')
|
||||
return calendar_obj.export_cal(cr, uid, [self.calendar_id])
|
||||
def get_dav_eprop(self,cr,ns,prop):
|
||||
return None
|
||||
|
||||
def get_data_len(self, cr):
|
||||
return self.content_length
|
||||
|
||||
def set_data(self, cr, uid, data):
|
||||
calendar_obj = pooler.get_pool(cr.dbname).get('basic.calendar')
|
||||
return calendar_obj.import_cal(cr, uid, base64.encodestring(data), self.calendar_id)
|
||||
def _child_get(self, cr, name=False, parent_id=False, domain=None):
|
||||
dirobj = self.context._dirobj
|
||||
uid = self.context.uid
|
||||
ctx = self.context.context.copy()
|
||||
ctx.update(self.dctx)
|
||||
where = [('collection_id','=',self.dir_id)]
|
||||
if name:
|
||||
where.append(('name','=',name))
|
||||
if not domain:
|
||||
domain = []
|
||||
|
||||
fil_obj = dirobj.pool.get('basic.calendar')
|
||||
ids = fil_obj.search(cr,uid,where,context=ctx)
|
||||
res = []
|
||||
if ids:
|
||||
for fil in fil_obj.browse(cr,uid,ids,context=ctx):
|
||||
res.append(node_calendar(fil.name,self,self.context,fil))
|
||||
return res
|
||||
|
||||
|
||||
def get_etag(self, cr):
|
||||
""" Get a tag, unique per object + modification.
|
||||
|
||||
|
@ -64,24 +93,64 @@ class node_calendar(object):
|
|||
return str(wtime)
|
||||
|
||||
def _get_ttag(self, cr):
|
||||
return 'calendar collection-%d' % self.dir_id
|
||||
|
||||
class node_calendar(nodes.node_class):
|
||||
our_type = 'file'
|
||||
def __init__(self,path, parent, context, calendar):
|
||||
super(node_calendar,self).__init__(path, parent,context)
|
||||
self.calendar_id = calendar.id
|
||||
self.mimetype = 'ics'
|
||||
self.create_date = calendar.create_date
|
||||
self.write_date = calendar.write_date or calendar.create_date
|
||||
self.content_length = 0
|
||||
self.displayname = calendar.name
|
||||
|
||||
def open(self, cr, mode=False):
|
||||
uid = self.context.uid
|
||||
if self.type in ('collection','database'):
|
||||
return False
|
||||
fobj = self.context._dirobj.pool.get('basic.calendar').browse(cr, uid, self.calendar_id, context=self.context.context)
|
||||
s = StringIO.StringIO(self.get_data(cr, fobj))
|
||||
s.name = self
|
||||
return s
|
||||
|
||||
def get_dav_props(self, cr):
|
||||
res = {}
|
||||
return res
|
||||
|
||||
def get_dav_eprop(self,cr,ns,prop):
|
||||
return None
|
||||
|
||||
|
||||
def get_data(self, cr, fil_obj = None):
|
||||
uid = self.context.uid
|
||||
calendar_obj = self.context._dirobj.pool.get('basic.calendar')
|
||||
return calendar_obj.export_cal(cr, uid, [self.calendar_id])
|
||||
|
||||
def get_data_len(self, cr, fil_obj = None):
|
||||
return self.content_length
|
||||
|
||||
def set_data(self, cr, data, fil_obj = None):
|
||||
uid = self.context.uid
|
||||
calendar_obj = self.context._dirobj.pool.get('basic.calendar')
|
||||
return calendar_obj.import_cal(cr, uid, base64.encodestring(data), self.calendar_id)
|
||||
|
||||
def _get_ttag(self,cr):
|
||||
return 'calendar-%d' % self.calendar_id
|
||||
|
||||
|
||||
|
||||
class Calendar(osv.osv):
|
||||
_inherit = 'basic.calendar'
|
||||
def get_etag(self, cr):
|
||||
""" Get a tag, unique per object + modification.
|
||||
|
||||
def get_calendar_object(self, cr, uid, uri, context=None):
|
||||
if not uri:
|
||||
return None
|
||||
if len(uri) > 1:
|
||||
return None
|
||||
name, file_type = tuple(uri[0].split('.'))
|
||||
res = self.name_search(cr, uid, name)
|
||||
if not res:
|
||||
return None
|
||||
calendar_id, calendar_name = res[0]
|
||||
calendar = self.browse(cr, uid, calendar_id)
|
||||
return node_calendar(uri, context, calendar)
|
||||
Calendar()
|
||||
see. http://tools.ietf.org/html/rfc2616#section-13.3.3 """
|
||||
return self._get_ttag(cr) + ':' + self._get_wtag(cr)
|
||||
|
||||
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4
|
||||
def _get_wtag(self, cr):
|
||||
""" Return the modification time as a unique, compact string """
|
||||
if self.write_date:
|
||||
wtime = time.mktime(time.strptime(self.write_date, '%Y-%m-%d %H:%M:%S'))
|
||||
else: wtime = time.time()
|
||||
return str(wtime)
|
||||
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4
|
||||
|
|
|
@ -17,8 +17,7 @@
|
|||
<record model="ir.ui.view" id="view_calendar_collection_tree">
|
||||
<field name="name">Calendar Collections : Tree</field>
|
||||
<field name="model">document.directory</field>
|
||||
<field name="type">tree</field>
|
||||
<field name="field_parent">child_ids</field>
|
||||
<field name="type">tree</field>
|
||||
<field name="arch" type="xml">
|
||||
<tree string="Calendar Collections" toolbar="1">
|
||||
<field name="name"/>
|
||||
|
|
|
@ -31,7 +31,7 @@ import pytz
|
|||
import re
|
||||
import tools
|
||||
import time
|
||||
|
||||
import caldav_node
|
||||
|
||||
try:
|
||||
import vobject
|
||||
|
@ -418,7 +418,12 @@ class calendar_collection(osv.osv):
|
|||
}
|
||||
_default = {
|
||||
'calendar_collection' : False,
|
||||
}
|
||||
}
|
||||
def _locate_child(self, cr, uid, root_id, uri,nparent, ncontext):
|
||||
""" try to locate the node in uri,
|
||||
Return a tuple (node_dir, remaining_path)
|
||||
"""
|
||||
return (caldav_node.node_database(context=ncontext), uri)
|
||||
|
||||
calendar_collection()
|
||||
|
||||
|
@ -449,6 +454,19 @@ class Calendar(CalDAV, osv.osv):
|
|||
'write_date': fields.datetime('Modifided Date'),
|
||||
}
|
||||
|
||||
def get_calendar_object(self, cr, uid, uri, context=None):
|
||||
if not uri:
|
||||
return None
|
||||
if len(uri) > 1:
|
||||
return None
|
||||
name, file_type = tuple(uri[0].split('.'))
|
||||
res = self.name_search(cr, uid, name)
|
||||
if not res:
|
||||
return None
|
||||
calendar_id, calendar_name = res[0]
|
||||
calendar = self.browse(cr, uid, calendar_id)
|
||||
return node_calendar(uri, context, calendar)
|
||||
|
||||
def export_cal(self, cr, uid, ids, vobj='vevent', context={}):
|
||||
""" Export Calendar
|
||||
@param self: The object pointer
|
||||
|
|
|
@ -93,8 +93,7 @@ class document_directory(osv.osv):
|
|||
'user_id': lambda self,cr,uid,ctx: uid,
|
||||
'domain': lambda self,cr,uid,ctx: '[]',
|
||||
'type': lambda *args: 'directory',
|
||||
'ressource_id': lambda *a: 0,
|
||||
'parent_id': _get_root_directory,
|
||||
'ressource_id': lambda *a: 0,
|
||||
'storage_id': _get_def_storage,
|
||||
}
|
||||
_sql_constraints = [
|
||||
|
@ -198,52 +197,11 @@ class document_directory(osv.osv):
|
|||
raise
|
||||
|
||||
|
||||
def _locate_child(self, cr,uid, root_id, uri,nparent, ncontext):
|
||||
def _locate_child(self, cr, uid, root_id, uri,nparent, ncontext):
|
||||
""" try to locate the node in uri,
|
||||
Return a tuple (node_dir, remaining_path)
|
||||
"""
|
||||
did = root_id
|
||||
duri = uri
|
||||
path = []
|
||||
context = ncontext.context
|
||||
while len(duri):
|
||||
nid = self.search(cr,uid,[('parent_id','=',did),('name','=',duri[0]),('type','=','directory')], context=context)
|
||||
if not nid:
|
||||
break
|
||||
if len(nid)>1:
|
||||
print "Duplicate dir? p= %d, n=\"%s\"" %(did,duri[0])
|
||||
path.append(duri[0])
|
||||
duri = duri[1:]
|
||||
did = nid[0]
|
||||
root_node = did and self.browse(cr,uid,did, context) or False
|
||||
return (nodes.node_dir(path, nparent,ncontext, root_node), duri)
|
||||
|
||||
|
||||
nid = self.search(cr,uid,[('parent_id','=',did),('name','=',duri[0]),('type','=','ressource')], context=context)
|
||||
if nid:
|
||||
if len(nid)>1:
|
||||
print "Duplicate dir? p= %d, n=\"%s\"" %(did,duri[0])
|
||||
path.append(duri[0])
|
||||
duri = duri[1:]
|
||||
did = nid[0]
|
||||
return nodes.node_res_dir(path, nparent,ncontext,self.browse(cr,uid,did, context))
|
||||
|
||||
# Here, we must find the appropriate non-dir child..
|
||||
# Chech for files:
|
||||
fil_obj = self.pool.get('ir.attachment')
|
||||
nid = fil_obj.search(cr,uid,[('parent_id','=',did),('name','=',duri[0])],context=context)
|
||||
if nid:
|
||||
if len(duri)>1:
|
||||
# cannot treat child as a dir
|
||||
return None
|
||||
if len(nid)>1:
|
||||
print "Duplicate file?",did,duri[0]
|
||||
path.append(duri[0])
|
||||
return nodes.node_file(path,nparent,ncontext,fil_obj.browse(cr,uid,nid[0],context))
|
||||
|
||||
print "nothing found:",did, duri
|
||||
#still, nothing found
|
||||
return None
|
||||
return (nodes.node_database(context=ncontext), uri)
|
||||
|
||||
def old_code():
|
||||
if not uri:
|
||||
|
|
|
@ -118,8 +118,7 @@
|
|||
<record model="ir.ui.view" id="view_document_directory_tree">
|
||||
<field name="name">document.directory</field>
|
||||
<field name="model">document.directory</field>
|
||||
<field name="type">tree</field>
|
||||
<field name="field_parent">child_ids</field>
|
||||
<field name="type">tree</field>
|
||||
<field name="arch" type="xml">
|
||||
<tree string="Directories" toolbar="1">
|
||||
<field name="name"/>
|
||||
|
|
|
@ -20,7 +20,7 @@
|
|||
##############################################################################
|
||||
|
||||
import base64
|
||||
|
||||
import StringIO
|
||||
from osv import osv, fields
|
||||
from osv.orm import except_orm
|
||||
import urlparse
|
||||
|
@ -69,14 +69,6 @@ class node_context(object):
|
|||
return ndir
|
||||
|
||||
|
||||
class node_database():
|
||||
""" A node representing the database directory
|
||||
Useless?
|
||||
"""
|
||||
def __init__(self,ncontext):
|
||||
self.nctx = ncontext
|
||||
|
||||
|
||||
|
||||
|
||||
class node_class(object):
|
||||
|
@ -163,7 +155,76 @@ class node_class(object):
|
|||
def get_dav_eprop(self,cr,ns,prop):
|
||||
return None
|
||||
|
||||
class node_dir(node_class):
|
||||
class node_database(node_class):
|
||||
""" A node representing the database directory
|
||||
|
||||
"""
|
||||
our_type = 'database'
|
||||
def __init__(self, path=[], parent=False, context=None):
|
||||
super(node_database,self).__init__(path, parent, context)
|
||||
|
||||
def children(self,cr):
|
||||
res = self._child_get(cr) + self._file_get(cr)
|
||||
return res
|
||||
|
||||
def child(self, cr, name):
|
||||
res = self._child_get(cr,name)
|
||||
if res:
|
||||
return res[0]
|
||||
res = self._file_get(cr,name)
|
||||
if res:
|
||||
return res[0]
|
||||
return None
|
||||
|
||||
def _child_get(self, cr, name=False, parent_id=False, domain=None):
|
||||
dirobj = self.context._dirobj
|
||||
uid = self.context.uid
|
||||
ctx = self.context.context.copy()
|
||||
ctx.update(self.dctx)
|
||||
where = [('parent_id','=',parent_id)]
|
||||
if name:
|
||||
where.append(('name','=',name))
|
||||
if not domain:
|
||||
domain = []
|
||||
|
||||
where2 = where + domain + [('type', '=', 'directory')]
|
||||
ids = dirobj.search(cr, uid, where2, context=ctx)
|
||||
res = []
|
||||
for dirr in dirobj.browse(cr,uid,ids,context=ctx):
|
||||
res.append(node_dir(dirr.name,self,self.context,dirr))
|
||||
|
||||
where2 = where + domain + [('type', '=', 'ressource'), ('ressource_parent_type_id','=',False)]
|
||||
ids = dirobj.search(cr, uid, where2, context=ctx)
|
||||
for dirr in dirobj.browse(cr,uid,ids,context=ctx):
|
||||
res.append(node_res_dir(dirr.name,self,self.context,dirr))
|
||||
|
||||
fil_obj = dirobj.pool.get('ir.attachment')
|
||||
ids = fil_obj.search(cr,uid,where,context=ctx)
|
||||
if ids:
|
||||
for fil in fil_obj.browse(cr,uid,ids,context=ctx):
|
||||
res.append(node_file(fil.name,self,self.context,fil))
|
||||
return res
|
||||
|
||||
def _file_get(self,cr, nodename=False, directory_id=False):
|
||||
res = []
|
||||
cntobj = self.context._dirobj.pool.get('document.directory.content')
|
||||
uid = self.context.uid
|
||||
ctx = self.context.context.copy()
|
||||
ctx.update(self.dctx)
|
||||
where = [('directory_id','=',directory_id) ]
|
||||
ids = cntobj.search(cr, uid, where, context=ctx)
|
||||
for content in cntobj.browse(cr, uid, ids, context=ctx):
|
||||
res3 = cntobj._file_get(cr, self, nodename, content)
|
||||
if res3:
|
||||
res.extend(res3)
|
||||
|
||||
return res
|
||||
|
||||
def _get_ttag(self,cr):
|
||||
return 'db-%s' % cr.dbname
|
||||
|
||||
|
||||
class node_dir(node_database):
|
||||
our_type = 'collection'
|
||||
def __init__(self,path, parent, context, dirr, dctx=None):
|
||||
super(node_dir,self).__init__(path, parent,context)
|
||||
|
@ -192,93 +253,20 @@ class node_dir(node_class):
|
|||
print e
|
||||
pass
|
||||
|
||||
def children(self,cr):
|
||||
res = self._child_get(cr) + self._file_get(cr)
|
||||
return res
|
||||
|
||||
|
||||
def get_data(self,cr):
|
||||
return ''
|
||||
|
||||
def child(self,cr, name):
|
||||
res = self._child_get(cr,name)
|
||||
if res:
|
||||
return res[0]
|
||||
res = self._file_get(cr,name)
|
||||
if res:
|
||||
return res[0]
|
||||
return None
|
||||
|
||||
|
||||
def _file_get(self,cr, nodename=False):
|
||||
res = []
|
||||
cntobj = self.context._dirobj.pool.get('document.directory.content')
|
||||
uid = self.context.uid
|
||||
ctx = self.context.context.copy()
|
||||
ctx.update(self.dctx)
|
||||
where = [('directory_id','=',self.dir_id) ]
|
||||
ids = cntobj.search(cr, uid, where, context=ctx)
|
||||
for content in cntobj.browse(cr, uid, ids, context=ctx):
|
||||
res3 = cntobj._file_get(cr, self, nodename, content)
|
||||
if res3:
|
||||
res.extend(res3)
|
||||
return super(node_dir,self)._file_get(cr, nodename, self.dir_id)
|
||||
|
||||
return res
|
||||
|
||||
def get_dav_props(self, cr):
|
||||
res = {}
|
||||
cntobj = self.context._dirobj.pool.get('document.directory.content')
|
||||
uid = self.context.uid
|
||||
ctx = self.context.context.copy()
|
||||
ctx.update(self.dctx)
|
||||
where = [('directory_id','=',self.dir_id) ]
|
||||
ids = cntobj.search(cr,uid,where,context=ctx)
|
||||
for content in cntobj.browse(cr,uid,ids,context=ctx):
|
||||
if content.extension == '.ics': # FIXME: call the content class!
|
||||
res['http://groupdav.org/'] = ('resourcetype',)
|
||||
break
|
||||
return res
|
||||
|
||||
def get_dav_eprop(self,cr,ns,prop):
|
||||
if ns != 'http://groupdav.org/' or prop != 'resourcetype':
|
||||
print "Who asked for %s:%s?" % (ns,prop)
|
||||
return None
|
||||
res = {}
|
||||
cntobj = self.context._dirobj.pool.get('document.directory.content')
|
||||
uid = self.context.uid
|
||||
ctx = self.context.context.copy()
|
||||
ctx.update(self.dctx)
|
||||
where = [('directory_id','=',self.dir_id) ]
|
||||
ids = cntobj.search(cr,uid,where,context=ctx)
|
||||
for content in cntobj.browse(cr,uid,ids,context=ctx):
|
||||
if content.extension == '.ics': # FIXME: call the content class!
|
||||
return ('vevent-collection','http://groupdav.org/')
|
||||
return None
|
||||
|
||||
def _child_get(self,cr,name = None):
|
||||
dirobj = self.context._dirobj
|
||||
uid = self.context.uid
|
||||
ctx = self.context.context.copy()
|
||||
ctx.update(self.dctx)
|
||||
where = [('parent_id','=',self.dir_id) ]
|
||||
if name:
|
||||
where.append(('name','=',name))
|
||||
|
||||
ids = dirobj.search(cr, uid, where + [('ressource_parent_type_id','=',False)],context=ctx)
|
||||
res = []
|
||||
if ids:
|
||||
for dirr in dirobj.browse(cr,uid,ids,context=ctx):
|
||||
if dirr.type == 'directory':
|
||||
res.append(node_dir(dirr.name,self,self.context,dirr))
|
||||
elif dirr.type == 'ressource':
|
||||
res.append(node_res_dir(dirr.name,self,self.context,dirr))
|
||||
|
||||
fil_obj=dirobj.pool.get('ir.attachment')
|
||||
#where2 = where # + [('res_model', '=', None)]
|
||||
ids = fil_obj.search(cr,uid,where,context=ctx)
|
||||
if ids:
|
||||
for fil in fil_obj.browse(cr,uid,ids,context=ctx):
|
||||
res.append(node_file(fil.name,self,self.context,fil))
|
||||
|
||||
return res
|
||||
|
||||
def _child_get(self, cr, name = None):
|
||||
return super(node_dir,self)._child_get(cr, name, self.dir_id)
|
||||
|
||||
|
||||
def create_child(self,cr,path,data):
|
||||
""" API function to create a child file object and node
|
||||
|
@ -601,7 +589,19 @@ class node_file(node_class):
|
|||
if fil.parent_id:
|
||||
self.storage_id = fil.parent_id.storage_id.id
|
||||
else:
|
||||
self.storage_id = None
|
||||
self.storage_id = None
|
||||
|
||||
def open(self, cr, mode=False):
|
||||
uid = self.context.uid
|
||||
if self.type in ('collection','database'):
|
||||
return False
|
||||
fobj = self.context._dirobj.pool.get('ir.attachment').browse(cr, uid, self.file_id, context=self.context.context)
|
||||
if fobj.store_method and fobj.store_method== 'fs' :
|
||||
s = StringIO.StringIO(self.get_data(cr, fobj))
|
||||
else:
|
||||
s = StringIO.StringIO(base64.decodestring(fobj.db_datas or ''))
|
||||
s.name = self
|
||||
return s
|
||||
|
||||
def fix_ppath(self, cr, fbro):
|
||||
"""Sometimes we may init this w/o path, parent.
|
||||
|
@ -687,6 +687,16 @@ class node_content(node_class):
|
|||
if dctx:
|
||||
self.dctx.update(dctx)
|
||||
self.act_id = act_id
|
||||
|
||||
def open(self, cr, mode=False):
|
||||
uid = self.context.uid
|
||||
if self.type in ('collection','database'):
|
||||
return False
|
||||
pool = self.context._dirobj.pool
|
||||
res = getattr(pool.get('document.directory.content'), 'process_read')(cr, uid, self)
|
||||
res = StringIO.StringIO(res)
|
||||
res.name = self
|
||||
return res
|
||||
|
||||
def fill_fields(self,cr,dctx = None):
|
||||
""" Try to read the object and fill missing fields, like mimetype,
|
||||
|
|
|
@ -309,31 +309,18 @@ class abstracted_fs:
|
|||
def open(self, node, mode):
|
||||
if not node:
|
||||
raise OSError(1, 'Operation not permited.')
|
||||
# Reading operation
|
||||
if node.type == 'file':
|
||||
cr = pooler.get_db(node.context.dbname).cursor()
|
||||
uid = node.context.uid
|
||||
if not self.isfile(node):
|
||||
raise OSError(1, 'Operation not permited.')
|
||||
fobj = node.context._dirobj.pool.get('ir.attachment').browse(cr, uid, node.file_id, context=node.context.context)
|
||||
if fobj.store_method and fobj.store_method== 'fs' :
|
||||
s = StringIO.StringIO(node.get_data(cr, fobj))
|
||||
else:
|
||||
s = StringIO.StringIO(base64.decodestring(fobj.db_datas or ''))
|
||||
s.name = node
|
||||
cr.close()
|
||||
return s
|
||||
elif node.type == 'content':
|
||||
uid = node.context.uid
|
||||
cr = pooler.get_db(node.context.dbname).cursor()
|
||||
pool = pooler.get_pool(node.context.dbname)
|
||||
res = getattr(pool.get('document.directory.content'), 'process_read')(cr, uid, node)
|
||||
res = StringIO.StringIO(res)
|
||||
res.name = node
|
||||
cr.close()
|
||||
return res
|
||||
else:
|
||||
# Reading operation
|
||||
cr = pooler.get_db(node.context.dbname).cursor()
|
||||
res = False
|
||||
#try:
|
||||
if node.type not in ('collection','database'):
|
||||
res = node.open(cr, mode)
|
||||
#except:
|
||||
# pass
|
||||
cr.close()
|
||||
if not res:
|
||||
raise OSError(1, 'Operation not permited.')
|
||||
return res
|
||||
|
||||
# ok, but need test more
|
||||
|
||||
|
|
|
@ -7,14 +7,14 @@
|
|||
<field name="code">shcal</field>
|
||||
</record>
|
||||
|
||||
<record model="document.directory" id="dir_calendars">
|
||||
<record model="document.directory" id="document.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="directory_id" ref="document.dir_calendars"/>
|
||||
<field name="extension">.ics</field>
|
||||
<field name="include_name" eval="False"/>
|
||||
<field name="object_id" ref="crm.model_crm_meeting"/>
|
||||
|
|
|
@ -332,8 +332,8 @@ class document_directory_content(osv.osv):
|
|||
return s
|
||||
document_directory_content()
|
||||
|
||||
class crm_case(osv.osv):
|
||||
_inherit = 'crm.case'
|
||||
class crm_meeting(osv.osv):
|
||||
_inherit = 'crm.meeting'
|
||||
_columns = {
|
||||
'code': fields.char('Calendar Code', size=64),
|
||||
'date_deadline': fields.datetime('Deadline', help="Deadline Date is automatically\
|
||||
|
@ -341,7 +341,7 @@ class crm_case(osv.osv):
|
|||
}
|
||||
|
||||
_defaults = {
|
||||
'code': lambda obj, cr, uid, context: obj.pool.get('ir.sequence').get(cr, uid, 'crm.case'),
|
||||
'code': lambda obj, cr, uid, context: obj.pool.get('ir.sequence').get(cr, uid, 'crm.meeting'),
|
||||
}
|
||||
|
||||
def copy(self, cr, uid, id, default=None, context=None):
|
||||
|
@ -356,32 +356,10 @@ class crm_case(osv.osv):
|
|||
|
||||
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)
|
||||
default.update({'code': self.pool.get('ir.sequence').get(cr, uid, 'crm.meeting'), 'id': False})
|
||||
return super(crm_meeting, self).copy(cr, uid, id, default, context)
|
||||
|
||||
def on_change_duration(self, cr, uid, id, date, duration):
|
||||
""" Change Duration
|
||||
@param self: The object pointer
|
||||
@param cr: the current row, from the database cursor,
|
||||
@param uid: the current user’s ID for security checks,
|
||||
@param id: crm case's ID,
|
||||
@param date: Pass the Date,
|
||||
@param duration: Pass the 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()
|
||||
crm_meeting()
|
||||
|
||||
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
|
||||
|
||||
|
|
|
@ -39,36 +39,16 @@
|
|||
</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>
|
||||
<record model="ir.ui.view" id="view_meeting_inherit_form">
|
||||
<field name="name">crm.meeting.code.form</field>
|
||||
<field name="model">crm.meeting</field>
|
||||
<field name="type">form</field>
|
||||
<field name="inherit_id" ref="crm.crm_case-view"/>
|
||||
<field name="inherit_id" ref="crm.crm_case_form_view_meet"/>
|
||||
<field name="arch" type="xml">
|
||||
<field name="priority" position="after">
|
||||
<field name="code"/>
|
||||
</field>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
<!-- CRM Case Form View -->
|
||||
|
||||
<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>
|
||||
|
|
Loading…
Reference in New Issue