openerp-dev-web team mailing list archive
-
openerp-dev-web team
-
Mailing list archive
-
Message #05935
[Merge] lp:~openerp-dev/openobject-server/trunk-temporal-db-ksa into lp:~openerp-dev/openobject-server/trunk-temporal-db
Kirti Savalia(OpenERP) has proposed merging lp:~openerp-dev/openobject-server/trunk-temporal-db-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-ksa/+merge/59035
[1] create a new class osv.osv_temporal and add columns
[2] overwrite create ,write and unlink method
--
https://code.launchpad.net/~openerp-dev/openobject-server/trunk-temporal-db-ksa/+merge/59035
Your team OpenERP R&D Team is subscribed to branch lp:~openerp-dev/openobject-server/trunk-temporal-db.
=== modified file 'openerp/osv/orm.py'
--- openerp/osv/orm.py 2011-04-11 10:13:27 +0000
+++ openerp/osv/orm.py 2011-04-26 09:49:36 +0000
@@ -48,7 +48,6 @@
import time
import traceback
import types
-
import openerp.netsvc as netsvc
from lxml import etree
from openerp.tools.config import config
@@ -2438,7 +2437,6 @@
"AND a.atttypid=t.oid", (self._table,))
col_data = dict(map(lambda x: (x['attname'], x),cr.dictfetchall()))
-
for k in self._columns:
if k in ('id', 'write_uid', 'write_date', 'create_uid', 'create_date'):
continue
@@ -4275,5 +4273,59 @@
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', required=True),
+ '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'),
+ })
+ 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')})
+ result = super(orm_temporal, self).create(cr, uid, vals, context=context)
+ return result
+
+ 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')
+ this = self.browse(cr, uid, ids[0], context=context)
+ defaults = {'temporal_date_from': this.temporal_date_from,'temporal_parent_id': this.id}
+ context.update({'temporal_date_from': timenow})
+ vals.update({'temporal_date_from': timenow})
+ temp_id = orm.copy(self, cr, uid, this.id, defaults, context=context)
+ result = super(orm_temporal, self).write(cr, uid, this.id, vals, context=context)
+ return result
+
+ def unlink(self, cr, uid, ids, context=None):
+ unlink = []
+ for id in ids:
+ for data in self.browse(cr, uid, ids ,context=context):
+ if data.temporal_parent_id:
+ unlink_ids = self.search(cr, uid, ['|',('temporal_parent_id', '=', data.temporal_parent_id.id),('id','=',data.temporal_parent_id.id)], context=context)
+ for unlink_id in unlink_ids:
+ unlink.append(unlink_id)
+ return super(orm_temporal, self).unlink(cr, uid, unlink, context=context)
+
+
# 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-26 09:49:36 +0000
@@ -79,7 +79,7 @@
# We open a *new* cursor here, one reason is that failed SQL
# queries (as in IntegrityError) will invalidate the current one.
cr = False
-
+
if hasattr(src, '__call__'):
# callable. We need to find the right parameters to call
# the orm._sql_message(self, cr, uid, ids, context) function,
@@ -98,7 +98,7 @@
pass
finally:
if cr: cr.close()
-
+
return False # so that the original SQL error will
# be returned, it is the best we have.
@@ -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:
Follow ups