Rucha (Open ERP) has proposed merging
lp:~openerp-dev/openobject-addons/trunk-temporal-db-intermediate-branch-rpa-ksa-fixes-rpa
into
lp:~openerp-dev/openobject-addons/trunk-temporal-db-intermediate-branch-rpa-ksa.
Requested reviews:
OpenERP R&D Team (openerp-dev)
For more details, see:
https://code.launchpad.net/~openerp-dev/openobject-addons/trunk-temporal-db-intermediate-branch-rpa-ksa-fixes-rpa/+merge/66074
code improvement
--
https://code.launchpad.net/~openerp-dev/openobject-addons/trunk-temporal-db-intermediate-branch-rpa-ksa-fixes-rpa/+merge/66074
Your team OpenERP R&D Team is requested to review the proposed merge of
lp:~openerp-dev/openobject-addons/trunk-temporal-db-intermediate-branch-rpa-ksa-fixes-rpa
into
lp:~openerp-dev/openobject-addons/trunk-temporal-db-intermediate-branch-rpa-ksa.
=== modified file 'base_temporal/base_temporal.py'
--- base_temporal/base_temporal.py 2011-06-24 07:13:34 +0000
+++ base_temporal/base_temporal.py 2011-06-28 06:16:33 +0000
@@ -25,30 +25,30 @@
class orm_temporal(orm.orm):
def set_date(self, obj, cr, uid, ids, name, args, context=None):
res = {}
+ context.update({'temporal_mode': False})
for id in ids:
- context.update({'temporal_mode': False})
next_id = self.get_next_id_in_timeline(obj, cr, uid, [id], context=context)
res[id] = next_id and obj.read(cr, uid, next_id, ['temporal_date_from'])[0]['temporal_date_from'] or False
return res
def get_ids_of_same_group(self, cr, uid, ids, context=None):
res = {}
+ context.update({'temporal_mode': False})
for record in self.browse(cr, uid, ids, context=context):
- context.update({'temporal_mode': False})
res[record.id] = self.search(cr, uid, [('temporal_parent_id','=',record.temporal_parent_id)], context=context)
return res
def get_next_id_in_timeline(self, obj, cr, uid, ids, context=None):
res = obj.get_ids_of_same_group(cr, uid, ids, context)
+ context.update({'temporal_mode': False})
for record in obj.browse(cr, uid, ids, context=context):
- context.update({'temporal_mode': False})
search_id = obj.search(cr, uid, [('id', 'in', res[record.id]), ('temporal_date_from', '>', record.temporal_date_from)], order='temporal_date_from asc', limit=1, context=context)
return search_id
def get_previous_id_in_timeline(self, obj, cr, uid, ids, context=None):
res = obj.get_ids_of_same_group(cr, uid, ids, context=context)
+ context.update({'temporal_mode': False})
for record in obj.browse(cr, uid, ids, context=context):
- context.update({'temporal_mode': False})
search_id = obj.search(cr, uid, [('id', 'in', res[record.id]), ('temporal_date_from', '<', record.temporal_date_from)], order='temporal_date_from desc', limit=1, context=context)
return search_id + ids
@@ -87,16 +87,18 @@
context = {}
if isinstance(ids, (int, long)):
ids = [ids]
- # if temporal_date_from pass in vals just call super without any copy
+
def _test_vals(vals):
for key, value in vals.items():
if self._columns[key]._type not in ('one2many','many2many'):
return True
return False
+
# if there is no fields written that are located on the temporal model, just call super
if not _test_vals(vals):
return super(orm_temporal, self).write(cr, uid, ids, vals, context=context)
+ # if temporal_date_from pass in vals just call super without any copy
if vals.get('temporal_date_from'):
return super(orm_temporal, self).write(cr, uid, ids, vals, context=context)
@@ -106,15 +108,16 @@
for record in self.browse(cr, uid, ids, context=context):
# get current time when make new copy of the current record
vals.update({'temporal_date_from': cr.timenow})
- self.shallow_copy(cr, uid, record.id, {}, context)
+ self.shallow_copy(cr, uid, record.id, context=context)
return super(orm_temporal, self).write(cr, uid, ids, vals, context=context)
def search(self, cr, user, args, offset=0, limit=None, order=None, context=None, count=False):
if context is None:
context = {}
- #if the key 'temporal_mode' is in the context with False, just make a normal read by calling super()
+ #if the 'temporal_mode' is False, just make a normal read by calling super()
if not context.get('temporal_mode', True):
return super(orm_temporal,self).search(cr, user, args, offset, limit, order, context, count)
+
#if present in the args, replace the clause with field 'id'
new_args = []
for item in args:
@@ -125,6 +128,7 @@
new_args.append(item)
#add the time constraint
+ # TOCHECK: cr.timenow will not play role here as we are assigning and using it at a same time
cr.timenow = time.strftime('%Y-%m-%d %H:%M:%S')
temporal_date = context.get("temporal_date", cr.timenow)
new_args += ['&','|',('temporal_date_from','=',False),('temporal_date_from', '<=', temporal_date), '|', ('temporal_date_to', '=', False), ('temporal_date_to', '>', temporal_date)]
@@ -138,16 +142,20 @@
if not context.get('temporal_date'):
result = super(orm_temporal, self).read(cr, uid, ids, fields=fields, context=context, load=load)
else:
+ # TOCHECK: cr.timenow will not play role here as we are assigning and using it at a same time
+ cr.timenow = time.strftime('%Y-%m-%d %H:%M:%S')
+ temporal_date = context.get("temporal_date", cr.timenow)
+
+ #temporal_date = context.get("temporal_date", time.strftime('%Y-%m-%d %H:%M:%S'))
+
#get the temporal_parent_id of given ids
temporal_parent_ids = super(orm_temporal, self).read(cr, uid, ids, fields=['temporal_parent_id'], context=context, load=load)
+ search_criteria = [('temporal_parent_id','=', temporal_parent_ids[0]['temporal_parent_id']), '&','|',('temporal_date_from','=',False),('temporal_date_from', '<=', temporal_date), '|', ('temporal_date_to', '=', False), ('temporal_date_to', '>', temporal_date)]
+
#search for real ids to read
- ids2 = []
- for id in ids:
- cr.timenow = time.strftime('%Y-%m-%d %H:%M:%S')
- temporal_date = context.get("temporal_date", cr.timenow)
- search_criteria = [('temporal_parent_id','=', temporal_parent_ids[0]['temporal_parent_id']), '&','|',('temporal_date_from','=',False),('temporal_date_from', '<=', temporal_date), '|', ('temporal_date_to', '=', False), ('temporal_date_to', '>', temporal_date)]
- ids2 += self.search(cr, uid, search_criteria, context=context)
+ ids2 = self.search(cr, uid, search_criteria, context=context)
result = super(orm_temporal, self).read(cr, uid, ids2, fields=fields, context=context, load=load)
+
if isinstance(ids_orig, (int, long)):
return result[0]
return result
_______________________________________________
Mailing list: https://launchpad.net/~openerp-dev-gtk
Post to : [email protected]
Unsubscribe : https://launchpad.net/~openerp-dev-gtk
More help : https://help.launchpad.net/ListHelp