← Back to team overview

openerp-dev-web team mailing list archive

lp:~openerp-dev/openobject-server/trunk-temporal-db-read-search-unlink-ksa into lp:~openerp-dev/openobject-server/trunk-temporal-db

 

Kirti Savalia(OpenERP) has proposed merging lp:~openerp-dev/openobject-server/trunk-temporal-db-read-search-unlink-ksa into lp:~openerp-dev/openobject-server/trunk-temporal-db.

Requested reviews:
  Rucha (Open ERP) (rpa-openerp)

For more details, see:
https://code.launchpad.net/~openerp-dev/openobject-server/trunk-temporal-db-read-search-unlink-ksa/+merge/60367

[1] Improve search function in order to allow a null value in temporal_date_from
[2] pass temporal_date_from in args that time just call super
[3] avoid creating history records when writing on a reocrd that is already an history record
[4] use temporal_mode in order to allow to pass a key in the context to avoid creating a duplication of the record for each modification  
[5] we should compute the temporal_date_to only if we modify the temporal_date_from of the next record in timeline for that use self._name:(_get_next_id_in_timeline,['temporal_date_from'], 10) instead of self._name:(lambda self, cr, uid, ids, c={}: ids, ['temporal_date_from'], 10). 

-- 
https://code.launchpad.net/~openerp-dev/openobject-server/trunk-temporal-db-read-search-unlink-ksa/+merge/60367
Your team OpenERP R&D Team is subscribed to branch lp:~openerp-dev/openobject-server/trunk-temporal-db.
=== modified file 'openerp/addons/base/res/partner/partner.py'
--- openerp/addons/base/res/partner/partner.py	2011-04-27 14:57:39 +0000
+++ openerp/addons/base/res/partner/partner.py	2011-05-09 12:03:25 +0000
@@ -270,7 +270,7 @@
             ).res_id
 res_partner()
 
-class res_partner_address(osv.osv):
+class res_partner_address(osv.osv_temporal):
     _description ='Partner Addresses'
     _name = 'res.partner.address'
     _order = 'type, name'

=== modified file 'openerp/osv/orm.py'
--- openerp/osv/orm.py	2011-04-29 05:38:31 +0000
+++ openerp/osv/orm.py	2011-05-09 12:03:25 +0000
@@ -4283,20 +4283,30 @@
 
 #    TOCHECK: need to pass extra argument, as self and obj
     def set_date(self, obj, cr, uid, ids, name, args, context=None):
+        if context is None:
+            context = {}
         res = {}
+        ids.reverse()
         for record in obj.browse(cr, uid, ids, context=context):
             if record.temporal_parent_id:
-                res[record.id] = context.get('temporal_date_from', record.temporal_parent_id.temporal_date_from)
+                res[record.id] = record.temporal_parent_id.temporal_date_from
+                break
             else:
                 res[record.id] = False
         return res
 
+    def get_next_id_in_timeline(self, obj, cr, uid, ids, context=None):
+        res = {}
+        for record in obj.browse(cr, uid, ids, context=context):
+            search_id = obj.search(cr, uid, [('temporal_parent_id', '=', record.id),'|',('temporal_date_to', '=', False),('temporal_date_to', '=', record.temporal_date_from)], context=context)
+        return search_id
+
     def __init__(self, cr):
         self._columns.update({
         'temporal_date_from': fields.datetime('Temporal From Date'),
         'temporal_date_to': fields.function(self.set_date, method=True, string='Temporal To Date', type='datetime',
             store = {
-                self._name: (lambda self, cr, uid, ids, c={}: ids, ['temporal_date_from'], 10),
+                        self._name: (self.get_next_id_in_timeline, ['temporal_date_from'], 10),
             }),
         'temporal_parent_id': fields.many2one(self._name, 'Temporal Parent ID', ondelete='cascade')
     })
@@ -4313,11 +4323,22 @@
         if isinstance(ids, (int, long)):
             ids = [ids]
         timenow = time.strftime('%Y-%m-%d %H:%M:%S')
-        context.update({'temporal_date_from': timenow}) # get current time when make new copy of the current record
-        vals.update({'temporal_date_from': timenow})
-        for record in self.browse(cr, uid, ids, context=context):
-            defaults = {'temporal_date_from': record.temporal_date_from,'temporal_parent_id': record.id}
-            orm.copy(self, cr, uid, record.id, defaults, context=context)
+        context.update({'temporal_date_from': timenow})
+        if context.get('temporal_mode', True):
+            for record in self.browse(cr, uid, ids, context=context):
+    #            avoid creating history  records when writing on a reocrd that is already an history record
+                if record.temporal_parent_id:
+                     ids.pop()
+                     continue
+                if vals.get('temporal_date_from'):
+                    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
+                else:
+                    vals.update({'temporal_date_from': timenow}) # get current time when make new copy of the current record
+                defaults = {'temporal_date_from': record.temporal_date_from,'temporal_parent_id': record.id}
+                orm.copy(self, cr, uid, record.id, defaults, context=context)
+        else:
+            return orm.write(self, cr, uid, ids, vals, context=context) # when temporal_mode=False no need to give effect of temporal behaviour
+
         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):
@@ -4338,7 +4359,7 @@
         #add the time constraint
         timenow = time.strftime('%Y-%m-%d %H:%M:%S')
         temporal_date = context.get("temporal_date", timenow)
-        new_args += [('temporal_date_from', '<=', temporal_date), '|', ('temporal_date_to', '=', False), ('temporal_date_to', '>', temporal_date)]
+        new_args += ['|',('temporal_date_from','=',False),('temporal_date_from', '<=', temporal_date), '|', ('temporal_date_to', '=', False), ('temporal_date_to', '>', temporal_date)]
         return super(orm_temporal, self).search(cr, user, new_args, offset, limit, order, context, count)
 
     def read(self, cr, uid, ids_orig, fields=None, context=None, load='_classic_read'):
@@ -4365,5 +4386,29 @@
             return result[0]
         return result
 
+    def browse(self, cr, uid, ids_orig, context=None, list_class=None, fields_process=None):
+        ids = isinstance(ids_orig, (int, long)) and [ids_orig] or ids_orig
+        if context is None:
+            context = {}
+        #if the context doesn't contain the key 'temporal_date', just call super() and make a normal browse
+        if not context.get('temporal_date'):
+            result = super(orm_temporal, self).browse(cr, uid, ids, context, list_class, fields_process)
+        else:
+            #get the temporal_parent_id of given ids
+            temporal_parent_ids = super(orm_temporal, self).browse(cr, uid, ids, context, list_class, fields_process)
+
+            #search for real ids
+            ids2 = []
+            i = 0
+            for id in ids:
+                search_criteria = ['|',('temporal_parent_id', '=', id), ('id', '=', id)]
+                if temporal_parent_ids[i].temporal_parent_id.id != False:
+                    search_criteria = ['|', '|',] + search_criteria + [('temporal_parent_id', '=', temporal_parent_ids[i].temporal_parent_id.id), ('id', '=', temporal_parent_ids[i].temporal_parent_id.id)]
+                ids2 += self.search(cr, uid, search_criteria, context=context)
+            result = super(orm_temporal, self).browse(cr, uid, ids2, context, list_class, fields_process)
+        if isinstance(ids_orig, (int, long)):
+            return result[0]
+        return result
+
 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
 


Follow ups