Rucha (Open ERP) has proposed merging 
lp:~openerp-dev/openobject-addons/trunk-temporal-db-fnct-imp-rpa into 
lp:~openerp-dev/openobject-addons/trunk-temporal-db-branch-ksa.

Requested reviews:
  qdp (OpenERP) (qdp)

For more details, see:
https://code.launchpad.net/~openerp-dev/openobject-addons/trunk-temporal-db-fnct-imp-rpa/+merge/63687

Fixed create and unlink
removed unused code
improvement for adding test object as temporal
-- 
https://code.launchpad.net/~openerp-dev/openobject-addons/trunk-temporal-db-fnct-imp-rpa/+merge/63687
Your team OpenERP R&D Team is subscribed to branch 
lp:~openerp-dev/openobject-addons/trunk-temporal-db-branch-ksa.
=== modified file 'base_temporal/base_temporal.py'
--- base_temporal/base_temporal.py	2011-06-06 10:41:51 +0000
+++ base_temporal/base_temporal.py	2011-06-07 11:46:07 +0000
@@ -64,20 +64,17 @@
         if not vals.get('temporal_date_from'):
             vals.update({'temporal_date_from': time.strftime('%Y-%m-%d %H:%M:%S')})
         res_id = super(orm_temporal, self).create(cr, uid, vals, context=context)
-        if not'temporal_parent_id' in vals:
+        if not vals.get('temporal_parent_id'):
             self.write(cr, uid, res_id, {'temporal_parent_id': res_id}, context={'temporal_mode': False})
         return res_id
 
     def unlink(self, cr, uid, ids, context=None):
-        if not context.get('temporal_mode',True):
-            #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)
-            #search for real ids to delete
-            ids2 = list(ids)
-            i = 0
-            for id in ids2:
-                search_criteria = [('temporal_parent_id','=', temporal_parent_ids[i]['temporal_parent_id'])]
-                ids += self.search(cr, uid, search_criteria, context=context)
+        if isinstance(ids, (int, long)):
+            ids = list(ids)
+        if context.get('temporal_mode',True):
+            context.update({'all_temporal': True})
+            temporal_parent_ids = self.search(cr, uid, [('temporal_parent_id','in', ids)], context=context)
+            ids += temporal_parent_ids
         return super(orm_temporal, self).unlink(cr, uid, ids, context)
 
     def write(self, cr, uid, ids, vals, context=None):
@@ -153,4 +150,4 @@
 test_temporal()
 
 
-# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
\ No newline at end of file
+# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:

=== modified file 'base_temporal/base_temporal_test.py'
--- base_temporal/base_temporal_test.py	2011-06-06 10:41:51 +0000
+++ base_temporal/base_temporal_test.py	2011-06-07 11:46:07 +0000
@@ -21,134 +21,19 @@
 from osv import fields, osv
 import time
 
-class base_temporal_test(osv.osv):
+class base_temporal_test(osv.osv_temporal):
     _name = "base.temporal.test"
     _description = "Base Temporal"
 
-    def set_date(self, cr, uid, ids, name, args, context=None):
-        res = {}
-        for record in self.browse(cr, uid, ids, context=context):
-            next_id = self.get_next_id_in_timeline(cr, uid, [record.id], context={'temporal_mode': False})
-            res[record.id] = next_id and self.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 = {}
-        for record in self.browse(cr, uid, ids, context=context):
-            res[record.id] = self.search(cr, uid,  [('temporal_parent_id','=',record.temporal_parent_id)], context={'temporal_mode': False})
-        return res
-
-    def get_next_id_in_timeline(self, cr, uid, ids, context=None):
-        res = self.get_ids_of_same_group(cr, uid, ids, context)
-        for record in self.browse(cr, uid, ids, context=context):
-            search_id = self.search(cr, uid, [('id', 'in', res[record.id]), ('temporal_date_from', '>', record.temporal_date_from)], order='temporal_date_from asc', limit=1, context={'temporal_mode': False})
-        return search_id
-
-    def get_previous_id_in_timeline(self, cr, uid, ids, context=None):
-        res = self.get_ids_of_same_group(cr, uid, ids, context=context)
-        for record in self.browse(cr, uid, ids, context=context):
-            search_id = self.search(cr, uid, [('id', 'in', res[record.id]), ('temporal_date_from', '<', record.temporal_date_from)], order='temporal_date_from desc', limit=1, context={'temporal_mode': False})
-        return search_id + ids
-
     _columns = {
         'name': fields.char('Temporal Name', size=64),
         'line_ids': fields.one2many('base.temporal.test.line', 'test_id', 'Line IdS'),
-        'temporal_date_from': fields.datetime('Temporal From Date', select=True),
-        'temporal_date_to': fields.function(set_date, method=True, select=True, string='Temporal To Date', type='datetime',
-            store = {
-                        'base.temporal.test': (get_previous_id_in_timeline , ['temporal_date_from'], 10),
-            }),
-        'temporal_parent_id': fields.integer('Temporal Parent ID', select=True,)
          }
 
-    def create(self, cr, uid, vals, context=None):
-        """on creation, fill the temporal_date_from and the temporal_parent_id"""
-        if not vals.get('temporal_date_from'):
-            vals.update({'temporal_date_from': time.strftime('%Y-%m-%d %H:%M:%S')})
-        res_id = super(base_temporal_test, self).create(cr, uid, vals, context=context)
-        if not 'temporal_parent_id' in vals:
-            self.write(cr, uid, res_id, {'temporal_parent_id': res_id}, context={'temporal_mode': False})
-        return res_id
-
-    def unlink(self, cr, uid, ids, context=None):
-        if not context.get('temporal_mode',True):
-            #get the temporal_parent_id of given ids
-            temporal_parent_ids = super(base_temporal_test, self).read(cr, uid, ids, fields=['temporal_parent_id'], context=context)
-            #search for real ids to delete
-            ids2 = list(ids)
-            i = 0
-            for id in ids2:
-                search_criteria = [('temporal_parent_id','=', temporal_parent_ids[i]['temporal_parent_id'])]
-                ids += self.search(cr, uid, search_criteria, context=context)
-        return super(base_temporal_test, self).unlink(cr, uid, ids, context)
-
-    def write(self, cr, uid, ids, vals, context=None):
-        if context is None:
-            context = {}
-        if isinstance(ids, (int, long)):
-            ids = [ids]
-        # if temporal_date_from pass in vals just call super without any copy
-        if vals.get('temporal_date_from'):
-            return super(base_temporal_test, self).write(cr, uid, ids, vals, context=context)
-
-        timenow = time.strftime('%Y-%m-%d %H:%M:%S')
-        if context.get('temporal_mode', True):
-            for record in self.browse(cr, uid, ids, context=context):
-                #avoid creating history  records when writing on a record that is already an history record
-                if not((not record.temporal_date_from or record.temporal_date_from <= timenow) and (not record.temporal_date_to or timenow < record.temporal_date_to)):
-                   continue
-                # get current time when make new copy of the current record
-                vals.update({'temporal_date_from': timenow})
-#                defaults = {'temporal_date_from': record.temporal_date_from,'temporal_parent_id': record.id}
-                self.copy(cr, uid, record.id, {}, context)
-        return super(base_temporal_test, 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 not context.get('temporal_mode', True):
-            return super(base_temporal_test,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:
-            if isinstance(item, tuple):
-                a, b, c = item
-                if a == 'id':
-                    new_args += ['|', ('temporal_parent_id', b, c)]
-            new_args.append(item)
-
-        #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','=',False),('temporal_date_from', '<=', temporal_date), '|', ('temporal_date_to', '=', False), ('temporal_date_to', '>', temporal_date)]
-        return super(base_temporal_test, 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'):
-        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 read
-        if not context.get('temporal_date'):
-            result = super(base_temporal_test, self).read(cr, uid, ids, fields=fields, context=context, load=load)
-        else:
-            #get the temporal_parent_id of given ids
-            temporal_parent_ids = super(base_temporal_test, self).read(cr, uid, ids, fields=['temporal_parent_id'], context=context, load=load)
-
-            #search for real ids to read
-            ids2 = []
-            i = 0
-            for id in ids:
-                search_criteria = [('temporal_parent_id','=', temporal_parent_ids[i]['temporal_parent_id'])]
-                ids2 += self.search(cr, uid, search_criteria, context=context)
-            result = super(base_temporal_test, self).read(cr, uid, ids2, fields=fields, context=context, load=load)
-        if isinstance(ids_orig, (int, long)):
-            return result[0]
-        return result
 
 base_temporal_test()
 
-class base_temporal_test_line(osv.osv):
+class base_temporal_test_line(osv.osv_temporal):
     _name = "base.temporal.test.line"
     _description = "Base Temporal Line"
     _columns = {
@@ -157,4 +42,6 @@
     }
 
 base_temporal_test_line()
+
+
 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:

=== modified file 'base_temporal/base_temporal_test_view.xml'
--- base_temporal/base_temporal_test_view.xml	2011-06-06 10:41:51 +0000
+++ base_temporal/base_temporal_test_view.xml	2011-06-07 11:46:07 +0000
@@ -53,6 +53,20 @@
     <menuitem action="action_base_temporal_test_tree"
         id="menu_partner_temporal_tree"
         parent="base.menu_base_partner" sequence="50"/>
+
+     <record model="ir.actions.act_window" id="action_base_temporal_test_1">
+            <field name="name">Base Temporal Test All</field>
+            <field name="res_model">base.temporal.test</field>
+            <field name="type">ir.actions.act_window</field>
+            <field name="view_type">form</field>
+            <field name="view_mode">tree,form</field>
+            <field name="context">{'temporal_mode': False}</field>
+            <field name="search_view_id" ref="view_base_temporal_test_tree"/>
+        </record>
+
+    <menuitem action="action_base_temporal_test_1"
+        id="menu_partner_temporal_tree1"
+        parent="base.menu_base_partner" sequence="50"/>
   </data>
 </openerp>
 

_______________________________________________
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

Reply via email to