← 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-configuration-rework

 

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-configuration-rework.

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/59366

Unlink,Search,Read Method
-- 
https://code.launchpad.net/~openerp-dev/openobject-server/trunk-temporal-db-read-search-unlink-ksa/+merge/59366
Your team OpenERP R&D Team is subscribed to branch lp:~openerp-dev/openobject-server/trunk-configuration-rework.
=== modified file 'openerp/addons/base/res/partner/partner.py'
--- openerp/addons/base/res/partner/partner.py	2011-04-21 06:15:44 +0000
+++ openerp/addons/base/res/partner/partner.py	2011-04-28 13:03:23 +0000
@@ -104,8 +104,8 @@
     res = obj.read(cr, uid, ids, ['code', 'name'], context)
     return [(r['code'], r['name']) for r in res] + [('','')]
 
-
-class res_partner(osv.osv):
+# Just for Testing osv temporal class so that use osv.osv_temporal instead of osv.osv
+class res_partner(osv.osv_temporal):
     _description='Partner'
     _name = "res.partner"
     _order = "name"

=== modified file 'openerp/osv/orm.py'
--- openerp/osv/orm.py	2011-04-26 10:54:26 +0000
+++ openerp/osv/orm.py	2011-04-28 13:03:23 +0000
@@ -4279,5 +4279,75 @@
                 results[k] = ''
         return results
 
+class orm_temporal(orm):
+
+#    TOCHECK: need to pass extra argument, as self and obj
+    def set_date(self, obj, cr, uid, ids, name, args, context=None):
+        res = {}
+        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)
+            else:
+                res[record.id] = False
+        return res
+
+    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),
+            }),
+        'temporal_parent_id': fields.many2one(self._name, 'Temporal Parent ID'), # self._name get object
+    })
+        return super(orm_temporal, self).__init__(cr)
+
+    def create(self, cr, uid, vals, context=None):
+        if not vals.get('temporal_date_from'):
+            vals.update({'temporal_date_from': time.strftime('%Y-%m-%d %H:%M:%S')})
+        return super(orm_temporal, self).create(cr, uid, vals, context=context)
+
+    def write(self, cr, uid, ids, vals, context=None):
+        if context is None:
+            context = {}
+        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)
+        return super(orm_temporal, self).write(cr, uid, ids, vals, context=context)
+
+    def unlink(self, cr, uid, ids, context=None):
+        unlink_ids = self.search(cr, uid, ['|',('temporal_parent_id', 'in', ids),('id','in', ids)], context=context)
+        return super(orm_temporal, self).unlink(cr, uid, unlink_ids, context=context)
+
+    def search(self, cr, user, args, offset=0, limit=None, order=None, context=None, count=False):
+        if context is None:
+            context = {}
+        original_args = args + [('temporal_parent_id', '=', False)]
+        if context.get('all_temporal'):
+            return super(orm_temporal,self).search(cr, user, args, offset, limit, order, context, count)
+        return super(orm_temporal, self).search(cr, user, original_args, offset, limit, order, context, count)
+
+        if context.get('temporal_date'):
+            args.append(['temporal_date_from', '<', context['temporal_date']] and ['temporal_date_to', '>', context['temporal_date']])
+        return super(orm_temporal, self).search(cr, user, args, offset, limit, order, context, count)
+
+
+    def read(self, cr, uid, ids, fields=None, context=None, load='_classic_read'):
+        new_ids = isinstance(ids, (str, int, long)) and [ids] or ids
+        if context is None:
+            context = {}
+        if fields and 'temporal_parent_id' not in fields:
+            original_fields = fields + [('temporal_parent_id', '=', False)]
+        data = self.search(cr, uid, [('temporal_parent_id', '=', False)], context=context)
+
+        if context.get('temporal_date'):
+            return super(orm_temporal, self).read(cr, uid, new_ids, fields=fields, context=context, load=load)
+        return super(orm_temporal, self).read(cr, uid, data, fields=original_fields, context=context, load=load)
+
 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
 

=== modified file 'openerp/osv/osv.py'
--- openerp/osv/osv.py	2011-02-07 12:57:23 +0000
+++ openerp/osv/osv.py	2011-04-28 13:03:23 +0000
@@ -360,5 +360,8 @@
         return obj
     createInstance = classmethod(createInstance)
 
+class osv_temporal(osv, orm.orm_temporal):
+    pass
+
 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: