Merge lp:~openerp-dev/openobject-server/trunk-temporal-db into lp:openobject-server

Proposed by qdp (OpenERP)
Status: Work in progress
Proposed branch: lp:~openerp-dev/openobject-server/trunk-temporal-db
Merge into: lp:openobject-server
Diff against target: 84 lines (+30/-6)
2 files modified
openerp/osv/orm.py (+26/-6)
openerp/sql_db.py (+4/-0)
To merge this branch: bzr merge lp:~openerp-dev/openobject-server/trunk-temporal-db
Reviewer Review Type Date Requested Status
OpenERP Core Team Pending
Review via email: mp+75276@code.launchpad.net

Description of the change

this branch contains:
*one [FIX]: on deletion of a record, we must also recompute the stored field of same objects linked to the deleted record (there is no reason not to do so)
*one [IMP]: adding of the transaction_datestart on the cursor. It will be used by temporal objects but can legitimately be in the core because it's an useful information.

To post a comment you must log in.
3475. By Vo Minh Thu

[IMP] tightening before merging in trunk.

3476. By Vo Minh Thu

[MERGE] merged trunk.

Unmerged revisions

3476. By Vo Minh Thu

[MERGE] merged trunk.

3475. By Vo Minh Thu

[IMP] tightening before merging in trunk.

3474. By Quentin (OpenERP) <email address hidden>

[IMP] cursor: added transaction_datestart

3473. By Quentin (OpenERP) <email address hidden>

[FIX] osv/orm: on deletion of an object, recompute also the stored field of same objects linked to the deleted record (there is no reason not to do so)

3472. By Quentin (OpenERP) <email address hidden>

[MERGE] osv/orm: shallow copy

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'openerp/osv/orm.py'
2--- openerp/osv/orm.py 2011-10-03 14:45:03 +0000
3+++ openerp/osv/orm.py 2011-10-03 16:11:27 +0000
4@@ -3545,12 +3545,11 @@
5 ir_values_obj.unlink(cr, uid, ir_value_ids, context=context)
6
7 for order, object, store_ids, fields in result_store:
8- if object != self._name:
9- obj = self.pool.get(object)
10- cr.execute('select id from '+obj._table+' where id IN %s', (tuple(store_ids),))
11- rids = map(lambda x: x[0], cr.fetchall())
12- if rids:
13- obj._store_set_values(cr, uid, rids, fields, context)
14+ obj = self.pool.get(object)
15+ cr.execute('select id from '+obj._table+' where id IN %s', (tuple(store_ids),))
16+ rids = map(lambda x: x[0], cr.fetchall())
17+ if rids:
18+ obj._store_set_values(cr, uid, rids, fields, context)
19
20 return True
21
22@@ -4533,6 +4532,27 @@
23 self.copy_translations(cr, uid, id, new_id, context)
24 return new_id
25
26+ def shallow_copy(self, cr, uid, id, default=None, context=None):
27+ """
28+ This method duplicates a record without copying its many2many and one2many fields.
29+
30+ :param cr: database cursor
31+ :param uid: current user id
32+ :param id: id of the record to copy
33+ :param default: dictionary of field values to override in the original values of the copied record, e.g: ``{'field_name': overriden_value, ...}``
34+ :type default: dictionary
35+ :param context: context arguments, like lang, time zone
36+ :type context: dictionary
37+ :return: True
38+ """
39+ if default is None:
40+ default = {}
41+ for field in self._columns:
42+ if self._columns[field]._type in ('one2many', 'many2many'):
43+ # If type of the field is o2m or m2m, assign blank values in default
44+ default[field] = []
45+ return self.copy(cr, uid, id, default, context)
46+
47 def exists(self, cr, uid, ids, context=None):
48 """Checks whether the given id or ids exist in this model,
49 and return the list of ids that do. This is simple to use for
50
51=== modified file 'openerp/sql_db.py'
52--- openerp/sql_db.py 2011-09-28 21:13:26 +0000
53+++ openerp/sql_db.py 2011-10-03 16:11:27 +0000
54@@ -68,6 +68,7 @@
55
56 import tools
57 from tools.func import wraps, frame_codeinfo
58+import time
59 from datetime import datetime as mdt
60 from datetime import timedelta
61 import threading
62@@ -167,6 +168,7 @@
63 self.__closed = True # avoid the call of close() (by __del__) if an exception
64 # is raised by any of the following initialisations
65 self._pool = pool
66+ self.transaction_datestart = time.strftime(tools.DEFAULT_SERVER_DATETIME_FORMAT)
67 self.dbname = dbname
68
69 # Whether to enable snapshot isolation level for this cursor.
70@@ -329,12 +331,14 @@
71 def commit(self):
72 """ Perform an SQL `COMMIT`
73 """
74+ self.transaction_datestart = time.strftime(tools.DEFAULT_SERVER_DATETIME_FORMAT)
75 return self._cnx.commit()
76
77 @check
78 def rollback(self):
79 """ Perform an SQL `ROLLBACK`
80 """
81+ self.transaction_datestart = time.strftime(tools.DEFAULT_SERVER_DATETIME_FORMAT)
82 return self._cnx.rollback()
83
84 @check