[IMP,FIX]:improve crm_calendar to handle virtual ids as string for reports,wizard,attachment,browse,read,search,ir_values(set,get),unlink,create,copy,write(partial) and fixed export_ics procedure
bzr revid: nch@tinyerp.com-20091210123425-y175qt0b3bgtxix9
This commit is contained in:
parent
e0d5d2e120
commit
6ef425eb9b
|
@ -31,6 +31,13 @@ from datetime import datetime
|
|||
from time import strftime
|
||||
from pytz import timezone
|
||||
import tools
|
||||
from service import web_services
|
||||
|
||||
def str2int(string_id = None):
|
||||
if string_id:
|
||||
if isinstance(string_id,str):
|
||||
return int(string_id.split('-')[0])
|
||||
return string_id
|
||||
|
||||
class crm_section(osv.osv):
|
||||
_name = 'crm.case.section'
|
||||
|
@ -195,7 +202,7 @@ class crm_case(osv.osv):
|
|||
startdate = datetime.strptime(crm['date'], "%Y-%m-%d %H:%M:%S")
|
||||
if not startdate:
|
||||
startdate = datetime.now()
|
||||
rset1 = rrulestr(str(crm[event_obj.__attribute__['rrule']['field']]), dtstart=startdate, forceset=True)
|
||||
rset1 = rrulestr(str(crm[self.__attribute__['rrule']['field']]), dtstart=startdate, forceset=True)
|
||||
vevent.rruleset = rset1
|
||||
vevent.add('uid').value = uid_val
|
||||
return ical.serialize()#.replace(vobject.icalendar.CRLF, vobject.icalendar.LF).strip()
|
||||
|
@ -234,15 +241,19 @@ class crm_case(osv.osv):
|
|||
return res
|
||||
|
||||
def write(self, cr, uid, ids, vals, context=None):
|
||||
res = super(crm_case, self).write(cr, uid, ids, vals, context=context)
|
||||
new_ids = []
|
||||
for id in ids:
|
||||
id = str2int(id)
|
||||
if not id in new_ids:
|
||||
new_ids.append(id)
|
||||
if 'case_id' in vals :
|
||||
vals['case_id'] = str2int(vals['case_id'])
|
||||
res = super(crm_case, self).write(cr, uid, new_ids, vals, context=context)
|
||||
return res
|
||||
|
||||
def browse(self, cr, uid, select, context=None, list_class=None, fields_process={}):
|
||||
if not type(select) == list :
|
||||
# Called from code
|
||||
id = int(str(select).split('-')[0])
|
||||
return super(crm_case, self).browse(cr, uid, id, context, list_class, fields_process)
|
||||
select = map(lambda x:int(str(x).split('-')[0]), select)
|
||||
if not isinstance(select,list): select = [select]
|
||||
select = map(lambda x:str2int(x), select)
|
||||
return super(crm_case, self).browse(cr, uid, select, context, list_class, fields_process)
|
||||
|
||||
def read(self, cr, uid, ids, fields=None, context={},
|
||||
|
@ -253,11 +264,9 @@ class crm_case(osv.osv):
|
|||
return super(crm_case, self).read(cr, uid, ids, fields=fields, context=context, load=load)
|
||||
if not type(ids) == list :
|
||||
# Called from code
|
||||
ids = int(str(ids).split('-')[0])
|
||||
res = super(crm_case, self).read(cr, uid, ids, fields=fields, context=context, load=load)
|
||||
return res
|
||||
return super(crm_case, self).read(cr, uid, str2int(ids), fields=fields, context=context, load=load)
|
||||
else:
|
||||
ids = map(lambda x:int(str(x).split('-')[0]), ids)
|
||||
ids = map(lambda x:str2int(x), ids)
|
||||
res = super(crm_case, self).read(cr, uid, ids, fields=fields, context=context, load=load)
|
||||
read_ids = ",".join([str(x) for x in ids])
|
||||
cr.execute('select id,rrule,rdates from crm_case where id in (%s)' % read_ids)
|
||||
|
@ -285,16 +294,25 @@ class crm_case(osv.osv):
|
|||
result += [val1]
|
||||
return result
|
||||
|
||||
def copy(self, cr, uid, id, default=None, context={}):
|
||||
return super(crm_case, self).copy(cr, uid, str2int(id), default, context)
|
||||
|
||||
def unlink(self, cr, uid, ids, context=None):
|
||||
#TODO: Change RRULE
|
||||
for id in ids:
|
||||
if len(str(id).split('-')) > 1:
|
||||
date_new = time.strftime("%Y-%m-%d %H:%M:%S", time.strptime(str(str(id).split('-')[1]), "%Y%m%d%H%M%S"))
|
||||
for record in self.read(cr, uid, [str(id).split('-')[0]], ['date', 'rdates', 'rrule']):
|
||||
for record in self.read(cr, uid, [str2int(id)], ['date', 'rdates', 'rrule']):
|
||||
if record['date'] == date_new:
|
||||
self.write(cr, uid, [int(str(id).split('-')[0])], {'rrule' : record['rrule'] +"\n" + str(date_new)})
|
||||
self.write(cr, uid, [str2int(id)], {'rrule' : record['rrule'] +"\n" + str(date_new)})
|
||||
else:
|
||||
return super(crm_case, self).unlink(cr, uid, ids)
|
||||
|
||||
def create(self, cr, uid, vals, context={}):
|
||||
if 'case_id' in vals:
|
||||
vals['case_id'] = str2int(vals['case_id'])
|
||||
return super(crm_case, self).create(cr, uid, vals, context)
|
||||
|
||||
crm_case()
|
||||
|
||||
|
||||
|
@ -308,4 +326,61 @@ class ir_attachment(osv.osv):
|
|||
args1.append(map(lambda x:str(x).split('-')[0], arg))
|
||||
return super(ir_attachment, self).search_count(cr, user, args1, context)
|
||||
|
||||
def search(self, cr, uid, args, offset=0, limit=None, order=None,
|
||||
context=None, count=False):
|
||||
new_args = []
|
||||
if len(args) > 1:
|
||||
new_args = [args[0]]
|
||||
if args[1][0] == 'res_id':
|
||||
new_args.append((args[1][0],args[1][1],str2int(args[1][2])))
|
||||
if new_args:
|
||||
args = new_args
|
||||
return super(ir_attachment, self).search(cr, uid, args, offset=offset,
|
||||
limit=limit, order=order,
|
||||
context=context, count=False)
|
||||
ir_attachment()
|
||||
|
||||
class ir_values(osv.osv):
|
||||
_inherit = 'ir.values'
|
||||
|
||||
def set(self, cr, uid, key, key2, name, models, value, replace=True, isobject=False, meta=False, preserve_user=False, company=False):
|
||||
new_model = []
|
||||
for data in models:
|
||||
if isinstance(data,tuple):
|
||||
new_model.append((data[0],str2int(data[1])))
|
||||
else:
|
||||
new_model.append(data)
|
||||
return super(ir_values,self).set(cr, uid, key, key2, name, new_model, value, replace, isobject, meta, preserve_user, company)
|
||||
|
||||
def get(self, cr, uid, key, key2, models, meta=False, context={}, res_id_req=False, without_user=True, key2_req=True):
|
||||
new_model = []
|
||||
for data in models:
|
||||
if isinstance(data,tuple):
|
||||
new_model.append((data[0],str2int(data[1])))
|
||||
else:
|
||||
new_model.append(data)
|
||||
return super(ir_values,self).get(cr, uid, key, key2, new_model, meta, context, res_id_req, without_user, key2_req)
|
||||
|
||||
ir_values()
|
||||
|
||||
class virtual_report_spool(web_services.report_spool):
|
||||
def exp_report(self, db, uid, object, ids, datas=None, context=None):
|
||||
new_ids = []
|
||||
for id in ids:
|
||||
new_ids.append(str2int(id))
|
||||
datas['id'] = str2int(datas['id'])
|
||||
res=super(virtual_report_spool,self).exp_report( db, uid, object, new_ids, datas, context)
|
||||
return res
|
||||
virtual_report_spool()
|
||||
|
||||
class virtual_wizard(web_services.wizard):
|
||||
def exp_execute(self, db, uid, wiz_id, datas, action='init', context=None):
|
||||
new_ids = []
|
||||
if 'id' in datas:
|
||||
datas['id'] = str2int(datas['id'])
|
||||
for id in datas['ids']:
|
||||
new_ids.append(str2int(id))
|
||||
datas['ids'] = new_ids
|
||||
res=super(virtual_wizard,self).exp_execute(db, uid, wiz_id, datas, action, context)
|
||||
return res
|
||||
virtual_wizard()
|
Loading…
Reference in New Issue