Merge lp:~openerp-dev/openobject-server/trunk-imp-readonly-field-dka into lp:openobject-server

Proposed by Darshan Kalola(OpenERP)
Status: Work in progress
Proposed branch: lp:~openerp-dev/openobject-server/trunk-imp-readonly-field-dka
Merge into: lp:openobject-server
Diff against target: 51 lines (+34/-0)
1 file modified
openerp/osv/orm.py (+34/-0)
To merge this branch: bzr merge lp:~openerp-dev/openobject-server/trunk-imp-readonly-field-dka
Reviewer Review Type Date Requested Status
OpenERP Core Team Pending
Review via email: mp+216700@code.launchpad.net
To post a comment you must log in.

Unmerged revisions

5193. By Darshan Kalola(OpenERP)

[IMP]orm : update write method to check field is readonly, if its readonly then raise error message 'you can not change the value of readonly field', checked readonly field base on states.

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 2014-04-16 14:34:31 +0000
3+++ openerp/osv/orm.py 2014-04-22 11:54:15 +0000
4@@ -3767,6 +3767,18 @@
5
6 return True
7
8+ def compute_domain(self, cr, user, ids, domain, context=None):
9+ state = ''
10+ readonly = False
11+ for obj in self.browse(cr, user, ids, context=context):
12+ if hasattr(obj,'state'):
13+ state = obj.state
14+ if domain[1] == 'not in':
15+ if state not in domain[2]: readonly = True
16+ if domain[1] == 'in':
17+ if state in domain[2]: readonly = True
18+ return readonly
19+
20 #
21 # TODO: Validate
22 #
23@@ -3830,6 +3842,28 @@
24 continue
25 groups = fobj.write
26
27+ state_exception = []
28+ res = []
29+ default_value = None
30+ if field in self._columns:
31+ fields = self._columns[field]
32+ if hasattr(fields, 'readonly'):
33+ default_value = self._columns[field].readonly
34+ if hasattr(fields, 'states'):
35+ states = self._columns[field].states
36+ for state, expr in states.items():
37+ if expr[0][0] == 'readonly':
38+ if expr[0][1] != default_value:
39+ state_exception.append(state)
40+ if expr[0][1] == False:
41+ res = ['state','not in', state_exception]
42+ else:
43+ res = ['state','in', state_exception]
44+ if len(res) > 0:
45+ if self.compute_domain(cr, user, ids, res, context=context):
46+ raise except_orm(_('Error'),
47+ _('You can not change the value of readonly field (%s).') % field)
48+
49 if groups:
50 edit = False
51 for group in groups: