[FIX/REF] base_calendar: virtual ids management

bzr revid: qdp-launchpad@openerp.com-20121211155627-xx33ah96xmpp47ca
This commit is contained in:
Quentin (OpenERP)
2012-12-11 16:56:27 +01:00
parent f1ef5b7f37
commit 1cd8e2c45b
2 changed files with 52 additions and 25 deletions
+26 -13
View File
@@ -88,6 +88,16 @@ def base_calendar_id2real_id(base_calendar_id=None, with_date=False):
return base_calendar_id and int(base_calendar_id) or base_calendar_id
def get_real_ids(ids):
if isinstance(ids, (str, int, long)):
return base_calendar_id2real_id(ids)
if isinstance(ids, (list, tuple)):
res = []
for id in ids:
res.append(base_calendar_id2real_id(id))
return res
def real_id2base_calendar_id(real_id, recurrent_date):
"""
Convert a real event id (type int) into a "virtual/recurring event id" (type string).
@@ -1328,16 +1338,6 @@ rule or repeating pattern of time to exclude from the recurring rule."),
data['end_type'] = 'end_date'
return data
def remove_virtual_id(self, ids):
if isinstance(ids, (str, int, long)):
return base_calendar_id2real_id(ids)
if isinstance(ids, (list, tuple)):
res = []
for id in ids:
res.append(base_calendar_id2real_id(id))
return res
def search(self, cr, uid, args, offset=0, limit=0, order=None, context=None, count=False):
context = context or {}
args_without_date = []
@@ -1387,6 +1387,13 @@ rule or repeating pattern of time to exclude from the recurring rule."),
return True
def write(self, cr, uid, ids, vals, context=None, check=True, update_check=True):
def _only_changes_to_apply_on_real_ids(field_names):
''' return True if changes are only to be made on the real ids'''
for field in field_names:
if field not in ['message_follower_ids']:
return False
return True
context = context or {}
if isinstance(ids, (str, int, long)):
ids = [ids]
@@ -1398,7 +1405,11 @@ rule or repeating pattern of time to exclude from the recurring rule."),
continue
ids.remove(event_id)
real_event_id = base_calendar_id2real_id(event_id)
if not vals.get('recurrency', True):
# if we are setting the recurrency flag to False or if we are only changing fields that
# should be only updated on the real ID and not on the virtual (like message_follower_ids):
# then set real ids to be updated.
if not vals.get('recurrency', True) or _only_changes_to_apply_on_real_ids(vals.keys()):
ids.append(real_event_id)
continue
@@ -1414,7 +1425,9 @@ rule or repeating pattern of time to exclude from the recurring rule."),
rrule='',
recurrency=False,
)
#do not copy the id
if data.get('id'):
del(data['id'])
new_id = self.copy(cr, uid, real_event_id, default=data, context=context)
date_new = event_id.split('-')[1]
@@ -1507,7 +1520,7 @@ rule or repeating pattern of time to exclude from the recurring rule."),
for r in result:
for k in EXTRAFIELDS:
if (k in r) and ((not fields) or (k not in fields)):
if (k in r) and (fields and (k not in fields)):
del r[k]
if isinstance(ids, (str, int, long)):
return result and result[0] or False
+26 -12
View File
@@ -23,9 +23,8 @@ from osv import osv, fields
import tools
from tools.translate import _
import base_calendar
from base_calendar import get_real_ids, base_calendar_id2real_id
from base_status.base_state import base_state
#
# crm.meeting is defined here so that it may be used by modules other than crm,
# without forcing the installation of crm.
@@ -69,7 +68,7 @@ class crm_meeting(base_state, osv.Model):
def message_get_subscription_data(self, cr, uid, ids, context=None):
res = {}
for virtual_id in ids:
real_id = base_calendar.base_calendar_id2real_id(virtual_id)
real_id = base_calendar_id2real_id(virtual_id)
result = super(crm_meeting, self).message_get_subscription_data(cr, uid, [real_id], context=context)
res[virtual_id] = result[real_id]
return res
@@ -128,7 +127,7 @@ class crm_meeting(base_state, osv.Model):
subtype=None, parent_id=False, attachments=None, context=None, **kwargs):
cal_event_pool = self.pool.get('calendar.event')
if isinstance(thread_id, str):
thread_id = cal_event_pool.remove_virtual_id(thread_id)
thread_id = get_real_ids(thread_id)
return super(crm_meeting, self).message_post(cr, uid, thread_id, body=body, subject=subject, type=type, subtype=subtype, parent_id=parent_id, attachments=attachments, context=context, **kwargs)
class mail_message(osv.osv):
@@ -138,11 +137,9 @@ class mail_message(osv.osv):
'''
convert the search on real ids in the case it was asked on virtual ids, then call super()
'''
cal_event_pool = self.pool.get('calendar.event')
for index in range(len(args)):
if args[index][0] == "res_id":
if isinstance(args[index][2], (str)):
args[index][2] = cal_event_pool.remove_virtual_id(args[index][2])
if args[index][0] == "res_id" and isinstance(args[index][2], (str)):
args[index][2] = get_real_ids(args[index][2])
return super(mail_message, self).search(cr, uid, args, offset, limit, order, context, count=False)
class ir_attachment(osv.osv):
@@ -152,10 +149,27 @@ class ir_attachment(osv.osv):
'''
convert the search on real ids in the case it was asked on virtual ids, then call super()
'''
cal_event_pool = self.pool.get('calendar.event')
for index in range(len(args)):
if args[index][0] == "res_id":
if isinstance(args[index][2], (str)):
args[index][2] = cal_event_pool.remove_virtual_id(args[index][2])
if args[index][0] == "res_id" and isinstance(args[index][2], (str)):
args[index][2] = get_real_ids(args[index][2])
return super(ir_attachment, self).search(cr, uid, args, offset, limit, order, context, count=False)
def write(self, cr, uid, ids, vals, context=None):
'''
when posting an attachment (new or not), convert the virtual ids in real ids.
'''
if isinstance(vals.get('res_id'), str):
vals['res_id'] = get_real_ids(vals.get('res_id'))
return super(ir_attachment, self).write(cr, uid, ids, vals, context)
class invite_wizard(osv.osv_memory):
_inherit = 'mail.wizard.invite'
def default_get(self, cr, uid, fields, context=None):
'''
in case someone clicked on 'invite others' wizard in the followers widget, transform virtual ids in real ids
'''
result = super(invite_wizard, self).default_get(cr, uid, fields, context=context)
if 'res_id' in result:
result['res_id'] = get_real_ids(result['res_id'])
return result